0% found this document useful (0 votes)
8 views4 pages

Assignment 2

Uploaded by

floydmustang1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Assignment 2

Uploaded by

floydmustang1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ACTIVITY 1.

1
#include <iostream>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

// Class to represent a student


class Student {
private:
string studentNumber;
string initials;
string surname;
char sex;
vector<string> moduleNames;
vector<int> marks;
vector<string> grades;

public:
// Constructor
Student(string studentNumber, string initials, string surname, char sex) {
this->studentNumber = studentNumber;
this->initials = initials;
this->surname = surname;
this->sex = sex;
}

// Method to enroll a student in a module with mark


void enrollModule(string moduleName, int mark) {
moduleNames.push_back(moduleName);
marks.push_back(mark);
grades.push_back(calculateGrade(mark));
}

// Method to calculate the grade based on the mark


string calculateGrade(int mark) {
if (mark >= 97 && mark <= 100) {
return "A+";
} else if (mark >= 93 && mark <= 96) {
return "A";
} else if (mark >= 90 && mark <= 92) {
return "A-";
} else if (mark >= 87 && mark <= 89) {
return "B+";
} else if (mark >= 83 && mark <= 86) {
return "B";
} else if (mark >= 80 && mark <= 82) {
return "B-";
} else if (mark >= 77 && mark <= 79) {
return "C+";
} else if (mark >= 73 && mark <= 76) {
return "C";
} else if (mark >= 70 && mark <= 72) {
return "C-";
} else if (mark >= 67 && mark <= 69) {
return "D+";
} else if (mark >= 63 && mark <= 66) {
return "D";
} else if (mark >= 60 && mark <= 62) {
return "D-";
} else {
return "F";
}
}

// Method to export student information to Excel sheet


void exportToExcel() {
ofstream outFile("student_info.csv"); // Open a CSV file for writing

// Write header row to CSV file


outFile << "Student Number,Initials,Surname,Sex,Module Name,Mark,Grade"
<< endl;

// Write student information to CSV file


for (int i = 0; i < moduleNames.size(); i++) {
outFile << studentNumber << "," << initials << "," << surname << "," <<
sex << ","
<< moduleNames[i] << "," << marks[i] << "," << grades[i] << endl;
}

outFile.close(); // Close the CSV file


cout << "Student information exported to Excel sheet successfully!" << endl;
}
};

int main() {
// Enroll a student
Student student("123456789", "J", "Doe", 'M');
student.enrollModule("Math", 95);
student.enrollModule("Science", 87);
student.enrollModule("History", 72);

// Export student information to Excel sheet


student.exportToExcel();

return 0;
}
ACTIVITY 1.2
#include <iostream>
#include <cmath>

using namespace std;

class VoltageMaterial {
private:
double v0; // Maximum voltage
double k; // Gregg's surface number
double omega_p; // Peak angular frequency
double alpha; // Index current factor
double beta; // Material resistive factor

public:
// Constructor
VoltageMaterial(double v0, double k, double omega_p, double alpha, double
beta) {
this->v0 = v0;
this->k = k;
this->omega_p = omega_p;
this->alpha = alpha;
this->beta = beta;
}

// Function to calculate the partial distribution of voltage


double PartialVoltage(double omega, double k, double beta) {
double term1 = v0 * pow(omega / omega_p, 2 * k / beta);
double term2 = exp(-pow(omega / omega_p, 2 * alpha / beta));
return term1 * term2;
}
};

int main() {
// Define the constants
double omega_p = 12.0; // rad/s
double alpha = 5.32;
double v0 = 50.0; // V

// Create an object of VoltageMaterial with the constants


VoltageMaterial vm(v0, alpha, omega_p, alpha, alpha);

// Test case 1
double omega1 = 1800.0; // rad/s
double k1 = 0.15;
double beta1 = 1.5;
double partialVoltage1 = vm.PartialVoltage(omega1, k1, beta1);
cout << "Partial Voltage for omega = " << omega1 << " rad/s, k = " << k1 <<
", beta = " << beta1 << " is: " << partialVoltage1 << " V" << endl;

// Test case 2
double omega2 = 1500.0; // rad/s
double k2 = 1.5;
double beta2 = 1.1;
double partialVoltage2 = vm.PartialVoltage(omega2, k2, beta2);
cout << "Partial Voltage for omega = " << omega2 << " rad/s, k = " << k2 <<
", beta = " << beta2 << " is: " << partialVoltage2 << " V" << endl;

return 0;
}

In this program, the function PartialVoltage is a member function of the class


VoltageMaterial, which is defined to represent the material attributes. The material
properties are initialized in the class' constructor. The PartialVoltage function uses
the specified formula to determine the partial distribution of voltage while taking
the values of omega, k, and beta as inputs. The main method constructs a
VoltageMaterial object with the specified constant values and runs two sets of input
parameters through the PartialVoltage function. The console prints the outcomes.

You might also like