如何理解set和get函数
发表于:2025-11-14 作者:千家信息网编辑
千家信息网最后更新 2025年11月14日,如何理解set和get函数,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。文章目录输出结果一个Set函数和一个 Get函数的GradeBo
千家信息网最后更新 2025年11月14日如何理解set和get函数参考程序
如何理解set和get函数,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
文章目录
输出结果
一个Set函数和一个 Get函数的GradeBook类 .而UML图如下所示:
参考程序
// Define class GradeBook that contains a courseName data member// and member functions to set and get its value; // Create and manipulate a GradeBook object.#includeusing 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 the grade book for\n" << getCourseName() << "!" << endl; } // end function displayMessageprivate: string courseName; // course name for this GradeBook}; // end class GradeBook // function main begins program executionint 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; getline( 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 return 0; // indicate successful termination} // end main
输出结果
看完上述内容,你们掌握如何理解set和get函数的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!
函数
内容
方法
更多
结果
问题
输出
束手无策
为此
原因
对此
技能
文章
目录
程序
篇文章
经验
行业
资讯
资讯频道
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
设备软件开发加密
材料开源数据库
化验室网络安全应急措施
临沂阿帕网络技术
网络技术能力是什么
无线网络技术在农业的应用例子
高职网络技术专业该怎么规划
睿帆科技数据库雪球
遵义博文软件开发公司
软件开发程序学校
数据库中2级索引和3级索引
试述数据库设计步骤
数据库的历史视频
南昌软件开发定制平台
计算三级网络技术抽题怎么抽
方舟服务器传送器 ID
金蝶尝试打开的数据库已经被机器
我的世界云梦服务器如何组队
俄罗斯软件开发工资
2021网络安全知识手册
样设计图软件开发
网络安全小语录
花生壳建服务器
计算机网络技术必背
网络安全伴我行4000
dp302打印服务器
软件开发入职前几年
网络安全视频稿
软件开发 个人发展期许
手游切换服务器后