0

Hello all, I am trying to finish this program, but am running into some trouble with the main() (I think).

It will output the courseID, but no grade, points, honorPoints, or averages

I think that I have everything overloaded correctly, but am messing up with the array of objects part of it, Am I completely off base here?
any advice or suggestions would be great. Here is directions for the part I am messing up.


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.
Write a main() program that declares 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.

CollegeCourse.h

#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);
    friend double operator / ( collegeCourse &cc, int divisor );
private:
    string courseID;
    int honorPoints;
    int creditsEarned;
    char grade;
};

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 out << course.courseID << ": " << course.creditsEarned
        << " -- " << course.grade << " -- " << course.honorPoints;

        return out;
    }



collegeCourse operator+(const collegeCourse& l, const collegeCourse& r)
    {
        collegeCourse honorPoints;
        honorPoints.courseID = l.courseID + r.courseID;
    
    
        return honorPoints;
    }


collegeCourse operator/(const collegeCourse& l, const collegeCourse& r)

    {
        collegeCourse honorPoints;
        honorPoints.creditsEarned = l.creditsEarned/ r.creditsEarned;
    
    
        return honorPoints;
    }

main.cpp

#include <iostream>
#include "CollegeCourse.h"
using namespace std;

int main()
{
    collegeCourse course[3]={collegeCourse("ENG 101", 'A', 3), collegeCourse("PSY251", 'B', 3), collegeCourse("HIS301", 'D', 4)};

    cout << "The average of " << endl;
    cout << course[0] << endl;
    cout << course[1] << endl;
    cout << " is " << endl;    

    cout << "The average of " << endl;
    cout << course[0] << endl;
    cout << course[1] << endl;
    cout << course[2] << endl;
    cout << " is " << endl;
        
return 0;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by ArkM
0

Reread overloading specifications then have a look at your overloaded operators.
Overloaded operator + must return CollegeCurse (what's a strange idea ;)) and overloaded operator / must return double (why "also"?)...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.