what I have here is a program that reads letters (grades) from a 2D character array and out puts them into a row/column system that shows the grades of 3 subjects for 5 different students.
My next objective is to calculate and display the GPA of each student by adding the 3 grades per student and then dividing it by 3.
This requires that I assign a value to each grade from the array into the format of A = 4, B = 3, C = 2, D = 1, F = 0. But I am having trouble with figuring out how to do this.
// grades.txt
A
A
B
C
C
F
C
D
B
B
A
C
B
A
B
// main.cpp
#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{
char grades[5][3];
int ROW;
int COL;
// opens grades.txt
ifstream inFile;
inFile.open("grades.txt");
if (inFile.fail())
{
cout << "Error! File did not open!... now closing...\n\n";
exit(1);
}
cout << "All Grades\n"
<< "Student" << '\t'
<< "English" << '\t'
<< "History" << '\t'
<< "Math" << '\t' << '\n';
// reads grades.txt into 2D array
for (int ROW = 0; ROW < 5; ROW++)
{
for (int COL = 0; COL < 3; COL++)
{
inFile >> grades[ROW][COL];
}
}
// outputs characters in 2D array
for (int ROW = 0; ROW < 5; ROW++)
{
cout << "#" << ROW+1 << '\t';
for (int COL = 0; COL < 3; COL++)
{
cout << grades[ROW][COL] << '\t';
}
cout << endl;
}
cout << endl;
inFile.close();
return 0;
}