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

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




error C2511: 'collegeCourse::collegeCourse(const d::string &,c

 
Reply to this topicStart new topic

error C2511: 'collegeCourse::collegeCourse(const d::string &,c

snyderchip
post 16 Jul, 2008 - 10:17 AM
Post #1


New D.I.C Head

*
Joined: 9 Jul, 2008
Posts: 17

can't get this to work. Keep getting error

Error 1 error C2511: 'collegeCourse::collegeCourse(std::string &,char,int)' : overloaded member function not found in 'collegeCourse'

CODE


#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(string& id, char score, int credits)
    {
        courseID = id;
        grade = score;
        creditsEarned = credits;

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

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

        


return 0;
}

User is offlineProfile CardPM

Go to the top of the page

skaoth
post 16 Jul, 2008 - 10:25 AM
Post #2


D.I.C Regular

Group Icon
Joined: 7 Nov, 2007
Posts: 338



Thanked 9 times

Dream Kudos: 100
My Contributions


This looks to be the problem.

Declared like this
CODE

collegeCourse(const string& id, int credits, char score);


implemented like this
CODE

collegeCourse::collegeCourse(string& id, char score, int credits)


notice that the char and int variable has been swapped. The should be in the same order. Either
CODE

collegeCourse(string& id, char score, int credits)
or
collegeCourse(string& id, int credits, char score)

for both the declaration and definition

This post has been edited by skaoth: 16 Jul, 2008 - 10:27 AM
User is offlineProfile CardPM

Go to the top of the page

barnwillyb
post 16 Jul, 2008 - 10:43 AM
Post #3


D.I.C Head

**
Joined: 22 May, 2007
Posts: 55


My Contributions


QUOTE(snyderchip @ 16 Jul, 2008 - 11:17 AM) *

can't get this to work. Keep getting error

Error 1 error C2511: 'collegeCourse::collegeCourse(std::string &,char,int)' : overloaded member function not found in 'collegeCourse'

CODE


#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(string& id, char score, int credits)
    {
        courseID = id;
        grade = score;
        creditsEarned = credits;

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

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

        


return 0;
}




change this: collegeCourse::collegeCourse(string& id, char score, int credits)
to this: collegeCourse::collegeCourse(const string& id, int credits, char score)
User is offlineProfile CardPM

Go to the top of the page

snyderchip
post 16 Jul, 2008 - 12:34 PM
Post #4


New D.I.C Head

*
Joined: 9 Jul, 2008
Posts: 17

great thanks. Now i am having the trouble i think with my operators can anyone help me with this.


I need have my output look like this but I can't get it to pull the average from my arrray.

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.3333


CODE

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


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



This post has been edited by snyderchip: 16 Jul, 2008 - 12:34 PM
User is offlineProfile CardPM

Go to the top of the page

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

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