Question: What is right formula for variable result to give correct grade to students? MIDTERM_EXAM is 0.25%, FINAL_EXAM is 0.25% and LABS=0.50..so formula needs to weight

What is right formula for variable result to give correct grade to students? MIDTERM_EXAM is 0.25%, FINAL_EXAM is 0.25% and LABS=0.50..so formula needs to weight them and then give correct grade

CODE:

/* Cameron Christensen

[50 pts] Write a C++ program that reads the following student input data (student.dat) into an array of Student c-struct objects. Provide a function in the program that can calculate the students final grade based on the following criteria:

The format of the file is as follows: //STUDENT_NAME // MIDTERM_EXAM FINAL_EXAM //LAB1 LAB2 LAB3 LAB4

Student.dat = Joe Doe 90.8 89.5 67 89.2 99.0 100.0 Susan F. Smith 95.5 94.0 78.5 90 87.5 57 Sam Grover 78 100.0 79.5 69.4 90.0 88.5 Diane C. Phelps 100 78.0 56.0 69 94.0 78 John Franklin 65 87.0 67.0 96 49.0 87 Derrick Myers 89.8 98.5 76 89.2 93.0 100.0

*/

#include #include #include #include using namespace std;

const int NUM_STUDENTS = 10;

struct studentRecord { string STUDENT_NAME; double MIDTERM_EXAM; double FINAL_EXAM; double LAB1; double LAB2; double LAB3; double LAB4; };

double calGrade(struct studentRecord& record) {

double result = (record.LAB1 * 0.50) + (record.LAB2 * 0.50) + (record.LAB3 * 0.50) + (record.LAB4 * 0.50) + (record.MIDTERM_EXAM * 0.25) + (record.FINAL_EXAM);

return result; }

char calcAward(double result) { char grade;

if (result > 90) { grade = 'A'; } else if (result > 80) { grade = 'B'; } else if (result > 70) { grade = 'C'; } else if (result > 60) { grade = 'D'; } else { grade = 'F'; }

return grade; }

int main() {

ifstream ifs("student.dat"); struct studentRecord records[NUM_STUDENTS];

if (ifs.fail()) { cout << "Error opening student data file" << endl; exit(1); }

int i = 0; while (!ifs.eof()) {

getline(ifs, records[i].STUDENT_NAME); ifs >> records[i].MIDTERM_EXAM; ifs >> records[i].FINAL_EXAM; ifs >> records[i].LAB1; ifs >> records[i].LAB2; ifs >> records[i].LAB3; ifs >> records[i].LAB4; i++; ifs.ignore(); }

cout << i << " student records read ... processing ... processing" << endl; for (int j = 0; j < i; j++) { double result = calGrade(records[j]); cout << records[j].STUDENT_NAME << " got " << result << " which is an " << calcAward(result) << endl; }

ifs.close();

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!