Question

In: Computer Science

Implement a program as an object using a class (abstract data type) in C++ that does...

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

Solutions

Expert Solution

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;
}


Related Solutions

Here is a C++ class definition for an abstract data type LinkedList of string objects. Implement...
Here is a C++ class definition for an abstract data type LinkedList of string objects. Implement each member function in the class below. Some of the functions we may have already done in the lecture, that's fine, try to do those first without looking at your notes. You may add whatever private data members or private member functions you want to this class. #include #include typedef std::string ItemType; struct Node { ItemType value; Node *next; }; class LinkedList { private:...
1. Implement the stack abstract data type. Write it as a separate class called Stack. For...
1. Implement the stack abstract data type. Write it as a separate class called Stack. For simplicity the data type to be stored in the stack is String but you can also use generic type. 2. Test your class implementation by calling push() and pop(). If the stack is empty (size equals zero) pop() should return null and print that “stack is empty”. If stack is full (size equals max) push() returns false and prints that “stack is full”. This...
Week 3 In-Class Exercise C++ Payroll Design a PayRoll class that is an abstract data type...
Week 3 In-Class Exercise C++ Payroll Design a PayRoll class that is an abstract data type for payroll. It has data members for an employee’s hourly pay rate, number of hours worked, and total pay for the week. Your class must include the following member functions: a constructor to set the hours and pay rate as arguments, a default constructor to set data members to 0, member functions to set each of the member variables to values given as an...
Program Task (C++) The program should contain an abstract data type (ADT) for an Employee, defined...
Program Task (C++) The program should contain an abstract data type (ADT) for an Employee, defined as follows: struct Employee int id; // unique employee identifier string name; // employee’s full name double rate; // employee’s hourly rate double hours; // how many hours they worked since last pay double taxable; // the current year’s taxable income }; This definition should appear above the main() function. The main() function should include: 1. Declare a single array to hold at most...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book has the following attributes: Book Title (character string); Book Author (character string); Book Price (Floating point number having two decimal places); Count of books on hand (int); The member functions are as follows: A constructor that is used to initialize all four elements of the structure to values inputted by the user; A function that displays in a readable tabular form the contents of...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to create a rectangle with user-specified height and width. 4. Method getArea() that returns...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Method getArea() that returns the area. Method...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT