C++第五次实验
来源:互联网 发布:机器码加密软件破解 编辑:程序博客网 时间:2024/06/05 20:54
/* *文件名称:Ex1-5.cpp *作者:吴培鸿 *完成日期:2016年5月6日 *对任务及求解方法的描述部分: *输入描述:无 *问题描述:1.程序填空 2.类的编写*程序输出:按要求写出程序*问题分析:略 *算法分析:略 */ //1.#include <iostream> #include <string> using namespace std; class Person { string name; // 姓名 int age; // 年龄 public: Person() {} void setname(string na) { name=na; } void setage(int a) { age=a; } string getname() { return name; } int getage() { return age; } }; class Leader:virtual public Person //继承Person的公有部分 { string job; // 职务 string dep; // 部门 public: Leader() { } void setjob(string jb) { job=jb; } void setdep(char dp[]) { dep=dp; } string getjob() { return job; } string getdep() { return dep; } }; class Engineer:virtual public Person // 继承Leader的公有部分 { string major; // 专业 string prof; // 职称 public: Engineer () { } void setmajor(string maj) { major=maj; } void setprof(string pf) { prof=pf; } string getmajor() { return major; } string getprof() { return prof; } }; class chairman:public Leader,public Engineer { } ;// 继承Engineer的公有部分 int main() { chairman c; c.setname("张三"); c.setage(42); c.setjob("处长"); c.setdep("技术处"); c.setmajor("轮机设计"); c.setprof("高级工程师"); cout <<c.getname() << "," <<c.getage()<<" 岁,担任" <<c.getdep() <<c.getjob() <<endl; cout <<c.getprof() << ",从事" << c.getmajor()<< "专业" << "。 " << endl; return 0; } //2.#include<iostream>#include<string>using namespace std;class Person{string name;int age;string sex;public:Person(){ }void get1(string name,int age,string sex);//输入名字、年龄、性别void showit();//一介输出};void Person::get1(string name,int age,string sex){this->name=name;this->age=age;this->sex=sex;}void Person::showit(){cout<<"姓名:"<<name<<endl;cout<<"年龄:"<<age<<endl;cout<<"性别:"<<sex<<endl;}class Teacher:public Person{string title;public:void get2(string title);//输入职称void show_it();//二阶输出};void Teacher::get2(string title){this->title=title;}void Teacher::show_it(){Person::showit();cout<<"职称:"<<title<<endl;}class Cadre:public Teacher{string post;public:Cadre(){}void get3(string post);//输入职务void show();//三阶输出};void Cadre::get3(string post){this->post=post;}void Cadre::show(){Teacher::show_it();cout<<"职务:"<<post<<endl;}class Teacher_Cadre:public Cadre{double wages;public:Teacher_Cadre(){}void get4(double wages);//输入工资void onshow();//最终输出};void Teacher_Cadre::get4(double wages){this->wages=wages;}void Teacher_Cadre::onshow(){Cadre::show();cout<<"工资:"<<wages<<endl;}int main(){Teacher_Cadre t1;t1.get1("曾辉",42,"男");t1.get2("副教授");t1.get3("主任");t1.get4(1534.5);t1.onshow();return 0;}
0 0
- 第五次C语言上机实验报告
- 第五次C程序设计实验报告
- 第五次C语言上机实验报告
- C语言第五次上机实验
- 第五次实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次实验报告
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 稳压电路之5V到3.3V的几种电源方案
- Java 设计模式(八) Proxy(代理)模式及Spring引申
- Path Sum 路径和(注:同时包含得到各个路径的模板:两种不同表达形式的代码)
- 使用脚本和定时任务自动备份管理服务器
- iOS post上传图片
- C++第五次实验
- 第十周-阅读程序
- qemu raw 文件的复制、迁移
- Linux系统编程-文件IO函数
- 多态问题
- 消息队列-metaq
- 17款最佳的代码审查工具
- iOS 9 storyBoard
- GitHub怎么用?GitHub是什么?新手怎么用GitHub?图文并茂,不看都不行