I can't seem to get it working properly. Here's what I have thus far.
#include <string>
#include <iostream>
class Student_t
{
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
double average; //to hold the Fina-Exam-Grade
char grade[2]; //to hold the students letter
public:
static int numStudents;
static int innerCount;
void ReadRecord();
void CalculateGrade();
void WriteRecord();
void ReportSummary();
};
int Student_t::numStudents=0;
int Student_t::innerCount=0;
//ReadRecord's function is to read in all of the individual
//Students information and exam grades and store in student_t
void Student_t::ReadRecord()
{
cout << "Please enter student first name:";
cin >> firstName;
cout << "Please enter student last name:";
cin >> lastName;
cout << "Please enter student first exam score <max 10>:";
cin >> exam1;
cout << "Please enter student second exam score <max 10>:";
cin >> exam2;
cout << "Please enter student Homework Average: ";
cin >> homeworkavg;
cout << "The Student's Average is: ";
cin >> average;
cin >> average;
numStudents++;
}
//CalculateGrade's function is to determine the letter grade
//and average grade for the student
void Student_t::CalculateGrade()
{
double avg=0;
avg = (exam1*.2)+(exam2*.2)+(homeworkavg*.35)+(.25*average);
average = avg; //send average
if(avg >= 90)strcpy(grade,"A"); //assign letter grade
else if(avg >= 80)strcpy(grade,"B");
else if(avg >= 70)strcpy(grade,"C");
else if(avg >= 60)strcpy(grade,"D");
else strcpy(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 Student_t::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(int argc, char* argv[])
{
Student_t Students[20];
//int StudentCount = 0;
Student_t::numStudents = 0;
int iNo;
EnterNumberOfStudents:
cout<<"Enter No of Students between(0 to 20): Enter 0 to Exit";
cin>>iNo;
if(!(iNo >= 0 && iNo <= 20))
goto EnterNumberOfStudents;
for(int j=0; j<iNo; j++)
{
Students[j].ReadRecord();
}
if(Student_t::numStudents > 0)
cout << "Sr.No\tFirst Name\tLast Name\tExam #1 Grade\tExam #2 Grade\tHomework Average\tFinal Grade\tGrade\n";
for(j=0; j<Student_t::numStudents; j++)
{
Students[j].CalculateGrade();
cout<<j+1 << "\t";
Students[j].WriteRecord();
cout<<"\n";
}
return 0;
}