2436: C++ 习题 输出日期时间--友元类

时间限制: 1 Sec  内存限制: 128 MB

提交: 1243  解决: 690

题目描述

设计一个日期类和时间类,编写display函数用于显示日期和时间。要求:将Time类声明为Date类的友元类,通过Time类中的display函数引用Date类对象的私有数据,输出年、月、日和时、分、秒。

输入

年、月、日和时、分、秒

输出

年、月、日和时、分、秒

样例输入

2013 12 23
14 23 50

样例输出

2013/12/23
14:23:50

提示

主函数已给定如下,提交时不需要包含下述主函数
/* C++代码 */
int main()
{
    int year,month,day;
    cin>>year>>month>>day;
    Date d1(year,month,day);
    int hour,minute,second;
    cin>>hour>>minute>>second;
    Time t1(hour,minute,second);
    t1.display(d1);
    return 0;
}

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include <iostream>
using namespace std;
class Date
{
public:
Date(int y,int m,int d);
int year,month,day;
};
class Time
{
public:
Time(int y,int m,int d);
void display(Date);
int hour,minute,second;
};
void Time::display(Date d)
{
cout<<d.year<<"/"<<d.month<<"/"<<d.day<<endl;
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
Date::Date(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
Time::Time(int y,int m,int d)
{
hour=y;
minute=m;
second=d;
}
int main()
{
int year,month,day;
cin>>year>>month>>day;
Date d1(year,month,day);
int hour,minute,second;
cin>>hour>>minute>>second;
Time t1(hour,minute,second);
t1.display(d1);
return 0;
}

YTU 2436: C++ 习题 输出日期时间--友元类的更多相关文章

  1. YTU 2435: C++ 习题 输出日期时间--友元函数

    2435: C++ 习题 输出日期时间--友元函数 时间限制: 1 Sec  内存限制: 128 MB 提交: 1069  解决: 787 题目描述 设计一个日期类和时间类,编写display函数用于 ...

  2. C++ 习题 输出日期时间--友元类

    Description 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:将Time类声明为Date类的友元类,通过Time类中的display函数引用Date类对象的私有数据, ...

  3. C++ 习题 输出日期时间--友元函数

    Description 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:display函数作为类外的普通函数,分别在Time和Date类中将display声明为友元函数.在主函 ...

  4. 问题 D: C++ 习题 输出日期时间--友元函数

    题目描述 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:display函数作为类外的普通函数,分别在Time和Date类中将display声明为友元函数.在主函数中调用dis ...

  5. javascript两行代码按指定格式输出日期时间

    javascript两行代码按指定格式输出日期时间,具体看代码: function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1 ...

  6. Java日期时间API系列7-----Jdk8中java.time包中的新的日期时间API类的特点

    1.不变性 新的日期/时间API中,所有的类都是不可变的,这对多线程环境有好处. 比如:LocalDateTime 2.关注点分离 新的API将人可读的日期时间和机器时间(unix timestamp ...

  7. Java日期时间API系列13-----Jdk8中java.time包中的新的日期时间API类,时间类转换,Date转LocalDateTime,LocalDateTime转Date等

    从前面的系列博客中可以看出Jdk8中java.time包中的新的日期时间API类设计的很好,但Date由于使用仍非常广泛,这就涉及到Date转LocalDateTime,LocalDateTime转D ...

  8. Java日期时间API系列19-----Jdk8中java.time包中的新的日期时间API类,ZonedDateTime与ZoneId和LocalDateTime的关系,ZonedDateTime格式化和时区转换等。

    通过Java日期时间API系列6-----Jdk8中java.time包中的新的日期时间API类中时间范围示意图:可以很清晰的看出ZonedDateTime相当于LocalDateTime+ZoneI ...

  9. Java日期时间API系列8-----Jdk8中java.time包中的新的日期时间API类的LocalDate源码分析

    目录 0.前言 1.TemporalAccessor源码 2.Temporal源码 3.TemporalAdjuster源码 4.ChronoLocalDate源码 5.LocalDate源码 6.总 ...

随机推荐

  1. Nginx的启动过程

    主要介绍Nginx的启动过程,可以在/core/nginx.c中找到Nginx的主函数main(),那么就从这里开始分析Nginx的启动过程. 涉及到的基本函数 源码:  View Code Ngin ...

  2. Python+selenium(定位一组元素)

    我们熟知Webdriver有8种定位元素的方法,但是当需要定位一组元素的时候,可以使用Webdriver提供的与之对应的8种用于定位一组元素的方法,分别是: find_elements_by_id() ...

  3. 一个监控oracle数据库某个字段值变化并发送邮件报警的脚本

    talk is cheap,here is the code: #!/bin/sh export ORACLE_HOME=/u01/app/oracle/product//client_1/ expo ...

  4. 如何解决安装istio后istioctl命令每次使用都需要重新配置路径

    Kubernetes在安装istio后初次使用istioctl命令时会提示istioctl command not found 这时候如果在istio文件夹的根目录下配置 export PATH=$P ...

  5. Archiving not possible: No primary destinations errors

    If space ran out in an archive destination, after you fix the problem, you may still recieve the fol ...

  6. Intent和IntentFilter简介

    Intent和IntentFilter简介 Intent和IntentFilter简介 意图Intent分类: 显式意图:利用class找到对方,在同一个应用程序类可以方便使用,但是在不同的应用程序无 ...

  7. CodeForces 592D Super M

    先把没用的边去掉,求出包含m个点的最小树.然后求出最小树的直径就可以得到答案了. #include <cstdio> #include <cstring> #include & ...

  8. Delphi接口使用实例介绍

    对于Object Pascal语言来说,最近一段时间最有意义的改进就是从Delphi3开始支持接口(interface),接口定义了能够与一个对象进行交互操作的一组过程和函数.对一个接口进行定义包含两 ...

  9. 【Java源码】集合类-LinkedList

    一.类继承关系 LinkedList和ArrayList都实现了List接口.所以有List的特性,同时LinkedList也实现了Deque,所以它也具有双端队列和栈的特性. public clas ...

  10. [bzoj3998][TJOI2015]弦论_后缀自动机

    弦论 bzoj-3998 TJOI-2015 题目大意:给定一个字符串,求其$k$小子串. 注释:$1\le length \le 5\cdot 10^5$,$1\le k\le 10^9$. 想法: ...