十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
如何理解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 class using std::string; using std::getline; // GradeBook class definition class 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 displayMessage private: string courseName; // course name for this GradeBook }; // end class GradeBook // function main begins program execution int 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函数的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!