Question
In C++ can you help me change stuct to class on the code provided below thank you #include #include #include #include #include #include #include #include
In C++
can you help me change stuct to class on the code provided below thank you
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const unsigned NumberOfStudents = 55;
const unsigned PointsPossible = 400;
const unsigned NumberOfAssignments = 10;
const unsigned NumberOfExercises = 10;
struct Student
{
int id;
string name;
int exercise[NumberOfExercises];
int assignment[NumberOfAssignments];
int midterm;
int final;
int codelab;
int exerciseTotal;
int assignmentTotal;
int totalPoints;
int percent;
string grade;
};
void getStudentDataFromFile(Student S[], string name);
void determineGrades(Student S[]);
void sort(Student S[]);
void printStudentDataToFile(Student S[], string name);
int main()
{
string InputFilename = "in.txt";
string OutputFilename = "out.txt";
Student students[NumberOfStudents];
getStudentDataFromFile(students, InputFilename);
determineGrades(students);
sort(students);
printStudentDataToFile(students,OutputFilename);
}
void getStudentDataFromFile(Student S[], string name)
{
fstream fin;
fin.open(name);
if (!fin)
{
cout << "Unable to open file " << endl;
}
else
{
string dummyline;
getline(fin, dummyline); //this is for ignoring the title line
while (!fin.eof())
{
for (int i = 0; i < NumberOfStudents; i++) {
fin >> S[i].id;
fin >> S[i].name;
string last = " ";
while (true) {
fin >> last;
if (isdigit(last[0])) {
break;
}
S[i].name += " " + last;
}
S[i].exercise[0] = stoi(last);
S[i].exerciseTotal = S[i].exercise[0];
for (int j = 1; j < NumberOfExercises; j++)
{
fin >> S[i].exercise[j];
S[i].exerciseTotal += S[i].exercise[j];
}
S[i].assignmentTotal = 0;
for (int k = 0; k < NumberOfAssignments; k++)
{
fin >> S[i].assignment[k];
S[i].assignmentTotal += S[i].assignment[k];
}
// drop
int temp = S[i].assignment[0];
for (int l = 0; l < NumberOfAssignments; l++) {
if (temp > S[i].assignment[l])
{
temp = S[i].assignment[l];
}
}
S[i].assignmentTotal -= temp;
fin >> S[i].midterm;
fin >> S[i].final;
fin >> S[i].codelab;
S[i].totalPoints = S[i].exerciseTotal + S[i].assignmentTotal+ S[i].codelab + S[i].final + S[i].midterm;
S[i].percent = 100 * S[i].totalPoints / PointsPossible;
}
}
}
}
void determineGrades(Student S[])
{
for (int i = 0; i < NumberOfStudents; i++)
{
int sum = S[i].percent;
if (sum >= 97)
S[i].grade = "A+";
else if (sum >= 93 )
S[i].grade = "A";
else if (sum >= 90 )
S[i].grade = "A-";
else if (sum >= 87 && sum < 90)
S[i].grade = "B+";
else if (sum >= 83 && sum < 87)
S[i].grade = "B";
else if (sum >= 80 && sum < 82)
S[i].grade = "B-";
else if (sum >= 77 && sum < 80)
S[i].grade = "C+";
else if (sum >= 73 && sum < 77)
S[i].grade = "C";
else if (sum >= 70 && sum < 72)
S[i].grade = "C-";
else if (sum >= 67 && sum < 70)
S[i].grade = "D+";
else if (sum >= 63 && sum < 67)
S[i].grade = "D";
else if (sum >= 60 && sum < 62)
S[i].grade = "D-";
else
S[i].grade = "F";
}
}
void sort(Student S[])
{
for(int i=0; i { for(int j=i+1; j { if(S[i].totalPoints < S[j].totalPoints) { Student tmp = S[i]; S[i] = S[j]; S[j] = tmp; } } } } void printStudentDataToFile(Student S[], string name) { ofstream fout; fout.open(name); if (!fout) { cout << "Unable to open file " << endl; } else { fout << "Stud Id Name Ex Ass Mi Fin CL Tot Pct Gr "; fout << "-------- ------------------- -- --- -- --- -- --- --- -- "; for (int i = 0; i < NumberOfStudents; ++i) { fout << setw(8) << setfill('0') << right << student[i].id << ' ' << setfill(' ') << left << setw(19) << student[i].name << right << setw(3) << student[i].exerciseTotal << setw(4) << student[i].assignmentTotal << setw(3) << student[i].midterm << setw(4) << student[i].final << setw(3) << student[i].codelab << setw(4) << student[i].totalPoints << setw(4) << student[i].percent << ' ' << student[i].grade << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started