Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand set and get functions

Shulou Source: shulou.com Published: 2022-06-03 05:44:36 11月18日 Update

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

Tags: Functions content methods more results problems output helpless for this reason skills articles catalogs programs articles experience industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker MariaDB Shulou Information Linux