My program is supposed to read from this output file and print the contents to the screen :
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
I have a read until end of file command and all the necessary other commands.
I read in the first id number as Student_id and then if the id is not equal to the new id read in then it calculated the grades for the student and outputs it to the screen and then continues to read the rest of the data entered.
This is what I have for that section of code:
Code:
if(Student_id!=New_id)
{
quiz.Average=quiz.Tot_Ach/quiz.Tot_Poss;
prog.Average=prog.Tot_Ach/prog.Tot_Poss;
Poss_Score= quiz.Tot_Poss+prog.Tot_Poss+mid.Tot_Poss+fin.Tot_Poss;
Acheived_Score=quiz.Tot_Ach+prog.Tot_Ach+mid.Tot_Ach+fin.Tot_Ach;
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;
}
Code:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
struct Type
{
double Poss_Score;
double Acheived_Score;
double Tot_Poss;
double Tot_Ach;
double Average;
}quiz,prog,mid,fin;
int main()
{
string Course_Name;
int Student_id;
int New_id;
string Lastname;
string Firstname;
char Assignment_Type;
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>>quiz.Poss_Score>>quiz.Acheived_Score;
quiz.Tot_Poss+=quiz.Tot_Poss;
quiz.Tot_Ach+=quiz.Tot_Ach;
break;
case 'P':
myfile>>prog.Poss_Score>>prog.Acheived_Score;
prog.Tot_Poss+=prog.Poss_Score;
prog.Tot_Ach+=prog.Tot_Ach;
break;
case 'M':
myfile>>mid.Poss_Score>>mid.Acheived_Score;
mid.Tot_Poss+=mid.Poss_Score;
mid.Tot_Ach+=mid.Acheived_Score;
break;
case 'F':
while(!myfile.eof())
{
getline(myfile,Course_Name);
myfile>>Student_id;
myfile.get();
myfile>>Lastname;
myfile.get();
myfile.get();
myfile>>Firstname;
myfile.get();
myfile>>Assignment_Type;
switch(Assignment_Type)
{
case 'Q':
myfile>>quiz.Poss_Score>>quiz.Acheived_Score;
quiz.Tot_Poss+=quiz.Tot_Poss;
quiz.Tot_Ach+=quiz.Tot_Ach;
break;
case 'P':
myfile>>prog.Poss_Score>>prog.Acheived_Score;
prog.Tot_Poss+=prog.Poss_Score;
prog.Tot_Ach+=prog.Tot_Ach;
break;
case 'M':
myfile>>mid.Poss_Score>>mid.Acheived_Score;
mid.Tot_Poss+=mid.Poss_Score;
mid.Tot_Ach+=mid.Acheived_Score;
break;
case 'F':
myfile>>fin.Poss_Score>>fin.Acheived_Score;;
fin.Tot_Poss+=fin.Poss_Score;
fin.Tot_Ach+=fin.Acheived_Score;
break;
default:cout<<"Invald Input";
}
}
myfile>>New_id;
if(Student_id!=New_id)
{
quiz.Average=quiz.Tot_Ach/quiz.Tot_Poss;
prog.Average=prog.Tot_Ach/prog.Tot_Poss;
Poss_Score= quiz.Tot_Poss+prog.Tot_Poss+mid.Tot_Poss+fin.Tot_Poss;
Acheived_Score=quiz.Tot_Ach+prog.Tot_Ach+mid.Tot_Ach+fin.Tot_Ach;
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;
}
}