I am not sure if I am doing this assignment correctly, here is what it asks and the code that I have. I am not sure how to do the main to meet the assignments requirements. Any suggestions/advice are appreciated.
a. Create a function template called average(). It will accept two arguments of the same type and computes the arithmetic average, returning a double.
Overload the average() function to work correctly with three arguments.b. Create a class called CollegeCourse with fields for:
the course ID (for example, "INF 114''),
your grade (for example, 'A'),
and the credits earned for the CollegeCourse (for example, 2).
The CollegeCourse constructor accepts values for these fields as arguments.
Calculate a fourth field named honorPoints. This field is 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.c. Overload the +operator() so that honor points for courses can be summed to create a summary CollegeCourse object.
Overload the /operator() so that a CollegeCourse object's honorPoints can be divided by an integer; this function should also return a double.
Overload the <<operator() to display the details of a CollegeCourse.d. Write a main() program that declares several integers, doubles, and CollegeCourse objects.
Instantiate your CollegeCourse objects by creating an array of objects.
Show your CollegeCourses using the +operator() and /operator() to compute the average honorPoints for the CollegeCourses.
Demonstrate that both versions of average() work correctly with integers, doubles, and CollegeCourse objects.
Your input might look like this:
int a=7, b = 26, c = 100;
double d = 39.25, e = 2.01,f = 4.2;
double avg;
[You will also have three CollegeCourse objects containing information like:
"ENG101", 'A', 3
"PSY251", 'B', 3
"HIS301", 'D', 4
(filled via your array of objects).]
and your output would look like this:
The average of 7 and 26 is 16
The average of 39.25 and 2.01 is 20.63The average of
ENG101 Grade: A Credits: 3 Honor points: 12
PSY251 Grade: B Credits: 3 Honor points: 9
is 10.5The average of 7, 26 and 100 is 44
The average of 39.25, 2.01 and 4.2 is 15.1533The 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
is 8.33333
#include <iostream>
#include "collegeCourse.h"
using namespace std;
template <typename T>
T average(T a, T b, T c)
{
return (a + b + c) / 3;
}
int main()
{
int a=7, b = 26, c = 100;
double d = 39.25, e = 2.01, f = 4.2;
double avg;
int k=average<int>(a,b,c);
double n=average<double>(d,e,f);
cout << "The average of " << a << ", " << b << ", " << c << " is: " << k << '\n';
cout << "The average of " << d << ", " << e << ", " << f << " is: " <<n << '\n';
return 0;
}
__________________collegeCourse.h______________________
#include <string>
#include <iostream>
using namespace std;
class collegeCourse {
public:
collegeCourse(const std::string& id, int credits, char score);
collegeCourse() { honorPoints = 0; creditsEarned = 0; grade = 'F';};
friend std::ostream& operator<<(std::ostream& out, const collegeCourse& course);
friend collegeCourse operator+(const collegeCourse& l, const collegeCourse& r);
friend collegeCourse operator/(const collegeCourse& l, const collegeCourse& r);
private:
std::string courseID;
int honorPoints;
int creditsEarned;
char grade;
};
collegeCourse::collegeCourse(const std::string& id, int credits, char score)
{
courseID = id;
creditsEarned = credits;
grade = score;
int points;
switch (grade) {
case 'A': points = 4;
break;
case 'B': points = 3;
break;
case 'C': points = 2;
break;
default: points = 1;
}
honorPoints = points * creditsEarned;
}
std::ostream& operator<<(std::ostream& out, const collegeCourse& course) // no ';' here
{
return cout << course.courseID << ": " << course.creditsEarned
<< " -- " << course.grade << " -- " << course.honorPoints;
return out;
}
collegeCourse operator+(const collegeCourse& l, const collegeCourse& r)
{
int honorPoints;
collegeCourse hnrPoints;
return hnrPoints;
}
collegeCourse operator/(const collegeCourse& l, const collegeCourse& r)
{
int honorPoints;
collegeCourse hnrPoints;
return hnrPoints;
}