第五章10
来源:互联网 发布:广西广电网络电视 编辑:程序博客网 时间:2024/06/03 11:26
#include <iostream> #include <cstring> using namespace std; class Teacher {public: Teacher(int,char [],char); void display(); private: int num; char name[20]; char sex; }; Teacher::Teacher(int n,char nam[],char s) {num=n; strcpy(name,nam); sex=s; } void Teacher::display() {cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl; } class BirthDate {public: BirthDate(int,int,int); void display(); void change(int,int,int); private: int year; int month; int day; }; BirthDate::BirthDate(int y,int m,int d) {year=y; month=m; day=d; } void BirthDate::display() {cout<<"birthday:"<<month<<"/"<<day<<"/"<<year<<endl;} void BirthDate::change(int y,int m,int d) {year=y; month=m; day=d; } class Professor:public Teacher //教授类 {public: Professor(int,char [],char,int,int,int,float); void display(); void change(int,int,int); private: float area; BirthDate birthday; }; Professor::Professor(int n,char nam[20],char s,int y,int m,int d,float a): Teacher(n,nam,s),birthday(y,m,d),area(a){ } void Professor::display() {Teacher::display(); birthday.display(); cout<<"area:"<<area<<endl; } void Professor::change(int y,int m,int d) {birthday.change(y,m,d); } int main() {Professor prof1(3012,"Zhang",'f',1949,10,1,125.4); cout<<endl<<"original data:"<<endl; prof1.display(); cout<<endl<<"new data:"<<endl; prof1.change(1950,6,1); prof1.display(); return 0; }
0 0
- 第五章10
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 第五章
- 【VB.NET机房重构】外键冲突
- CodeForces 71C Round Table Knights(数学+枚举)
- Android RxJava使用介绍(一) Hello World
- 变革时代 国内通讯云服务厂商对比介绍
- DSP编译器优化
- 第五章10
- 深入理解ThreadLocal
- myeclipse安装findbugs
- JVM指令字符集
- __func__标识符
- linux 命令系列之 基于xinetd服务(66)
- DSP程序汇编级优化
- Duilib编译成静态库
- 如何解决Python2的内存泄漏问题