0

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

Edited by BenJammin89: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by BenJammin89
0

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

Edited by jonsca: n/a

0

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.

This question has already been answered. 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.