Hi, I kind of need help with my homework. I already have a code but it doesn't seem to work. I'm confused about the parameters I put. I don't know which part I actually messed up. I don't know what else to do. Thank you so much in advance for your help :]
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//Function Prototypes
float gPACalculation(char cGrade);
string honorsDistinction(float fGPA);
void summaryInformation(float fGPA, string sHonorsDistinction);
//Declare Constants
const int SENTINEL = 0;
int main ()
{
//Declare Variables
ifstream inFile; //input file
ofstream outFile; //output file
char cGrade =' '; //grades
float fGPA = 0.0; //GPA
int nTotalGradePoints = 0; //Total points
int nCounter = 0; //counter
string sHonorsDistinction = ""; //honors distinction
string sStudentID = ""; //student id
int nPointsEquivalent = 0; //equivalent points
int nNumberOfGrades = 0; //number of grade
inFile.open("StudentData.txt"); //open input file
if (inFile)
{
outFile.open("SummaryStudentData.txt"); //open output file
inFile >> sStudentID;
inFile >> cGrade; //get grades from input file
fGPA = gPACalculation (cGrade); //call GPA calculation function
sHonorsDistinction = honorsDistinction(fGPA); //call HonorsDistinction function
summaryInformation(fGPA, sHonorsDistinction);
outFile.close(); //closes output file
cout << "Program executed successfully." << endl; //prints success on the screen
cout << "Refer to SummaryStudentData.txt file for output." << endl; //prints refer to the screen
}
else
{
cout << "Couldn't open StudentData.txt." << endl;
cout << "Program terminated." << endl;
}
system("pause");
return 0;
}
float gPACalculation(char cGrade)
{
int nPointsEquivalent = 0;
int nTotalGradePoints = 0;
int nCounter = 0;
ifstream inFile;
float fGPA = 0.0;
while (!inFile.eof()) //while loop not at the end of the input file
{
nTotalGradePoints = 0; //set total number of points to 0
nCounter = 0; //set counter to 0
inFile >> cGrade; //get grades from input file
}
if (cGrade == 'A') //If statement to determine points
nPointsEquivalent = 4; //Points for A
else if (cGrade == 'B')
nPointsEquivalent = 3; //Points for B
else if (cGrade == 'C')
nPointsEquivalent = 2; //Points for C
else if (cGrade == 'D')
nPointsEquivalent = 1; //Points for D
else if (cGrade == 'F')
nPointsEquivalent = 0; //Points for F
fGPA = nTotalGradePoints / nCounter;
return cGrade;
}
string honorsDistinction(float fGPA)
{
//declare variables
string sHonorsDistinction = " ";
if (fGPA > 3.7) //if statement that determines the honor distinction of the equivalent GPA
sHonorsDistinction = "Summa Cum Laude"; //prints summa cum laude
else if ((fGPA < 3.7) && (fGPA > 3.4))
sHonorsDistinction = "Magna Cum Laude"; //prints magna cum laude
else if ((fGPA < 3.4) && (fGPA > 3.1))
sHonorsDistinction = "Cum Laude"; //prints cum laude
return sHonorsDistinction; //returns honor distinction
}
void summaryInformation(float fGPA,string sHonorsDistinction)
{
//declare variables
ifstream inFile; //input file
ofstream outFile; //output file
string sStudentID = "";
inFile >> sStudentID;
outFile << "Summary of Student GPA's and Honors" << endl;
outFile << endl;
outFile << sStudentID << fGPA << sHonorsDistinction << endl;
return;
}