// 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 using std::cout; using std::cin; using std::endl; #include // 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 /************************************************************************** * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and * * Pearson Education, Inc. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * **************************************************************************/