N
NotEnough
I have a program assigment due next week. I have a a simple c++ grade
average program below. How do I turn it into an inheritance. Where Grade
is the base class. And Quiztest - Project - LabTest - TestGrade are four
devired class.
/*-------------------------------------------------------------------------------
*File Name: ReadTest.cpp
*Abstract: Implement a class to process a list of grades
*Student:
*Date:
*------------------------------------------------------------------------------*/
#include<iostream>
#include<fstream>
#include<iomanip>
using std::setprecision;
using namespace std;
const int MAXGRADE = 20;
main()
{
ifstream ifl; //input file stream
int g[MAXGRADE];
int nNumGrades;
char junk[30];
//open student grade file
ifl.open("StudentRecord.txt");
if (ifl == NULL)
{
cout << "Could not open the file\n";
exit(0);
}
// loop to run through only the ten student grades
for (int k=0;k<10; k++)
{
ifl >> junk;
cout << junk<< " ";
ifl >> junk;
cout << junk <<endl;
//this loop goes through the 4 groups of grades
for (int j=0;j<4; j++)
{
ifl >> nNumGrades;
cout << nNumGrades <<endl;
//this loop prints each grade.
for (int i=0;i<nNumGrades; i++)
{
ifl >> g;
}
//verify
for (int i=0;i<nNumGrades; i++)
{
cout << g<< ",";
}
int total = 0;
for (int i=0; i<nNumGrades;i++)
{
total += g;
}
cout<< "the total of your grades is "<<total<<endl;
//Average calculation
double dAve = static_cast<double> (total)/nNumGrades;
cout<< " Average: "<<setprecision(2)<<fixed<<dAve<<endl;
cout << endl;
}
}
return 0;
}
average program below. How do I turn it into an inheritance. Where Grade
is the base class. And Quiztest - Project - LabTest - TestGrade are four
devired class.
/*-------------------------------------------------------------------------------
*File Name: ReadTest.cpp
*Abstract: Implement a class to process a list of grades
*Student:
*Date:
*------------------------------------------------------------------------------*/
#include<iostream>
#include<fstream>
#include<iomanip>
using std::setprecision;
using namespace std;
const int MAXGRADE = 20;
main()
{
ifstream ifl; //input file stream
int g[MAXGRADE];
int nNumGrades;
char junk[30];
//open student grade file
ifl.open("StudentRecord.txt");
if (ifl == NULL)
{
cout << "Could not open the file\n";
exit(0);
}
// loop to run through only the ten student grades
for (int k=0;k<10; k++)
{
ifl >> junk;
cout << junk<< " ";
ifl >> junk;
cout << junk <<endl;
//this loop goes through the 4 groups of grades
for (int j=0;j<4; j++)
{
ifl >> nNumGrades;
cout << nNumGrades <<endl;
//this loop prints each grade.
for (int i=0;i<nNumGrades; i++)
{
ifl >> g;
}
//verify
for (int i=0;i<nNumGrades; i++)
{
cout << g<< ",";
}
int total = 0;
for (int i=0; i<nNumGrades;i++)
{
total += g;
}
cout<< "the total of your grades is "<<total<<endl;
//Average calculation
double dAve = static_cast<double> (total)/nNumGrades;
cout<< " Average: "<<setprecision(2)<<fixed<<dAve<<endl;
cout << endl;
}
}
return 0;
}