I really need some help I though I had this figured out but I am having major trouble with the below two parts.
I can't get my output to look like it is suppose to
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.63
The average of
ENG101 Grade: A Credits: 3 Honor points: 12
PSY251 Grade: B Credits: 3 Honor points: 9
is 10.5
The average of 7, 26 and 100 is 44
The average of 39.25, 2.01 and 4.2 is 15.1533
The 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
The beginning i think I have completed
. 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.
CODE
header file
#include <string>
#include <iostream>
using namespace std;
class collegeCourse {
public:
collegeCourse(const string& id, int credits, char score);
collegeCourse() { honorPoints = 0; creditsEarned = 0; grade = 'F';};
friend ostream& operator<<(ostream& out, const collegeCourse& course);
friend collegeCourse operator+(const collegeCourse& l, const collegeCourse& r);
friend collegeCourse operator/(const collegeCourse& l, const collegeCourse& r);
int getCreditsEarned() const { return creditsEarned;}
private:
string courseID;
int honorPoints;
int creditsEarned;
char grade;
};
template <collegeCourse, int>
int average (collegeCourse const& a, collegeCourse const& b, collegeCourse const& c)
{
int credits = (a.getCreditsEarned() + b.getCreditsEarned() + c.getCreditsEarned()) / 3;
return credits;
}
collegeCourse::collegeCourse(const 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;
}
ostream& operator<<(ostream& out, const collegeCourse& course)
{
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;
}
main file
CODE
#include <iostream>
#include "collegeCourse.h"
using namespace std;
template <typename T>
T average(T a, T b)
{
return (a + b) / 2;
}
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 j=average<int>(a,b);
int k=average<int>(a,b,c);
double n=average<double>(d,e,f);
const int collegeCourse = 3;
const int grade = 3;
const int hnrPoints = 3;
char myClass[3];
collegeCourse myClass[3]={collegeCourse("ENG 101", "A", 1), collegeCourse("PSY251", "B", 3), collegeCourse("HIS301", "D", 4)};
average(myClass[0], myClass[1], myClass[2]);
cout << "The average of " << a << ", " << b << ", " << " is: " << j << '\n';
cout << "The average of " << a << ", " << b << ", " << c << " is: " << k << '\n';
cout << "The average of " << d << ", " << e << ", " << f << " is: " <<n << '\n';
cout << " The average of " id << ", Grade: " << score << " Credits: " << credits <<
" Honor Points: " << hnrPoints << " is " << average(myClass[0], myClass[1] << endl;
return 0;
}