/* This program will calculate the current semester's GPA and the cumulative GPA of a student.
The program should use an input data file to: read students 6 digit id number (id), old grade point
average (ogpa), and the old number of course credits (occ). The program will read the current course credits
(c1, c2, c3, and c4) and the current grades (g1, g2, g3, and g4) for each course. Then the program will compute
old number of honor points oph = occ * ogpa, new number of honor points nhp = c1 * g1 +c2 * g2 + c3 * g3 + c4 * g4,
current GPA cur_gpa = nhp / ncc, and last the cumulative GPA cum_gpa = (nhp + ohp ) / (ncc + occ) */
ifstream infile; // define file stream for input- gpa.txt
ofstream outfile; // object for writing to a file
infile.open ("gpa.txt"); // opening gpa.txt file where my data is saved
if (infile.fail () ) // testing to make sure my file was opened
{
cerr<< "Could not open input file "; // going to send an error message if file did not open
exit (1);
}
outfile.open ("kathHomework5.txt"); // opening a file to write to and naming that file kathHomewok5.txt
if ( outfile.fail () ) // testing to make sure my file was open
{
cerr<< "could not open output "<<endl; // will send an error message if file was not open
exit (2);
}
// all files are open
infile>>ID>>ogpa>>occ; // inputting my student ID, old grade point average, and old number of course credits from my data file
infile>>c1>>c2>>c3>>c4; // inputting my current course credits from my data file
infile>>g1>>g2>>g3>>g4; // inputting my current grades from my data file
ohp = occ * ogpa; // calculating old number of honor points
nhp = c1 * g1 + c2 * g2 + c3 * g3 + c4 * g4; // calculating new number of honor points
ncc = c1 + c2 + c3 + c4; // calculating total number of new course credits
cur_gpa = nhp/ncc; // calculating current GPA
cum_gpa = (nhp + ohp) / (ncc + occ); // calculating cumulative GPA
tcc = occ + ncc; // calculating total credits completed
cout<<setw(50)<< "Student Records" <<endl; // outputting a title for the document for users to understand what they are looking at
cout<<endl;
cout<<setw(50)<< "Student ID number: " <<setw(2)<<ID<<endl; // outputting student ID
cout<<setw(50)<< "Previous semesters credit: " <<setw(2)<<occ<<endl; // outputting previous semesters credit
cout<<setw(50)<< "Previous semesters GPA: " <<setw(2)<<ogpa<<endl; // outputting previous semesters GPA
cout<<setw(50)<< "Current semester's credits: " <<setw(2)<<ncc<<endl; // outputting current semesters credits
cout<<setprecision(2)<<setw(50)<< "GPA of current semester: " <<setw(2)<<cur_gpa<<endl; // outputting GPA of current semester
cout<<setprecision(2)<<setw(50)<< "Cumulative GPA: " <<setw(2)<<cum_gpa<<endl; // outputting cumulative GPA
cout<<setw(50)<< "Total credits completed: " <<setw(2)<<tcc<<endl; // outputting total credits completed
infile.close(); // closing my infile- gpa.txt
outfile.close(); // closing my outfile kathHomework5.txt