I am trying to make a program that will calculate gpa using a transcript from an input file. The transcript includes the title of the subject, the letter grade, and the credits per class. However, I wouldn't know how many courses are in the file. How would I start to write out this program? The only things I can use are ifstream, ofstream, for-loops, if statements, and if-else statements.
Wouldn't the grades just be single letters? Can you assume the class would not be a single letter in name?
I would write this program by scanning the file 1 char at a time and putting them into char* based on spaces (if you cant use strings). I would throw out any char* that are bigger than 1 immediately.
The weight calibration could be a little tricky so you may have to wait until the end of the program and save a char* of grades with an int* of hours, with correlating indices from grade to weight. (do 1 input of grade amout per hour and then divide at the end by total number of hours)
Also, I would assume a standard grading scale based to A B C D F and appropriate weight for each letter grade.
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main ()
{
cahr ch;
ifstream myfile ("example.txt");
int totalPoints = 0, totalPossible = 0;
if (myfile.is_open())
{
while (inFile >> ch)
{
if(ch == 'A')
{
//advance in file to get # of hours
totalPoints += 4 * #hours;
totalPossible+= #hours;
}
if(ch == 'B')
{
//advance in file to get # of hours
totalPoints += 3 * #hours;
totalPossible+= #hours;
}
if(ch == 'C')
{
//advance in file to get # of hours
totalPoints += 2 * #hours;
totalPossible+= #hours;
}
if(ch == 'D')
{
//advance in file to get # of hours
totalPoints += 1 * #hours;
totalPossible++= #hours;
}
if(ch == 'F')
{
//advance in file to get # of hours
totalPossible+= #hours;
}
}
}
else cout << "Unable to open file";
cout<< "GPA: " << totalPoints / totalPossible;
return 0;
}
There must be better criteria for the syntax of the transcript. I am assuming no class can be named A B C D or F. Also, this code would break when a class contained with A B C D or F in the name. Also, I was not able to compile and insure this would work correctly but maybe it will give you a kickstart?