Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,614 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 954 people online right now. Registration is fast and FREE... Join Now!




Help with Array!

 
Reply to this topicStart new topic

Help with Array!

snyderchip
post 16 Jul, 2008 - 01:26 PM
Post #1


New D.I.C Head

*
Joined: 9 Jul, 2008
Posts: 17


I don't know if this is right but I need my out put to look like this and it is not working.
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

CODE


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;
    }

#include <iostream>
#include <string>
#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;
        collegeCourse myClass[3]={collegeCourse("ENG 101", 'A', 1), collegeCourse("PSY251", 'B', 3), collegeCourse("HIS301", 'D', 4)};


        cout << "The average of " << a << ", " << b << " is: " << average(7, 26) << endl;
        cout << "The average of " << a << ", " << b << ", "  << c << "is: " << average(7, 26, 100) << endl;
        cout << "The average of " << d << ", " << e << ", " << f << " is: " << average(39.25, 2.01, 4.2) << endl;

        collegeCourse anInstance;
        cout << "The average of " << myClass[0] << "and " << myClass[1] << endl;
        cout << " is " << endl;
        

        collegeCourse anInstance;
        cout << "The average of " << myClass[0] << " , " << myClass[1] << " and " << myClass[2] << endl;
        cout << " is " << endl;
        


return 0;
}
User is offlineProfile CardPM

Go to the top of the page

F!st!cuffs
post 17 Jul, 2008 - 05:13 AM
Post #2


D.I.C Head

**
Joined: 15 Jul, 2008
Posts: 55



Thanked 2 times
My Contributions


Your probably gonna have to post collegeCourse.h and what kind of errors your getting for an answer to your problem.
QUOTE

CODE


        collegeCourse anInstance;
        cout << "The average of " << myClass[0] << "and " << myClass[1] << endl;
        cout << " is " << endl;
        

        collegeCourse anInstance;
        cout << "The average of " << myClass[0] << " , " << myClass[1] << " and " << myClass[2] << endl;
        cout << " is " << endl;



If everything prints out here but not printing the average then it might be because your not passing anything to the average function you overloaded earlier
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 02:49AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month