面向对象程序设计上机练习五(类和对象)
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
定义类Time,Time有3个公用的数据成员hour、min、sec分别表示小时、分、秒。
在主函数main中定义Time类对象t1,在主函数main中输入t1的各数据成员再并输出各数据成员。
Input
输入类对象的3个数据成员hour、min、sec。
Output
输出类对象的3个数据成员hour、min、sec。
Example Input
9 10 11
Example Output
9:10:11
Hint
Author
zlh
#include <iostream>
using namespace std;
class time
{
private:
int h;
int m;
int s;
public:
void settime()//赋值成员函数
{
cin >>h>>m>>s;
}
void showtime()//输出成员函数
{
cout <<h<<":"<<m<<":"<<s<< endl;
}
};
//主函数
int main()
{
class time t;
t.settime();
t.showtime();
return 0;
}