有子对象该怎麽办
来源:互联网 发布:淘宝怎么上传质检报告 编辑:程序博客网 时间:2024/03/28 16:08
Description
Input
num,name,sex,year,month,day 和修改后的year,month,day
Output
num,name,sex,year,month,day
Sample Input
2001 Huang m1970 1 11994 5 26
Sample Output
num:2001name:Huangsex:mbirthday:1994/5/26
#include <iostream>
#include <string>
using namespace std;
class BirthDate {
public:
BirthDate(int,int,int);
void display();
void setbirthday(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:"<<year<<"/"<<month<<"/"<<day<<endl;}void BirthDate::setbirthday(int y,int m,int d){ year=y; month=m; day=d;}
class Teacher
{
public:
Teacher(int,string,char);
void display();
private:
int num;
string name;
char sex;
};Teacher::Teacher(int n,string na,char s):num(n),name(na),sex(s){}void Teacher::display(){ cout<<"num:"<<num<<endl; cout<<"name:"<<name<<endl; cout<<"sex:"<<sex<<endl;}
class Professor:public Teacher
{
public:
Professor(int,string,char,BirthDate);
void display();
void setbirthday(int,int,int);
private:
BirthDate birthday;
};Professor::Professor(int n,string na,char s,BirthDate(b)):Teacher(n,na,s),birthday(b){}void Professor::display(){ Teacher::display(); birthday.display();
}void Professor::setbirthday(int y,int m,int d){ birthday.setbirthday(y, m, d);}/* C++代码 */
int main()
{
int num;
string name;
char sex;
int year,month,day;
cin>>num>>name>>sex;
cin>>year>>month>>day;
Professor prof(num,name,sex,BirthDate(year,month,day));
cin>>year>>month>>day;
prof.setbirthday(year,month,day);
prof.display();
return 0;
}
学习总结:主要子对象哦
- 有子对象该怎麽办
- 有子对象的派生类的构造函数
- 有子对象的派生类的构造函数
- 有子对象的派生类的构造函数
- C++有子对象的派生类的构造函数
- C++有子对象的派生类的构造函数
- 有子对象的派生类的构造函数
- 该月有几天
- C++ 13.2 类赋值操作符----定义该类型对象赋值时会发生什么(有不懂)
- 表单提交时 有一个字段不是来自该表单中的对象时
- hibernate删除父对象提示子对象有记录的问题
- 如何使Python中父对象有的属性子对象都有?
- 9.29 一个方法中有两个Block并且同时操作了一个对象,该对象只会被保留一次
- new一个类对象和使用类名创建一个对象有什么区别?该怎么解决
- 输入一个整形数组,数组中有正数也有负数,求该数组中所以子数组和的最大值
- 【C++继承与派生之二】有子对象的派生类的构造函数
- Unity3D:NGUI Srollview子对象中有Button时,点击不能滚动
- 该注册有何好处
- 查验身份证(15)
- 一起学习 JPA(1)
- host,nslookup
- 打开Eclipse遇到Failed to create the Java Virtual Machine问题
- GUI--Swing组件(1)
- 有子对象该怎麽办
- 关键路径
- 第四章第二十题
- HDU-1050-Moving Tables(C++ && 贪心初步)
- hdu2546 饭卡
- The beginning of my way of the programing
- 【ASP.NET】初次见面
- DataGridView 单元格中内容为链接,字体为蓝色
- Apache Kafka:下一代分布式消息系统