Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Details Design a set of classes that store student grade information. There shou

ID: 3858307 • Letter: D

Question

Details

Design a set of classes that store student grade information. There should be one base class to store common data, and three derived classes that divide the set of students into three categories: English students, History students, and Math students. All data stored in these classes should be private or protected. Any access to class data from outside should be done through public member functions. The base class should allocate storage for the following data (and only this data):

student's first name (you may assume 20 characters or less)

student's last name (you may assume 20 characters or less)

Which course the student is in (English, History, or Math)

Each class should have a function that will compute and return the student's final average, based on the stored grades. All grades are based on a 100 point scale. Here are the grades that need storing for each subject, along with the breakdown for computing each final grade:

English -- Term Paper = 25%, Midterm = 35%, Final Test = 40%

History -- Attendance = 10%, Project = 30%, Midterm = 30%, Final Test = 30%

Math -- There are 5 quizzes, to be averaged into one Quiz Average (which can be a decimal number). Final grade computed as follows:
* Quiz Average = 15%, Test 1 = 25%, Test 2 = 25%, Final Test = 35%

Write a main program (in a separate file) that does the following (in this order):

a) Ask the user for input and output file names. This is the only input and output that should be done from keyboard and to the screen. All other input and output will be to and from files. (See the sample run below).

b) Read the student data from the input file and store it using an array of appropriate type. You should use just one array for all students, not a separate array for each subject (i.e. this will be a heterogeneous list). You will need to allocate this list dynamically, since the size is stored in the input file. (Note that this also means each list item will need to be created dynamically). Each student's data should be stored in a separate object. (Any dynamically allocated space should be cleaned up appropriately with delete when you are finished with it).

Hint: Remember that a heterogeneous list is implemented using an array of pointers to the base class type. And as stated above, this must be created dynamically in this situation. i.e. you will need to use the new operator. If you declare your array like this:
    Student* list[size];
then it is WRONG.

c) Print a summary report to the output file, as specified below. You'll need to use the function that computes the final average when you do this, since the final averages will be included in this summary report.

File formats

Input File -- The first line of the input file will contain the number of students listed in the file. This will tell you how big a list you need. After the first lines, every set of two lines constitutes a student entry. The first line of a student entry is the name, in the format lastName, firstName. Note that a name could include spaces -- the comma will delineate last name from first name. The second line will contain the subject ("English", "History", or "Math"), followed by a list of grades (all integers), all separated by spaces. The order of the grades for each class type is as follows:

English -- Term Paper, Midterm, Final Test
History -- Attendance, Project, Midterm, Final Test
Math -- Quiz 1, Quiz 2, Quiz 3, Quiz 4, Quiz 5, Test 1, Test 2, Final Test

Output File -- The output file that you print should list each student's name (firstName lastName - no extra punctuation between), Final Test grade, final average (printed to 2 decimal places), and letter grade (based on 10 point scale, i.e. 90-100 A, 80-89 B, etc). Output should be separated by subject, with an appropriate heading before each section, and each student's information listed on a separate line, in an organized fashion. (See example below). Data must line up appropriately in columns when multiple lines are printed in the file. At the bottom of the output file, print a grade distribution of ALL students -- how many As, Bs, Cs, etc.

Within each subject in the output file, list the students in alphabetic order, sorted by last name. Do not change the given case (upper/lower case) of the names that were read from the input file when you print the output file, and do not change the output file format. Just print the records in order by last name. This sort needs to be true alphabetical (not just the "lexicographical" sort).

General Requirements

No global variables, other than constants!

All member data of your classes must be private or protected

Use the const qualifier on member functions wherever it is appropriate.

The code for this program should be portable. Test with g++ compiler commands before submitting

You may use any of the standard I/O libraries that have been discussed in class (iostream, iomanip, fstream, as well as C libraries, like cstring, cctype, etc). You may also use the string class library

You may not use any of the other STL (Standard Template Libraries) besides string

Do not use any C++11-only libraries or features

You should have already seen basic C++ file I/O techniques and I/O formatting in your pre-requisite course. If you need a refresher, see the following notes sets from COP 3014, Summer 2010:

File I/O and Stream Objects

Output Stream Formatting

Sample run

Screen input and output: (keyboard input is underlined)

Sample input file: (Get a copy here)


Corresponding output file:

Explanation / Answer

#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<fstream.h>
#include<iomanip.h>
//using namespace std;
class student{
protected:
char f_name[20];
char l_name[20];
char course;
public:
void setData(char a[],char b[],char c)
{
strcpy(f_name,a);
strcpy(l_name,b);
course=c;
}
void printdata()
{
cout<<f_name<<" "<<l_name;
}
char getcourse()
{
return course;
}
};
class eng: protected student
{
float atten,proj,mid,fin;

public:
void setdata_1(float a, float b,float c, float d)
{
atten=a;
proj=b;
mid=c;
fin=d;
}

float avg()
{

return ((0.1*atten)+(0.3*proj)+(0.3*mid)+(0.3*fin));
}
char grade()
{
if(avg()>=90) return 'A';
else if(avg()>=70 && avg()<=90) return 'B';
else return 'C';
}
void display()
{
cout<<" "<<fin<<" "<<setiosflags(ios::fixed)<<setprecision(2)<<avg()<<" "<<grade();
}
};
class hist: protected student
{
float term,mid,fin;
public:
void setdata_1(float a, float b,float c)
{
term=a;
mid=b;
fin=c;
}
float avg()
{
return ((0.1*term)+(0.35*mid)+(0.4*fin));
}
char grade()
{
if(avg()>=90) return 'A';
else if(avg()>=70 && avg()<90) return 'B';
else if(avg()>=60 &&avg()<70) return 'C';
else return 'D';
}
void display()
{
cout<<" "<<fin<<" "<<setiosflags(ios::fixed)<<setprecision(2)<<avg()<<" "<<grade();
}
};
class math: protected student
{
float quiz,t1,t2,fin;
public:
void setdata_1(float a, float b,float c,float d)
{
quiz=a;
t1=b;
t2=c;
fin=d;
}
float avg()
{
return ((0.15*quiz)+(0.25*t1)+(0.25*t2)+(0.35*fin));
}
char grade()
{
if(avg()>=90) return 'A';
else if(avg()>=70 && avg()<=90) return 'B';
else return 'C';
}
void display()
{
cout<<" "<<fin<<" "<<setiosflags(ios::fixed)<<setprecision(2)<<avg()<<" "<<grade();
}
};
int main()
{
char file[50];
int size;

char a[20],b[20],c[20];
cout<<"Enter file name ";
cin>>file;
int j=0,l=0,o=0;;
math m[10];
eng e[10];
hist h[10];
ifstream fin(file);
fin>>size;

student *stud=new student[size];
for(int i=0;i<size;i++)
{

fin>>ws;
fin.getline(a,20,', ');
fin>>ws;
fin.getline(b,20,' ');
fin>>ws;
fin.getline(c,20,' ');
fin>>ws;
stud[i].setData(b,a,c[0]);
//stud[i].printdata();
switch(c[0])
{
case 'M':
{

int a,b,c,d,e,f,g,h;
fin>>a>>ws>>b>>ws>>c>>ws>>d>>ws>>e>>ws>>f>>ws>>g>>ws>>h>>ws;

m[j].setdata_1(((a+b+c+d+e)/5),f,g,h);
// m[j].display();
j++;
break;
}
case 'H':
{
int a,b,c;
fin>>ws>>a>>b>>ws>>c>>ws;
h[l].setdata_1(a,b,c);
// h[l].display();
l++;
break;
}
case 'E':
{
int a,b,c,d;
fin>>ws>>a>>b>>ws>>c>>ws>>d;
e[o].setdata_1(a,b,c,d);
// e[o].display();
o++;
break;
}
}
}
cout<<"Here is the result Student Grade Summary ------------ ";
cout<<"ENGLISH CLASS ";
cout<<"Student name Final Final Avg Letter Grade ";
l=0;

for(i=0;i<size;i++)
{
if(stud[i].getcourse()=='E')
{

stud[i].printdata();
e[l].display();
cout<<endl;
l++;
}
}
cout<<"HISTORY CLASS ";
cout<<"Student name Final Exa Final Avg Letter Grade ";
l=0;

for(i=0;i<size;i++)
{
if(stud[i].getcourse()=='E')
{

stud[i].printdata();
h[l].display();
cout<<endl;
l++;
}
}
cout<<"MATHS CLASS ";
cout<<"Student name Final Exa Final Avg Letter Grade ";
l=0;

for(i=0;i<size;i++)
{
if(stud[i].getcourse()=='E')
{

stud[i].printdata();
m[l].display();
cout<<endl;
l++;
}
}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote