- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
c实例教学(类的应用-02)(Cexampleteaching(classapplication-02))
c++实例教学(类的应用-02)(C++ example teaching (class application -02))
9.2 staff file management procedures
This is a simplified employee file management program. Among them, the employees file data and the settings of these data, modify, delete and other operations to form a program module. The program implements the encapsulation function of object oriented programming by processing the file data through the public part of the module ---- the class.
Program / / 6_2.cpp
#includeiostream.h
#includestring.h
Class employee{
Char *name; / / employee name
Short age; / / age
Float salary; / / salary
Public:
Employee ();
Void set_name (char *);
Void set_age (short a) {age=a;}
Void set_salary (float s) {salary=s;}
Void, print ();
~employee () {delete[]name;}
};
Employee:: employee ()
{
Name=0;
Age=0;
Salary=0.0;
}
Void employee:: set_name (char, *n)
{
Name=new char[strlen (n) +1];
Strcpy (name, n);
}
Void employee:: Print ()
{
Cout Name: name;
Cout Age: age;
Cout Salary: salaryendl;
}
Void, main ()
{
Char *na=0;
Short ag=0;
Float sa=0;
Na=new char[10];
Employee emp[5];
For (int i=0; i5; i++)
{
Cinna;
Cinag;
Cinsa;
Emp[i].set_name (Na);
Emp[i].set_age (Ag);
Emp[i].set_salary (SA);
Emp[i].print ();
}
Emp[3].set_salary (5100);
Emp[3].print ();
Emp[1].~employee ();
Cinna;
Emp[1].set_name (Na);
Emp[1].set_age (23);
Emp[1].set_salary (2000);
Emp[1].print ();
}
Explain:
This is a simplified employee file management program in which the 5~33 line defines a Employee class that contains the file data of an employee and several processing functions for these data.
The constructor employee, which is automatically invoked when the image is interpreted. The empty file of an employee is created at this time.
The thirty-ninth line illustrates an array of objects, creating an empty file of five employees at a time.
Set_name (), set_age (), set_salary () three functions can be used to fill in the name, age and salary for the employee file. When you fill in your name, you create an array of characte
您可能关注的文档
- 2008元宵节祝福语(2008 blessings of the Lantern Festival).doc
- 2008年度中国最具竞争力品牌咨询公司20强(2008 China's most competitive brand consulting firm 20).doc
- 2008年东风4型内燃机车乘务员专业知识(2008, Dongfeng 4 type diesel locomotive attendant professional knowledge).doc
- 2008年度工作总结(Summary of work in 2008).doc
- 2007年全国国际货运代理从业人员资格考试(国际货代英语)试卷(2007 National International Freight Forwarders qualification examination (International Freight Forwarding English) test paper).doc
- 2007《活塞式压力计》检定规程释义(Interpretation of verification regulation of piston pressure gauge 2007).doc
- 2008年度新华书店工会工作总结(Summary of trade union work of Xinhua Bookstore in 2008).doc
- 2008年度成都市广播电视节目奖评奖结果(The results of the Chengdu radio and TV program awards in 2008).doc
- 2008年度感动中国十大人物事迹及颁奖词(Deeds and awards speech of moving China's ten great figures in 2008).doc
- 2008年高考英语试题(湖南卷)(2008 college entrance examination English examination (Hunan roll)).doc
- cm9软件中英文对照及可删列表(Cm9 software in English, Chinese and delete list).doc
- cnc 编 程 经 验 总 结(CNC programming experience summary).doc
- cnc机床坐标系的确定及工件坐标系(Determination of CNC machine tool coordinate system and workpiece coordinate system).doc
- cnc编程解说(CNC programming commentary).doc
- container procesure(容器的过程).doc
- coreldraw 10主界面操作快捷键(CorelDRAW 10 main interface operation shortcut key).doc
- coreldraw 工具箱的基本应用(The basic application of the CorelDRAW toolbox).doc
- codelite集成开发环境使用vc编译器开发(The CodeLite integrated development environment is developed using the VC compiler).doc
- controlnet现场总线(ControlNet现场总线).doc
- cpu 显卡(cpu 显卡).doc
文档评论(0)