设计Clock类,成员数据包含时(hour)分(minute)秒(second),都是int类型,根据给定的main函数设计必要的成员函数。 main函数已给定,提交时只需要提交main函数外的代码部分。 #include<iostream> using namespace std; //你提交的代码在这里 int main() { Clock c1,c2(12,25,38); cout<<"Show object c1:"; c1.Show(); cout<<"Show object c2:"; c2.Show(); int h,m,s; cin>>h>>m>>s; cout<<"Reset and Show object c1:"; c1.Set(h,m,s); c1.Show(); cin>>h>>m>>s; cout<<"Reset and Show object c2:"; c2.Set(h,m,s); c2.Show(); return 0; } 输入 2行,每行3个整数,分别表示时、分和秒。数据保证合法。 输出 输出包含4行,按照样例输出格式输出。 输入样例 1 0 0 0 23 59 59 输出样例 1 Show object c1:8:16:24 Show object c2:12:25:38 Reset and Show object c1:0:0:0 Reset and Show object c2:23:59:59
时间: 2024-03-23 12:40:32 浏览: 66
```cpp
#include<iostream>
using namespace std;
class Clock{
private:
int hour, minute, second;
public:
Clock(){
hour = 8; minute = 16; second = 24;
}
Clock(int h, int m, int s){
hour = h; minute = m; second = s;
}
void Set(int h, int m, int s){
hour = h; minute = m; second = s;
}
void Show(){
cout << hour << ":" << minute << ":" << second << endl;
}
};
int main() {
Clock c1,c2(12,25,38);
cout<<"Show object c1:";
c1.Show();
cout<<"Show object c2:";
c2.Show();
int h,m,s;
cin>>h>>m>>s;
cout<<"Reset and Show object c1:";
c1.Set(h,m,s);
c1.Show();
cin>>h>>m>>s;
cout<<"Reset and Show object c2:";
c2.Set(h,m,s);
c2.Show();
return 0;
}
```
阅读全文