I have the code written, compiling and no errors, I just need it to write to a file now.
This is the code I have.
Is the header piece correct?
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using std::ofstream;
using namespace std;
class finalgrade
{
char firstName[20]; //to hold the first name
char lastName[20]; //to hold the last name
int exam1; //to hold Exam-1-Grade
int exam2; //to hold Exam-2-Grade
int homeworkavg; //to hold Homework-Average
int finalexamgrade; //to hold the Final-Exam-Grade
double average;
char grade; //to hold the students letter
public:
static int numStudents;
static int innerCount;
void ReadRecord();
void CalculateGrade();
void WriteRecord();
void ReportSummary();
};
int finalgrade::numStudents=0;
int finalgrade::innerCount=0;
//ReadRecord's function is to read in all of the individual
//Students information and exam grades and store in student_t
void finalgrade::ReadRecord()
{
cout << "Please enter Students First Name: ";
cin >> firstName;
cout << "Please enter student Last name: ";
cin >> lastName;
cout << "Please enter the students First Exam score: ";
cin >> exam1;
cout << "Please enter the students Second Exam score: ";
cin >> exam2;
cout << "Please enter the students Homework Average: ";
cin >> homeworkavg;
cout << "Please enter the students Final Exam Grade: ";
cin >> finalexamgrade;
numStudents++;
}
//CalculateGrade's function is to determine the letter grade
//and average grade for the student
void finalgrade::CalculateGrade()
{
double avg=0;
avg = (exam1*.2)+(exam2*.2)+(homeworkavg*.35)+(.25*finalexamgrade);
average = avg; //send average
if(avg >= 90)grade='A'; //assign letter grade as a *single* character
else if(avg >= 80)grade='B';
else if(avg >= 70)grade='C';
else if(avg >= 60)grade='D';
else grade='F';
}
//WriteRecord's function is to display all the gathered information on
//the screen after the averages and letter grades have been assigned
void finalgrade::WriteRecord()
{
cout << firstName << "\t";
cout << lastName << " \t";
cout << exam1 << " \t";
cout << exam2 << " \t";
cout << homeworkavg << " \t";
cout << average << " \t";
cout << grade << " \t";
//return 0;
}
int main(void)
{
finalgrade Students[20];
//int StudentCount = 0;
finalgrade::numStudents = 0;
int iNo;
do{
cout<<"Enter No of Students between(0 to 20): Enter 0 to Exit: ";
cin>>iNo;
}while (!(iNo >= 0 && iNo <= 20));
for(int j=0; j<iNo; j++)
{
Students[j].ReadRecord();
}
if(finalgrade::numStudents > 0)
cout << "Sr.No\tFirst Name\tLast Name\tExam #1 Grade\tExam #2 Grade\tHomework Average\tFinal Grade\tGrade\n";
for(int j=0; j<finalgrade::numStudents; j++)
{
Students[j].CalculateGrade();
cout<<j+1 << "\t";
Students[j].WriteRecord();
cout<<"\n";
}
system("pause"); //this line was added to cause the screen to pause
return 0;
}
Any help is appreciated. Thank you.