In: Computer Science
Implement a program as an object using a class (abstract data type) in C++ that does the following:
1) reads the firstName, lastName and 3 test scores of at least five students.
2) calculate student test score totals, average, letter grade for each student.
3) Display the results in a table format showing firstName, lastName, test1, test2, test3, total, average, letterGrade, of all the students.
3 files .h, .cpp, main.cpp
create an object that can hold records.
must get records from a file.
output must be table format
Mickey Mouse 100 90 80 70
Minnie Mouse 95 100 75 85
Daffy Duck 50 60 70 80
Daisy Duck 100 95 90 80
Tom Jerry 90 100 85 80
grades.h:
#include <iostream>
using namespace std;
struct student
{
string firstName,lastName;
int marks[3];
};
char grade(double marks)
if(marks>=90 && marks<=100)
return 'A';
else if(marks>=80)
return 'B';
else if(marks>=70)
return 'C';
else if(marks>=60)
return 'D';
else
return 'F';
}
int total(student s)
{
return s.marks[0]+s.marks[1]+s.marks[2];
}
double average(int total)
{
return total/3.0;
}
Grades.cpp:
#include "Grades.h"
void print(student s)
{
cout << "First Name : " << s.firstName <<
endl;
cout << "Last Name : " << s.lastName <<
endl;
cout << "Test 1 : " << s.marks[0] << endl;
cout << "Test 2 : " << s.marks[1] << endl;
cout << "Test 3 : " << s.marks[2] << endl;
cout << "Total : " << total(s) << endl;
cout << "Average : " << average(total(s)) <<
endl;
cout << "Grade : " << grade(average(total(s))) <<
endl;
}
student input()
{
student s;
cout << "Input details of student :" << endl;
cout << "First Name : ";
cin >> s.firstName;
cout << "Last Name : ";
cin >> s.lastName;
cout << "Test 1 : ";
cin >> s.marks[0];
cout << "Test 2 : ";
cin >> s.marks[1];
cout << "Test 3 : ";
cin >> s.marks[2];
return s;
}
Main.cpp:
#include "Grades.cpp"
int main()
{
student s[5];
for(int i=0;i<5;i++)
{
s[i]=input();
}
for(int i=0;i<5;i++)
{
print(s[i]);
}
return 0;
}