本题要求输入小时、分钟和秒数,并将其输出。针对时间表示中出现的异常进行处理。例如小时数不应超过
6-3 时间检测
分数 15
全屏浏览
切换布局
作者 李梅莲
单位 许昌学院
本题要求输入小时、分钟和秒数,并将其输出。针对时间表示中出现的异常进行处理。例如小时数不应超过23,分钟不应超过59,秒数不应超过59。此外,以上三个变量均应大于等于0。
函数接口定义:
void Time(int h,int m,int s);
在这里解释接口参数。在这里解释接口参数。例如:其中 h, m和 s 都是用户传入的参数,分别表示时、分、秒,函数应输出对应时间。
裁判测试程序样例:
#include <iostream>
using namespace std;
void Time(int h,intm,int s);
int main( )
{
int h,m,s;
cin>>h>>m>>s;
try
{
Time(h,m,s);
}
catch(const char *arg)
{
cout<<arg<<endl;
}
catch(...)
{
cout<<"I have catched an exception!"<<endl;
}
return 0;
}
/* 请在这里填写答案 */
输入样例:
8 64 50
输出样例:
The time is wrong!
输入样例:
-8 22 30
输出样例:
I have catched an exception!
输入样例:
8 30 20
输出样例:
The current time is: 8:30:20
void Time(int h, int m, int s)
{
if (h > 23 || m > 59 || s > 59)
{
throw "The time is wrong!";
}
else if(h<0||m<0||s<0)
{
throw "I have catched an exception!";
}
else
cout<<"The current time is: "<<h<<":"<<m<<":"<<s;
}