How to understand set and get functions
How to understand set and get functions, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Article catalogue
Output result
The GradeBook class of a Set function and a Get function. The UML figure is as follows:
Reference program
/ / 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 classusing std::string;using std::getline;// GradeBook class definitionclass 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