need help with this program that is telling me to calculate gpa
This is the test data and output
http://tinypic.com/r/1zccyue/5
this is what i have so far..
http://tinypic.com/r/w0mk9/5
i know some things might be wrong, but i'm trying to fix it
here's the problems i'm having:
1.)How to read all the values from the input file (using sentinel values I think) even though you have some values that are skipped (or not there)
ex.)if you look at the test data you see #ID 19364 only has 4 values for that line
this is what i had put in the input file (its probably wrong, i put the -1's in the place of where some of the lines don't have all values)
http://tinypic.com/r/ndwkcw/5
2.)How do i write the code to multiply the grade and crhrs because you see that there's a grade and crhrs for each course? then i have to add up all the credit hours on each person's ID..
ex.) how will i write points =.....
Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <stdlib.h>
using namespace std;
//function prototypes go here
int main()
{
double gpa, points, hours, ID, grade, crhrs;
ofstream OutputFile;
OutputFile.open("Output.dat");
ifstream infile;
infile.open("Input.dat");
OutputFile<<setw(30)<<"Thomas Powe"<<endl;
OutputFile<<setw(29)<<"03-27-12"<<endl<<endl;
OutputFile<<setw(15)<<"ID"<<setw(18)<<"GPA"<<endl<<endl;
infile>>ID>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs;
while (!infile.eof())
{
//OutputFile<<setw(15)<<ID<<setw(18)<<"Comin Soon"<<endl;
points = (grade * crhrs) + (grade * crhrs) + (grade * crhrs) + (grade * crhrs) + (grade * crhrs);
hours=crhrs + crhrs + crhrs +crhrs +crhrs;
gpa=points/hours;
infile>>ID>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs>>grade>>crhrs;
OutputFile<<setw(15)<<ID<<setw(18)<<gpa<<endl;
}
OutputFile.close();
infile.close();
return 0;
}
|
this what i have so far