YTU 2435: C++ 习题 输出日期时间--友元函数
2435: C++ 习题 输出日期时间--友元函数
时间限制: 1 Sec 内存限制: 128 MB
提交: 1069 解决: 787
题目描述
设计一个日期类和时间类,编写display函数用于显示日期和时间。要求:display函数作为类外的普通函数,分别在Time和Date类中将display声明为友元函数。在主函数中调用display函数,display函数分别引用Time和Date两个类的对象的私有数据,输出年、月、日和时、分、秒。
输入
年、月、日和时、分、秒
输出
年、月、日和时、分、秒
样例输入
2013 12 23
14 23 50
样例输出
2013/12/23
14:23:50
提示
主函数已给定如下,提交时不需要包含下述主函数
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class Date
{
public:
Date(int y,int m,int d);
int year,month,day;
};
class Time
{
public:
Time(int h,int m,int s);
int hour,minute,second;
};
Date::Date(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
}
void display(const Date &d1,const Time &t1)
{
const Date *a=&d1;
const Time *b=&t1;
cout<<a->year<<"/"<<a->month<<"/"<<a->day<<endl;
cout<<b->hour<<":"<<b->minute<<":"<<b->second<<endl;
}
int main()
{
void display(const Date &,const Time &);
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);
display(d1,t1);
return 0;
}
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class Date
{
public:
Date(int y,int m,int d);
int year,month,day;
};
class Time
{
public:
Time(int h,int m,int s);
int hour,minute,second;
};
Date::Date(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
}
void display(const Date &d1,const Time &t1)
{
const Date *a=&d1;
const Time *b=&t1;
cout<<a->year<<"/"<<a->month<<"/"<<a->day<<endl;
cout<<b->hour<<":"<<b->minute<<":"<<b->second<<endl;
}
int main()
{
void display(const Date &,const Time &);
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);
display(d1,t1);
return 0;
}
YTU 2435: C++ 习题 输出日期时间--友元函数的更多相关文章
- YTU 2436: C++ 习题 输出日期时间--友元类
2436: C++ 习题 输出日期时间--友元类 时间限制: 1 Sec 内存限制: 128 MB 提交: 1243 解决: 690 题目描述 设计一个日期类和时间类,编写display函数用于显 ...
- C++ 习题 输出日期时间--友元函数
Description 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:display函数作为类外的普通函数,分别在Time和Date类中将display声明为友元函数.在主函 ...
- 问题 D: C++ 习题 输出日期时间--友元函数
题目描述 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:display函数作为类外的普通函数,分别在Time和Date类中将display声明为友元函数.在主函数中调用dis ...
- C++ 习题 输出日期时间--友元类
Description 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:将Time类声明为Date类的友元类,通过Time类中的display函数引用Date类对象的私有数据, ...
- javascript两行代码按指定格式输出日期时间
javascript两行代码按指定格式输出日期时间,具体看代码: function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1 ...
- SAP 使用较频繁的日期时间处理函数总结
在ABAP实际开发中,经常需要用到一些日期时间处理函数,个人感觉经常使用到的函数进行一下汇总 1. 根据工厂日历 计划交货日期 和 收货处理时间 来计算 销售计划中计划完工日期,其他类似日期计算等 ...
- Mysql日期时间Extract函数介绍
MySQL日期时间Extract函数的优点在于可以选取日期时间的各个部分,从年一直到微秒,让我们对MySQL日期时间的处理更为轻松. MySQL 日期时间 Extract(选取)函数.1. 选取日期时 ...
- MySQL日期时间处理函数
-- MySQL日期时间处理函数SELECT NOW() FROM DUAL;-- 当前日期时间:2017-05-12 11:41:47-- 在MySQL里也存在和Oracle里类似的dual虚拟表: ...
- JavaScript日期时间格式化函数
这篇文章主要介绍了JavaScript日期时间格式化函数分享,需要的朋友可以参考下 这个函数经常用到,分享给大家. 函数代码: //格式化参数说明: //y:年,M:月,d:日,h:时,m分,s:秒, ...
随机推荐
- 【02】GitHub 工具 Octotree
#推荐一个 GitHub 工具 Octotree Chrome extension 它可以让你在看任何仓库时,获得一个左边的树状图.
- dfs树上的边
by GeneralLiu 一 开 始 学 tarjan 的 强连通分量 , 割边 , 割点 时 没有 学扎实 经过培训 ,发现了些 需要注意的 小细节 举个荔枝 dfs树 上的 边 学了 tar ...
- 转载:K-means聚类算法
转载地址:http://www.cnblogs.com/jerrylead/archive/2011/04/06/2006910.html K-means也是聚类算法中最简单的一种了,但是里面包含的思 ...
- 我是一个线程 - IBM刘欣
来自:码农翻身(微信号:coderising) 作者:IBM刘欣 我是一个线程,我一出生就被编了个号: 0×3704,然后被领到一个昏暗的屋子里, 这里我发现了很多和我一模一样的同伴. 我身边的同伴0 ...
- 【收藏】实战Nginx与PHP(FastCGI)的安装、配置与优化
拜读南非蚂蚁大牛的文章真是有所收获 http://ixdba.blog.51cto.com/2895551/806622 一.什么是 FastCGI FastCGI是一个可伸缩地.高速地在HTTP s ...
- 给Ubuntu更换成163的源(sources.list)Unable to locate package
Refer to http://www.crifan.com/ubuntu_change_sources_list_to_163/ 1. backup /etc/apt/sources.list 2. ...
- Knockout.js用jquery的val设置值不更新
用如下方法,加上change() .val("blah").change()
- 【c++】【转】结构体字节对齐
http://www.cnblogs.com/heyonggang/archive/2012/12/11/2812304.html
- Prime Distance(二次筛素数)
Description The branch of mathematics called number theory is about properties of numbers. One of th ...
- CSDN-markdown基本的语法说明
文件夹 概述 简介Markdown CSDN Markdown的功能支持 标题 Setext形式 atx形式 区块引用 分隔线 强调 列表 无序列表 有序列表 注意事项 链接 自己主动链接 普通文本链 ...