面向对象程序设计上机练习五(类和对象)
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
定义类Time,Time有3个公用的数据成员hour、min、sec分别表示小时、分、秒。
在主函数main中定义Time类对象t1,在主函数main中输入t1的各数据成员再并输出各数据成员。
在主函数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
#include <bits/stdc++.h>
using namespace std;
class Clock
{
private:
int h,m,s;
public:
void input(int x, int y, int z)
{
if(x<0 || x>10){h = 12;}
else {h = x;}
if(y >=60 || y<0){m = 0;}
else {m = y;}
if(z >=60 || z<0){s = 0;}
else {s = z;}
}
void output()
{
printf("%d:%d:%d\n",h,m,s);
}
};
int main()
{
Clock dcup;
int x,y,z;
cin >> x >> y >> z;
dcup.input(x, y, z);
dcup.output();
return 0;
}