simple little program from a book. One of the exercises is to modify it to use displayMessage to output the "Welcome" message and the name of the Professor. Problem is everytime I do it the name of the Course and the professor are the same. What am I doing wrong?
/////////////////////
//main function

#include <iostream>
using namespace std;

#include "3.11.h"

int main()
{
    GradeBook gradeBook1("Ben");
    GradeBook professorName("Jammin");
    return 0;
}

//Seperate Source-Code file

#include "3.11.h"

    GradeBook::GradeBook( string name )
    {
        setCourseName(name),
        setProfessorName(name),
        displayMessage();
    }

    void GradeBook::setCourseName( string name )
    {
        courseName = name;
    }

    void GradeBook::setProfessorName( string name )
    {
        professorName = name;
    }

    string GradeBook::getCourseName()
    {
        return courseName;
    }

    string GradeBook::getProfessorName()
    {
        return professorName;
    }

    void GradeBook::displayMessage()
    {
       cout << "Welcome to the Grade Book for: " << getCourseName() << "!" << endl;
       cout << "\nThis course is presented by: " << getProfessorName() << "!" << endl;
    }

//Header File

#include <iostream>
#include <string>

using namespace std;

class GradeBook
{
public:
    GradeBook( string );
    void setCourseName( string );
    void setProfessorName( string );
    string getCourseName();
    string getProfessorName();
     void displayMessage();
private:
    string courseName;
    string professorName;
};

Have your constructor for Gradebook take two parameters, one for the student's name and one for the professors. As you have it, you are setting both the student and professor name to be the name passed in:

GradeBook::GradeBook( string name )
    {
        setCourseName(name),
        setProfessorName(name),
        displayMessage();
    }

should be something like:

Gradebook::Gradebook(string coursename,string profname)
{
            setCourseName(coursename);
            setProfessorName(profname);
            displayMessage();

}

and change the declaration to GradeBook( string,string );

Have your constructor for Gradebook take two parameters, one for the student's name and one for the professors. As you have it, you are setting both the student and professor name to be the name passed in:

GradeBook::GradeBook( string name )
    {
        setCourseName(name),
        setProfessorName(name),
        displayMessage();
    }

should be something like:

Gradebook::Gradebook(string coursename,string profname)
{
            setCourseName(coursename);
            setProfessorName(profname);
            displayMessage();

}

and change the declaration to GradeBook( string,string );

Awesome. Got it. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.