Starting from:

$30

CSCI804-Lab 6 A template Function Solved

•            Create a function template named average(…). It accepts two arguments of the same type and computes their arithmetic average. The average is returned as a double 

•            Overload the average(…) function to work correctly with three arguments. 

•            Create a class named CollegeCourse with fields for the course ID (e.g. ‘ENG101’), your grade (e.g. ‘A’) and the credits earned for the CollegeCourse (e.g. 3).   

o   The CollegeCourse constructor accepts values for these fields as arguments, and calculates a forth field named honorPoints. Calculate honorPoints as the product of the grade points (4 for an A, 3 for a B, 2 for a C and 1 for a D) and the credits.  

o   The CollegneCourse has a manipulator setValues(…) accepts values for these fields as arguments, and calculates the forth field named honorPoints. 

o   Overload the + operator so that honor points for courses can be summed to create a summary CollegeCourse object whose course ID is “Total” and grade is determined by ratio of the total honor points and the total credit point. The grade is ‘F’ if the ratio is less than 1. 

o   Overload the / operator so that a CollegeCourse object’s honorPoints can be divided by an integer 

o   Overload the << operator to display the details of a CollegeCourse. 

 

Save the implementation as Averages.cpp. Download the file testAverages.cpp in which declares several integers, doubles and CollegeCourses and verifies that both versions of average(…) work correctly with different arguments.

 

Compile the program like g++ testAverages.cpp  Run the program like.

./a.out 

 

average of 7 and 26 is 16 

 

average of 39.25 and 2.01 is 20.63 

 

average of 

   ENG101 Grade: A Credits: 3 Honor points: 12 

   PSY251 Grade: B Credits: 3 Honor points: 9 

10.5 

 

average of 7, 26 and 100 is 44 

 

average of 39.25, 2.01 and 4.2 is 15.1533 

 

average of 

   ENG101 Grade: A Credits: 3 Honor points: 12 

   PSY251 Grade: B Credits: 3 Honor points: 9 

   HIS301 Grade: D Credits: 4 Honor points: 4 

8.33333 

More products