首页 > 其他 > 详细

用含成员函数的类来实现输入和输出时间

时间:2016-03-26 08:13:25      阅读:93      评论:0      收藏:0      [点我收藏+]

用含成员函数的类来实现输入和输出时间。

程序:

#include<iostream>

using namespace std;

class Time

{

public:

void set_time();

void show_time();

private:

int hour;

int minute;

int sec;

};


int main()

{

Time t1;

t1.set_time();

t1.show_time();

Time t2;

t2.set_time();

t2.show_time();

system("pause");

return 0;

}


void Time::set_time()

{

cin >> hour;

cin >> minute;

cin >> sec;

}


void Time::show_time()

{

cout<<hour<<":"<<minute<<":"<<sec<<endl;

}

结果:

12 34 11

12:34:11

17 33 23

17:33:23

请按任意键继续. . .


本文出自 “岩枭” 博客,请务必保留此出处http://yaoyaolx.blog.51cto.com/10732111/1755356

用含成员函数的类来实现输入和输出时间

原文:http://yaoyaolx.blog.51cto.com/10732111/1755356

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!