标签:private system public return minute
用含成员函数的类来实现输入和输出时间。
程序:
#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
标签:private system public return minute
原文地址:http://yaoyaolx.blog.51cto.com/10732111/1755356