分别定义一个日期类和一个时间类,派生出一个新日期时间类,请以继承方式实现该类,并编写主函数main()测
2个回答
展开全部
看如下代码,注释就不写了
#include<iostream>
using namespace std;
class Adate
{
public:
Adate(int year,int month,int day){Year=year;Month=month;Day=day;}
void ShowAdate(){cout<<Year<<"年"<<Month<<"月"<<Day<<"日";};
private:
int Year;
int Month;
int Day;
};
class Atime
{
public:
Atime(int hour,int minute,int second){Hour=hour;Minute=minute;Second=second;};
void ShowAtime(){cout<<Hour<<"时"<<Minute<<"分"<<Second<<"秒"<<endl;}
private:
int Hour;
int Minute;
int Second;
};
class Atimedate:public Adate,public Atime
{
public:
Atimedate(int year,int month,int day,int hour,int minute,int second):Adate(year,month,day),Atime(hour,minute,second)//继承类的构造函数
{
};
void Showtimedate(){cout<<"现在是:"<<endl;ShowAdate();ShowAtime();};
};
int main()
{
Atimedate a(2010,12,9,13,42,50);
a.Showtimedate();
getchar();
return 0;
}
#include<iostream>
using namespace std;
class Adate
{
public:
Adate(int year,int month,int day){Year=year;Month=month;Day=day;}
void ShowAdate(){cout<<Year<<"年"<<Month<<"月"<<Day<<"日";};
private:
int Year;
int Month;
int Day;
};
class Atime
{
public:
Atime(int hour,int minute,int second){Hour=hour;Minute=minute;Second=second;};
void ShowAtime(){cout<<Hour<<"时"<<Minute<<"分"<<Second<<"秒"<<endl;}
private:
int Hour;
int Minute;
int Second;
};
class Atimedate:public Adate,public Atime
{
public:
Atimedate(int year,int month,int day,int hour,int minute,int second):Adate(year,month,day),Atime(hour,minute,second)//继承类的构造函数
{
};
void Showtimedate(){cout<<"现在是:"<<endl;ShowAdate();ShowAtime();};
};
int main()
{
Atimedate a(2010,12,9,13,42,50);
a.Showtimedate();
getchar();
return 0;
}
展开全部
class Date
{
public:
Date(int year, int month, int day);
string getDate()
{
stringstream str;
string ret;
str<<__year<<"/"<<__month<<"/"<<__day;
str>>ret;
return ret;
}
int setDate(int year, int month, int day);
private:
int __year;
int __month;
int __day;
};
class Time
{
public:
Time(int hour, int minute, int second);
string getTime();
int setTime(int hour, int minute, int second);
private:
int __hour;
int __minute;
int __second
};
class DateTime : public Date, public Time
{
public:
DateTime(int year, int month, int day, int hour, int minute, int second):Date(int year, int month, int day), Time(int hour, int minute, int second){}
string getDateTime(){return getDate().concat(getTime);}
};
//应该是能看懂咯,不完整的自己补上吧^_^
测试留给你自己写,不然你是学不到知识的,如果有问题可以给我留言或直接Hi我。
{
public:
Date(int year, int month, int day);
string getDate()
{
stringstream str;
string ret;
str<<__year<<"/"<<__month<<"/"<<__day;
str>>ret;
return ret;
}
int setDate(int year, int month, int day);
private:
int __year;
int __month;
int __day;
};
class Time
{
public:
Time(int hour, int minute, int second);
string getTime();
int setTime(int hour, int minute, int second);
private:
int __hour;
int __minute;
int __second
};
class DateTime : public Date, public Time
{
public:
DateTime(int year, int month, int day, int hour, int minute, int second):Date(int year, int month, int day), Time(int hour, int minute, int second){}
string getDateTime(){return getDate().concat(getTime);}
};
//应该是能看懂咯,不完整的自己补上吧^_^
测试留给你自己写,不然你是学不到知识的,如果有问题可以给我留言或直接Hi我。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询