- 8
- 0
- 约1.48万字
- 约 40页
- 2017-01-01 发布于河南
- 举报
c课件ObjectsandClasses
08 Objects and Classes datatype variable_name = initialization_value; int year = 2010; float score_of_cpp[124]={0}; char *ptr = {“79 golden medal”}; struct point { int x; int y; } centre_point; centre_point.x=0; centre_point.y=0; Consider a computer adventure game Among the objects in the game might be: You, the player Your enemies, e.g. dragons Your weapons Obstacles such as locked doors, rivers, etc. The prize e.g. energy or a fair maiden Consider a computer adventure game Among the objects in the game might be: You, the player A player will have data values to represent certain attributes, e.g. the state of their health or the weapons they possess. A player must be able to perform functions such as walk, run, attack an enemy, and rescue the fair maiden to win. Your enemies, e.g. dragons Your weapons Obstacles such as locked doors, rivers, etc. The prize e.g. energy or a fair maiden pseudo code representations of the classes class player { // functions: walk( ) run( ) jump( ) attack( ) rescue( ) ... //data: state_of_health type_of_weapon ... } ; class player Team[4] ; pseudo code representations of the classes Constructing a class in C++ class bank_account { public: void open( int acc_no, double initial_balance ) ; void deposit( double amount ) ; void withdraw( double amount ) ; void display_balance() ; private: int account_number ; double balance ; } ; private and public members The keywords private and public specify the access control level for the data and function members of the class. Data members declared with private access control are accessible only to member functions of the class and unavailable to any functions that are not members of the class. This is called information hiding and prevents the data from being changed except from within the class. Members declared with public access are accessible in any part of a program. access private and public members The class member function definition class bank_account { public:
您可能关注的文档
最近下载
- 制造业信息化战略规划实施与优化-PDM.docx VIP
- 那智不二越机器人flexgui toolbox操作说明书.pdf VIP
- 智慧工厂-智慧工厂解决方案.docx VIP
- 高中化学解题方法归纳:和量法.doc VIP
- 译林牛津新版高中英语(必修1-3)单词表.pdf VIP
- 包装有限公司分切机安全风险分级清单.docx VIP
- 重庆市西南大学附属中学2025届高三下学期二诊模拟考试物理试卷 含解析.docx VIP
- 【高中英语】《星火英语同步词汇》抗遗忘速记手册.docx VIP
- 成都市锦江区2026届初三一诊(暨期末考试)数学试卷(含答案).docx
- 三坐标 培训教程.pptx VIP
原创力文档

文档评论(0)