c++第五次实验
2016-05-20 11:02
323 查看
一、问题及代码
二、运行结果
/* *文件名称:1.cpp *作者:曾魏伟 *完成日期:2016年5月20日 *对任务及求解方法的描述部分: *输入描述:无 *问题描述:类的编写 *程序输出:按要求写出程序 *问题分析:略 *算法分析:略 */ #include<iostream> #include<string> using namespace std; class Teacher { string title; public: void get(string name,int age,string sex,string title);//输入职称、名字、年龄、性别 void show_it(); string name; int age; string sex; }; void Teacher::get(string name,int age,string sex,string title) { this->name=name; this->age=age; this->sex=sex; this->title=title; } void Teacher::show_it() { cout<<"姓名:"<<name<<endl; cout<<"年龄:"<<age<<endl; cout<<"性别:"<<sex<<endl; cout<<"职称:"<<title<<endl; } class Cadre:public Teacher { string post; public: void get1(string post);//输入职务 void showpost(); }; void Cadre::get1(string post) { this->post=post; } void Cadre::showpost() { Teacher::show_it(); cout<<"职务:"<<post<<endl; } class Teacher_Cadre:public Cadre { double wages; public: void get2(double wages);//输入工资 void show();//最终输出 }; void Teacher_Cadre::get2(double wages) { this->wages=wages; } void Teacher_Cadre::show() { Cadre::showpost(); cout<<"工资:"<<wages<<"元"<<endl; } int main() { Teacher_Cadre c; c.get("曾辉",42,"男","副教授"); c.get1("主任"); c.get2(1534.5); c.show(); return 0; }
二、运行结果
相关文章推荐
- c++第六次试验
- c++第七次实验
- c++第六次实验——输出星号图
- c++第五次实验作业
- C++第四次上机作业
- C++第6次实验——项目一输出星号图
- c++第6次实验
- c++第四次实验作业
- c++第六次上机实验——循环复习
- C++基础:各种输入方法总结,cin、cin.get()、cin.getline()、getline()、gets()、getchar()
- C++第六次实验—循环(实验)
- Leetcode #13 in cpp
- c++第三次实验一类和对象2
- STL源码笔记(18)—平衡二叉树AVL(C++封装+模板)
- c++作业6
- c++学习笔记(5):C++ typename的起源与用法
- c++第四次实验
- c++第六次实验-2
- c语言发送邮件
- C++第四次上机实验