Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand set and get functions

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report