The following program should take the following input from this file and calculate the average for Q-Quizzes, P-Programming Assignments and also calculate the final percentage for each student. Somehow I cant get it to detect the two names and calculate correct averages and percentage.
This is the content of the input file
CPTR151‐01
000143 Doe John Q 10 5
000143 Doe John Q 10 7
000143 Doe John Q 10 9
000143 Doe John P 20 17
000143 Doe John P 20 15
000143 Doe John M 50 45
000143 Doe John F 50 40
991253 Dough Jane Q 10 10
991253 Dough Jane Q 10 6
991253 Dough Jane Q 10 2
991253 Dough Jane P 20 20
991253 Dough Jane P 20 7
991253 Dough Jane M 50 35
991253 Dough Jane F 50 47.5
Code:#include<iostream> #include<string> #include<fstream> using namespace std; int main() { string Course_Name; int Student_id; int New_id; string Lastname; string Firstname; char Assignment_Type; double Poss_Quiz_Score; double Acheived_Quiz_Score; double Tot_Poss_Quiz; double Tot_Ach_Quiz; double Quiz_Average; double Poss_Prog_Score; double Acheived_Prog_Score; double Tot_Poss_Prog; double Tot_Ach_Prog; double Prog_Average; double Poss_Mid_Score; double Acheived_Mid_Score; double Tot_Poss_Mid; double Tot_Ach_Mid; double Poss_Final_Score; double Acheived_Final_Score; double Tot_Poss_Fin; double Tot_Ach_Fin; double Poss_Score; double Acheived_Score; double Per; //Section 1- This section reads the information from the input file and assigns appropriate variable names. ifstream myfile; myfile.open("student_info.dat"); while(!myfile.eof()) { getline(myfile,Course_Name); myfile>>Student_id; myfile.get(); myfile>>Lastname; myfile.get(); myfile>>Firstname; myfile.get(); myfile>>Assignment_Type; switch(Assignment_Type) { case 'Q': myfile>>Poss_Quiz_Score>>Acheived_Quiz_Score; Tot_Poss_Quiz+=Tot_Poss_Quiz; Tot_Ach_Quiz+=Tot_Ach_Quiz; break; case 'P': myfile>>Poss_Prog_Score>>Acheived_Prog_Score; Tot_Poss_Prog+=Poss_Prog_Score; Tot_Ach_Prog+=Tot_Ach_Prog; break; case 'M': myfile>>Poss_Mid_Score>>Acheived_Mid_Score; Tot_Poss_Mid+=Poss_Mid_Score; Tot_Ach_Mid+=Acheived_Mid_Score; break; case 'F': myfile>>Poss_Final_Score>>Acheived_Final_Score; myfile>>Poss_Final_Score>>Acheived_Final_Score; Tot_Poss_Fin+=Poss_Final_Score; Tot_Ach_Fin+=Acheived_Final_Score; break; default:cout<<"Invald Input"; } myfile>>New_id; if(Student_id!=New_id) { Quiz_Average=Tot_Ach_Quiz/Tot_Poss_Quiz; Prog_Average=Tot_Ach_Prog/Tot_Poss_Prog; Poss_Score= Tot_Poss_Quiz+Tot_Poss_Prog+Tot_Poss_Mid+Tot_Poss_Fin; Acheived_Score=Tot_Ach_Quiz+Tot_Ach_Prog+Tot_Ach_Mid+Tot_Ach_Fin; Per=(Acheived_Score/Poss_Score)*100/1; cout<<Firstname<<" "<<Lastname<<endl; cout<<"Quiz Average: "<<Quiz_Average<<endl; cout<<"Programming Average: "<<Prog_Average<<endl; cout<<"Final Percentage: "<<Per; } } return 0; }