I am taking my first programming course online at FSU, so I don't have any real help outside of my book. I don't understand how to successfully add a second string data member to my header file and adjust the .cpp file accordingly. The question in the text book asked me to modify an existing example and to add a second data member and perform the following:
Provide a set function and a get function
Modify the constructor
Modify the funciton displayMessage.
I'm sure it's a simple answer and I am lost. I added the instructorName code.
Any direction would be most helpful.
My header:
// Fig. 3.11: GradeBook.h
// GradeBook class definition. This file presents GradeBook's public
// interface without revealing the implementations of GradeBook's member
// functions, which are defined in GradeBook.cpp.
#include <string> // class GradeBook uses C++ standard string class
using std::string;
// GradeBook class definition
class GradeBook
{
public:
GradeBook( string ); // constructor that initializes courseName
void setCourseName( string ); // function that sets the course name
string getCourseName(); // function that gets the course name
void displayMessage(); // function that displays a welcome message
void setInstructorName( string ); //function that sets the instructor's name
string getInstructorName(); // function that gets the instructor's name
private:
string courseName; // course name for this GradeBook
string instructorName; // instructor name for this GradeBook
}; // end class GradeBook
My .cpp:
// Fig. 3.12: GradeBookchanged.cpp
// GradeBook member-function definitions. This file contains
// implementations of the member functions prototyped in GradeBook.h.
#include <iostream>
using std::cout;
using std::endl;
#include "GradeBook.h" // include definition of class GradeBook
// constructor initializes courseName with string supplied as argument
GradeBook::GradeBook( string name, instructor )
{
setCourseName( name ); // call set function to initialize courseName
setInstructorName( instructor); //call set function to initilaize instructorName
} // end GradeBook constructor
// function to set the course name
void GradeBook::setCourseName( string name )
{
courseName = name; // store the course name in the object
} // end function setCourseName
//function to set the instructor's name
void GradeBook::setInstructorName( string instructor)
{
instructorName = instructor;
}
// function to get the course name
string GradeBook::getCourseName()
{
return courseName; // return object's courseName
} // end function getCourseName
//function to get the instructor's name
string GradeBook::getInstructorName()
{
return instructorName; // return objects's instructorName
}
// display a welcome message to the GradeBook user
void GradeBook::displayMessage()
{
// call getCourseName to get the courseName
cout << "Welcome to the grade book for\n" << getCourseName()
<< "!" << "\nThis course is presented by: " << getInstructorName() << endl;
} // end function displayMessage