Question: Can someone change my code so it will compiled and run without any issue in c++ 03 standard IDE #include #include #include using namespace std;
Can someone change my code so it will compiled and run without any issue in c++ 03 standard IDE
#include #include #include
using namespace std; // structure to store a students data. struct student{ string name; // array of size 4 to store 4 exam marks. vector examValues = vector(4); // variable to store average score. double averageScore; // array to store grade for each exam. vector letterGrade = vector(5); };
// getData function to populate data from file. // @Param is a array of type student.
void GetData(vector &studentData) { ifstream in; // opening file. in.open("Grading.txt"); // error handling to check if file exits or not. if(!in){ cout << "Error file doesnot exits!! "; } // looping through no of students and populating array with data from file. for(int i = 0; i < studentData.size(); i++) { getline(in, studentData[i].name); for(int j = 0; j < studentData[i].examValues.size(); j++) { string marks; getline(in, marks); studentData[i].examValues[j] = atoi(marks.c_str()); } } } // a additional function to calculate and return letter Grade by accepting average score. char calculateGrade(double average){ if(average >= 90 && average <= 100) { return 'A'; } else if(average >= 80 && average <= 89) { return 'B'; } else if(average >= 70 && average <= 79) { return 'C'; } else if(average >= 60 && average <= 69) { return 'D'; } else { return 'F'; } } // function to calculate average score and letter grade for each student. // accepting a student array. void CalcAvg(vector &studentData){
for(int i = 0; i < studentData.size(); i++){ double sum = 0; for(int j = 0; j < studentData[i].examValues.size(); j++){ sum += studentData[i].examValues[j]; } double average = sum / 4; studentData[i].averageScore = round(average); studentData[i].letterGrade[i] = calculateGrade(studentData[i].averageScore); } }
// function to display students data. void displayData(vector &studentData){ cout << "Student stats are as follows: "; cout << "Sq.\t\tName\t\tAverage\tGrade "; for(int i = 0; i < studentData.size(); i++){ cout << i + 1 << ".\t" << studentData[i].name << "\t" << studentData[i].averageScore << "\t" << studentData[i].letterGrade[i] << endl; } }
// Driver Code. int main() { // declaring a array of type student and size 5. vector gradeBook(5); // populating array. GetData(gradeBook); // calcualte average and storing in arrays. CalcAvg(gradeBook); // displaying data on screen. displayData(gradeBook); }