Question
Code won't open file, and also I think there is a math problem in result. Criteria and format of code is in comments. /* Cameron
Code won't open file, and also I think there is a math problem in result. Criteria and format of code is in comments.
/* 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 //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
using namespace std;
const int NUM_STUDENTS = 10;
struct studentRecord { string STUDENT_NAME; int MIDTERM_EXAM; int FINAL_EXAM; int LAB1; int LAB2; int LAB3; int 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 = 'N'; 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() { //read in the student scores from a file ifstream ifs("student.dat"); string STUDENT_NAME; int MIDTERM_EXAM, FINAL_EXAM, LAB1, LAB2, LAB3, LAB4; struct studentRecord records[10]; if (ifs.fail()) { cout << "Error opening student data file" << endl; exit(1); } int i = 0; while (!ifs.eof()) { ifs >> STUDENT_NAME >> MIDTERM_EXAM >> FINAL_EXAM >> LAB1 >> LAB2 >> LAB3 >> LAB4;
records[i].STUDENT_NAME = STUDENT_NAME; records[i].MIDTERM_EXAM = MIDTERM_EXAM; records[i].FINAL_EXAM = FINAL_EXAM; records[i].LAB1 = LAB1; records[i].LAB2 = LAB2; records[i].LAB3 = LAB3; records[i].LAB4 = LAB4;
i++; }
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; }
}
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