I need some help with the following assignment. I think I'm pretty close, but I'm missing something. Any help is very much appreciated.
Assignment:
Part 1 : "Create a function template called average(). It will accept two arguments of the same type and computes the arithmetic average. The average is returned as a double.
Overload the average() function to work correctly with three arguments."
Part 2: "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, and calculates a fourth field named honorPoints."
Part 3: "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.
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. Overload the <<operator() to display the details of a CollegeCourse."
Part 4: "Write a main() program that declares several integers, doubles, and CollegeCourses. Instantiate your CollegeCourses by creating an array of objects. Demonstrate that both versions of average() work correctly with different arguments"
#include <iostream>
#include "CollegeCourse.h"
using namespace std;
template <typename T>
T average(T a, T b, T c)
{
return (a + b + c) / 2;
}
int main()
{
cout << average(1, 2, 3) << '\n';
return 0;
}
#include <string>
using namespace std;
class CollegeCourse {
public:
CollegeCourse(const std::string& id, int cred, char score);
friend std::ostream& operator<<(std::ostream& out, const CollegeCourse& course);
private:
std::string courseID;
int honorPoints;
int credits;
char grade;
};
CollegeCourse::CollegeCourse(const std::string& id, int cred, char score)
{
courseID = id;
credits = cred;
grade = score;
{
int points;
switch (grade) {
case 'A': points = 4;
case 'B': points = 3;
case 'C': points = 2;
case 'D': points = 1;
}
honorPoints = points * credits;
}
std::ostream& operator<<(std::ostream& out, const CollegeCourse& course);
{
return out << course.courseID << ": " << course.credits
<< " -- " << course.grade << " -- " << course.honorPoints;
//return 0;
}
CollegeCourse operator+(const CollegeCourse &sum);
{
int hnrPoints;
CollegeCourse hnrPoints;
hnrPoints.sumCourse = honorPoints++;
return hnrPoints;
}
CollegeCourse operator/(const CollegeCourse &number);
{
int hnrPoints;
CollegeCourse hnrPoints;
hnrPoints.sumCourse = honorPoints/number;
return hnrPoints;
}