Hi there,
I am trying to get my head around this simple program, but there are things that really don't make sense...
here's the program:
// Fig. 3.5: fig03_05.cpp
// Define class GradeBook that contains a courseName data member
// and member functions to set and get its value;
// Create and manipulate a GradeBook object.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string> // program uses C++ standard string class
using std::string;
using std::getline;
// GradeBook class definition
class GradeBook
{
public:
// function that sets the course name
void setCourseName( string name )
{
courseName = name; // store the course name in the object
} // end function setCourseName
// function that gets the course name
string getCourseName()
{
return courseName; // return the object's courseName
} // end function getCourseName
// function that displays a welcome message
void displayMessage()
{
// this statement calls getCourseName to get the
// name of the course this GradeBook represents
cout << "Welcome to the grade book for\n" << getCourseName() << "!"
<< endl;
} // end function displayMessage
private:
string courseName; // course name for this GradeBook
}; // end class GradeBook
// function main begins program execution
int main()
{
string nameOfCourse; // string of characters to store the course name
GradeBook myGradeBook; // create a GradeBook object named myGradeBook
// display initial value of courseName
cout << "Initial course name is: " << myGradeBook.getCourseName()
<< endl;
// prompt for, input and set course name
cout << "\nPlease enter the course name:" << endl;
getline( cin, nameOfCourse ); // read a course name with blanks
myGradeBook.setCourseName( nameOfCourse ); // set the course name
cout << endl; // outputs a blank line
myGradeBook.displayMessage(); // display message with new course name
return 0; // indicate successful termination
} // end main
Now:
1) Line 19-22: why do we need in line 21
courseName = name;
?
2) line 49:why do we need
<< myGradeBook.getCourseName()
??
In general, I have been looking at this program for over3 hours and I still don't seem to get it completely. Is there any good soul who is willing to explain it to me line by line? I know it might sound as a waste of time for you but I am trying to "get it"! :-/
I think I need some sleep now :zzz:, thanks