//Fig. 3.5:guowai.cpp
//define class Gradebook that contains a courseName date member
//ang member functions to set its value;
//Creat and manipulate a GradeBook object with these functions.
#include <iostream>
using namespace std;
#include <string>
class GradeBook
{
public:
// function that sets the course name
void setCourseName(string name )
{
courseName = name;
}
//function that get the course name
string getCourseName()
{
return courseName;//return the object's courseName
}
void displayMessage()
{
cout<<"Welcome to the grade book for\n"<<getCourseName()<<"!"<<endl;
}
private :
string courseName;
};//end class GradeBook
int main()
{
string courseName;
};
int main()
{
string nameOfCourse;
Gradebook myGradebook;
cout << "Inatial course name is :" << myGradeBook.getCourseName() << endl;
getline (cin,nameofCourse );
myGradeBook.setCourseName( nameOFCourse);
cout<<end;
myGrade.displayMessage();
return 0;
}
看起来很高级,而且、很简单。
练打字速度。827,二十分钟。