Senin, 05 Maret 2012

gradebook

#include <iostream>
#include <stdlib.h>



  #include <string> // program uses C++ standard string class
  using std::string;


  // 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;
     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
     system("pause");
     return 0; // indicate successful termination
  } // end main

Tidak ada komentar:

Posting Komentar