实验资料报告材料五1.对含有时分秒地时间编程设计2

上传人:枫** 文档编号:507584076 上传时间:2022-11-16 格式:DOC 页数:7 大小:95.50KB
返回 下载 相关 举报
实验资料报告材料五1.对含有时分秒地时间编程设计2_第1页
第1页 / 共7页
实验资料报告材料五1.对含有时分秒地时间编程设计2_第2页
第2页 / 共7页
实验资料报告材料五1.对含有时分秒地时间编程设计2_第3页
第3页 / 共7页
实验资料报告材料五1.对含有时分秒地时间编程设计2_第4页
第4页 / 共7页
实验资料报告材料五1.对含有时分秒地时间编程设计2_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《实验资料报告材料五1.对含有时分秒地时间编程设计2》由会员分享,可在线阅读,更多相关《实验资料报告材料五1.对含有时分秒地时间编程设计2(7页珍藏版)》请在金锄头文库上搜索。

1、word面向对象技术实验报告(五)组 别第十 组学 号班 级实验地点软件实验室二指导教师实验时间2012-6-12(注:一到五条在实验预习时填写,六、七条在实验当中或之后填写)一、实验项目名称:实验五 多态性和虚函数(一) 实验目的:1.理解运行时的多态性和编译时的多态性。 2.掌握运算符重载的两种方法。 3.掌握虚函数的定义和使用方法。 4.掌握抽象类的概念和使用方法。(二)实验要求: 1.对含有时、分、秒的时间编程设计+-运算符的重载。 2.现有一个学校管理系统,在其中包含的处理信息有三个方面,即教师、学生和职工。利用一个菜单来实现对他们的操作。要求使用虚函数。 三、实验环境及要求:多媒体

2、计算机一台Windows XP操作系统Visual C+6.0四、实验原理及步骤:()实验原理:() 重载运算符的使用方式同原有运算符一样,但要明确它的操作数与原操作数的区别。 ()函数被声明为虚函数后,子类继承后,若调用此虚函数,则调用子类中的函数;反之调用基类中的函数。(二)实验步骤:1.打开vc,创建c+源文件; 2.输入程序源代码 3.不断的调试程序,直至程序可以正常运行; 4.记录实验数据。 程序源代码:实验二:#include#include#includeclass person friend class list;protected:char name20;int age;ch

3、ar add40;char tele15;static person *ptr;person *next;public:person (char *,int,char *,char *);virtual void print();virtual void insert();class student:public personfriend class list;int level;float grade_point_average;public:student(char *,int,char *,char *,int,float);void print();void insert();clas

4、s teacher:public personfriend class list;float salary;public:teacher(char *,int,char *,char *,float);void print();void insert();class staff:public personfriend class list;float hourly_wages;public:staff(char *,int,char *,char *,float);void print();void insert();class listperson *root;public:list()ro

5、ot=0;void insert_person(person *node);void remove(char *name);void print_list();person:person(char *name,int age,char *add,char *tele)strcpy(person:name,name);strcpy(person:add,add);strcpy(person:tele,tele);person:age=age;next=0;void person:print()coutnname:namen;coutage: addn;coutaddress:addn;coutt

6、elephone number:telen;student:student(char *name,int age,char *add,char *tele,int level,float grade_point_average):person(name,age,add,tele)student:level=level;student:grade_point_average=grade_point_average;void student:print()person:print();coutgrade point average: grade_point_average;coutlevel;vo

7、id student:insert()ptr=new student(name,age,add,tele,level,grade_point_average);teacher:teacher(char *name,int age,char *add,char *tele,float salary):person(name,age,add,tele)teacher:salary=salary;void teacher:print()person:print();coutsalary: salaryn;void teacher:insert()ptr=new teacher(name,age,ad

8、d,tele,salary);staff:staff(char *name,int age,char *add,char *tele,float hourly_wages):person(name,age,add,tele)staff:hourly_wages=hourly_wages;void staff:print()person:print();couthourly_wages:hourly_wagesname);person *curr_node=root;person *previous=0;while(curr_node!=0&strcmp(curr_node-name,key)n

9、ext;node-insert();node-ptr-next=curr_node;if(previous=0)root=node-ptr;else previous-next=node-ptr;void list:remove(char *name)person *curr_node=root;person *previous=0;while(curr_node!=0&strcmp(curr_node-name,name)!=0)previous=curr_node;curr_node=curr_node-next;if(curr_node!=0&previous=0)root=curr_n

10、ode-next;delete curr_node;else if (curr_node!=0&previous!=0)previous-next=curr_node-next;delete curr_node;void list:print_list()person *cur=root;while(cur!=0)cur-print();cur=cur-next;person *person:ptr=0;void main()list people; student stu(昕,20,02455524,3,54);teacher tea(易,26,563);staff sta(舒,24,7,2

11、0);int input;for(;)cout1-插入学生t;cout2-插入教师t;cout3-插入职工t;cout4-删除职工t;cout5-删除学生t;cout6-删除教师t;cout7-显示信息t;cout0-退出input;switch(input)case 1:people.insert_person(&stu);break;case 2:people.insert_person(&tea);break;case 3:people.insert_person(&sta);break;case 4:people.remove(chenling);break;case 5:people

12、.remove(wangchong);break;case 6:people.remove(lining);break;case 7:people.print_list();coutendl;break;case 0:return;实验一:#includeclass timeprivate:int hour,minute,second;public:time(int h=0, int m=0,int s=0)hour = h; minute = m; second = s;time operator +()second+;if(second=60)minute+;second=0;if(minute = 60)hour+;minute=0;second=0;if(hour = 24)hour=0;minute=0;second=0;return *this;time operator -()if(second=0) second=59;minute-;else second-;return *this; void display() couthour : min

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号