YTU-OJ-Problem D: A代码完善--系统日期

Problem D: A代码完善--系统日期

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 153   Solved: 67
[ Submit][ Status][ Web Board]

Description

注:本题只需要提交填写部分的代码,请按照C++方式提交。

已知某操作系统的默认日期时间格式为 MMDDhhmmYYYY.ss ,其中YYYY表示年,MM表示月,DD表示日,hh表示小时,mm表示分种,ss表示秒。
按要求设计日期时间类DateTime,显示指定格式的日期。

#include <iostream>
#include <stdio.h>
#include <iomanip>
using namespace std;
class Date
{
public:
    Date(int year,int month,int day):year(year),month(month),day(day) {}
    Date(const Date &d)
    {
        this->year=d.year;
        this->month=d.month;
        this->day=d.day;
    }
protected:
    int year;
    int month;
    int day;
};

class Time
{
public:
    Time(int hour,int minute,int seconds):hour(hour),minute(minute),seconds(seconds) {}
    Time(const Time &t)
    {
        this->hour=t.hour;
        this->minute=t.minute;
        this->seconds=t.seconds;
    }
protected:
    int hour;
    int minute;
    int seconds;
};
/*************************
  在此处补充和修改你的代码
class DateTime :protected Date,protected Time
{
public:
    DateTime(Date &d, Time &t )
    void show()
};
**************************/
int main()
{
    int year,month,day;
    cin>>year>>month>>day;
    Date d1(year,month,day);
    int hour,minute,seconds;
    cin>>hour>>minute>>seconds;
    Time t1(hour,minute,seconds);
    DateTime dt(d1,t1);
    dt.show();
    return 0;
}

Input

年 月 日 小时 分钟 秒

Output

按格式MMDDhhmmYYYY.ss显示日期

Sample Input

2014 7 10 10 30 15

Sample Output

071010302014.15

HINT

前导0的输出,printf("%02d",5) ;  显示为 05。


#include <iostream>
#include <stdio.h>
#include <iomanip>
using namespace std;
class Date
{
public:
    Date(int year,int month,int day):year(year),month(month),day(day) {}
    Date(const Date &d)
    {
        this->year=d.year;
        this->month=d.month;
        this->day=d.day;
    }
protected:
    int year;
    int month;
    int day;
};

class Time
{
public:
    Time(int hour,int minute,int seconds):hour(hour),minute(minute),seconds(seconds) {}
    Time(const Time &t)
    {
        this->hour=t.hour;
        this->minute=t.minute;
        this->seconds=t.seconds;
    }
protected:
    int hour;
    int minute;
    int seconds;
};
//在此处补充和修改你的代码
class DateTime :protected Date,protected Time
{
public:
    DateTime(Date &d, Time &t ): Date(d),Time (t){}
    void show()
    {
        /*按格式MMDDhhmmYYYY.ss显示日期
        Sample Input
        2014 /7 10/ 10 30/15
        Sample Output
        0710/1030/2014.15*/
        printf("%02d%02d%02d%02d%d.%02d\n",month,day,hour,minute,year,seconds);
    }
};
//
int main()
{
    int year,month,day;
    cin>>year>>month>>day;
    Date d1(year,month,day);
    int hour,minute,seconds;
    cin>>hour>>minute>>seconds;
    Time t1(hour,minute,seconds);
    DateTime dt(d1,t1);
    dt.show();
    return 0;
}<span style="color:#ff0000;">
</span>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1.编写类MyDate.java 2.该类有如下构造方法 2.1 无参数构造方法public MyDate(),以当前的系统时间构造MyDate对象 2.2 public MyDate(int year, int month, int day), 以指定的年月日构造MyDate对象 3.该类有如下属性 3.1 private int year ;//年 3.2 private int month; //月 3.3 private int day; //日 4.该类有如下方法 4.1 public String after(int day); //返回当前对象代表的日期之后day天的日期,比如当前对象是2008-8-8,调用after(5)以后,应该返回2008-8-13,格式可自定义 4.2 public String before(int day); //返回当前对象代表的日期之前day天的日期,比如当前对象是2008-8-8,调用before(5)以后,应该返回2008-8-3,格式可自定义 4.3 public void setYear(int year); //设置年为指定值year 4.4 public void setMonth(int month); //设置月为指定值month 4.5 public void setDay(int day); //设置日为指定值day 4.6 public int getYear(); //返回当前对象的年 4.7 public int getMonth(); //返回当前对象的月 4.8 public int getDay(); //返回当前对象的日 4.9 public void set (int year, int month, int day); //设置年、月、日为指定的值year、month、day 4.10 public String toString();//以字符串形式返回当前对象的年月日,例如2008年08月08日,格式可自定义 4.11 public boolean equals(MyDate mydate);//当前对象与另一个对象比较,如果两个对象的年月日均相等,则返回true,反之返回false 5.编写TestMyDate.java,在main方法中对MyDate类的各个方法进行测试 6.按照编程规范为MyDate.java编写规范的代码 7.按照java doc API的要求,对代码编写规范的注释,然后利用javadoc.exe命令生成MyDate.java的API doc 8.撰写上机报告
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值