[YTU]_2906( 多重继承 日期与时间)
生活随笔
收集整理的這篇文章主要介紹了
[YTU]_2906( 多重继承 日期与时间)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目描述
在空缺的地方補全代碼,只需提交補全部分即可
請用C++方式提交
#include <iostream>
using namespace std;
class Time
{
public:
??? void set_time();
??? void show_time();
private:
??? int hour;
??? int minute;
??? int sec;
};
class Date
{
public:
??? void set_date();
??? void show_date();
private:
??? int year;
??? int month;
??? int day;
};
class Clock:public Time,public Date
{
public:
??? void set_Clock();
??? void show_Clock();
};
/******begin*******/
?此處補全缺失代碼 只需提交補充部分即可
/*******end********/
int main()
{
??? Clock c;
??? c.set_Clock();
??? c.show_Clock();
??? return 0;
}
輸入
第一行輸入 時間 分鐘 秒
第二行輸入 年 月 日
每行三個整數
輸出
格式化后的輸入
樣例輸入
22 22 222022 12 22樣例輸出
22:22:222022/12/22#include <iostream> using namespace std; class Time { public:void set_time();void show_time(); private:int hour;int minute;int sec; }; class Date { public:void set_date();void show_date(); private:int year;int month;int day; }; class Clock:public Time,public Date { public:void set_Clock();void show_Clock(); }; void Time::set_time() {cin>>hour>>minute>>sec; } void Date::set_date() {cin>>year>>month>>day; } void Clock::set_Clock() {Time::set_time();Date::set_date(); } void Time::show_time() {cout<<hour<<':'<<minute<<':'<<sec<<endl; } void Date::show_date() {cout<<year<<'/'<<month<<'/'<<day<<endl; } void Clock::show_Clock() {Time::show_time();Date::show_date(); } int main() {Clock c;c.set_Clock();c.show_Clock();return 0; }總結
以上是生活随笔為你收集整理的[YTU]_2906( 多重继承 日期与时间)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU]_2635(P4 游戏中的Hu
- 下一篇: [YTU]_2478( C++习题 虚函