5.18
2015-06-11 01:27
218 查看
#include<iostream> #include<string> using namespace std; class Person //声明基类Person { public: void input() { cout<<"请输入编号:"; cin>>number; cout<<endl; cout<<"请输入姓名:"; cin>>name; cout<<endl; } void print() { cout<<"编号:"<<number<<endl <<"姓名:"<<name<<endl; } protected: string number; string name; }; class Student:public Person{ //声明类Person是类Student的基类 public: void input1() { input(); cout<<"请输入班号:"; cin>>Class; cout<<endl; cout<<"请输入成绩:"; cin>>Mark; cout<<endl; } void print1() { print(); cout<<"班号:"<<Class<<endl <<"成绩:"<<Mark<<endl; } protected: string Class; int Mark; }; class Teacher:public Person{ //声明类Person是类Teacher的基类 public: void input2() { input(); cout<<"请输入职称:"; cin>>Title; cout<<endl; cout<<"请输入部门:"; cin>>Dept; cout<<endl; } void print2() { print(); cout<<"职称:"<<Title<<endl <<"部门:"<<Dept<<endl; } protected: string Title; string Dept; }; int main() { Student s; Teacher t; cout<<"输入学生信息:"<<endl; s.input1(); cout<<"学生数据"<<endl; s.print1(); cout<<endl; cout<<"输入教师信息:"<<endl; t.input2(); cout<<"教师数据"<<endl; t.print2(); return 0; }
相关文章推荐
- 一篇文章学会 git 分支开发
- 渗透测试之手动漏洞利用
- Qt4学习(2)——布局使用(制作登记界面)
- iOS 操作系统架构
- 黑马程序员_网络编程
- iOS 操作系统架构
- 给Tomcat的DOS窗口重命名
- 黑马程序员_84_IO转换流
- sendmsg: no buffer space available
- DuiVision开发教程(17)-对话框
- sendmsg: no buffer space available
- 自定义Button实现圆角和点击效果
- 对于oracle监听器的配置
- 10款免费且开源的项目管理工具
- 10款免费且开源的项目管理工具
- Drawable和Bitmap的区别
- ZedBoard REV-D板子搭载Linaro系统
- 回归模型[regression model]
- 黑马程序员_83_IO字节流
- ERROR org.apache.hadoop.hdfs.server.datanode.DataNode: Incompatible namespaceIDs