Question: C++ help How do you make a while loop that can go to different students and print out all the students classes, class credit, grades
C++ help
How do you make a while loop that can go to different students and print out all the students classes, class credit, grades then calculate the gpa of the classes?
This is the code I currently have below:
#include
using namespace std;
int main() {
// Creating the grades.dat file below
string dataname = "grades.dat"; // create the name of the file ofstream outFile; outFile.open(dataname.c_str());
if (outFile.fail()) { // print out a fail
cout
//Student files below to be implemented into the .dat file outFile
//Print success of the student files above cout
// Created the grades.dat file above
//Creating the console print out below
double x = 0; // used to calculate GPA int sum = 0; // passing classes counted int value; // number for each letter grade double gpa = 0; // calculate gpa
/avigating the grades.dat file below string StudentID[10]; string Studentname[10]; string Studentclass[10]; string Studentcredit[10]; string Studentgrade[10];
ifstream inFile; inFile.open(dataname.c_str()); /avigating the grades.dat file above
if (inFile.fail()) { // print out a fail
cout
//collecting data after navigating the .dat file getline(inFile, StudentID[0]); getline(inFile, Studentname[0]);
cout
cout
while (StudentID[0] == 1){
for (int i = 0; i
if (i != 0) {
getline(inFile, StudentID[i]); getline(inFile, Studentname[i]); getline(inFile, Studentclass[i]); getline(inFile, Studentcredit[i]); getline(inFile, Studentgrade[i]);
} else {
getline(inFile, Studentclass[i]); getline(inFile, Studentcredit[i]); getline(inFile, Studentgrade[i]);
}
// grading system below if (Studentgrade[i] == "A") {
value = 4; sum = sum + 1;
} else if (Studentgrade[i] == "B") {
value = 3; sum = sum + 1;
} else if (Studentgrade[i] == "C") {
value = 2; sum = sum + 1;
} else if (Studentgrade[i] == "D") {
value = 1; sum = sum + 0;
} else {
value = 0; sum = sum + 0;
}
// calculating the values and where the class are "eligible" for passing string str = Studentcredit[i]; x = x + value;
cout
}
gpa = (x / sum); } return 0; }
The output should look something like this:

The file grades.dat has been written successfully. Student Name: BOKOW, R. Student ID: 2333021 Course Code Course Credit Course Grade NS201 3 A MG342 3 FA302 1 A Total Semester Course Grade(s) Completed: 3 Semester GPA: 4 Student Name: FALLIN, D. Student ID: 2574063 Course Code Course Credit Course Grade MK106 3 C MA208 3 B CM201 3 C CP101 2 B Total Semester Course Grade(s) Completed: 4 Semester GPA: 2.5 Student Name: KINGSLEY, M. Student ID: 2663628 Course Code Course Credit Course Grade QA140 3 A CM245 3 B EQ521 3 A MK341 3 A CP101 2 B Total Semester Course Grade(s) Completed: 5 Semester GPA: 3.6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
