例如写入 12 80 93
#include <iostream>
#include "myFunction.h"
using namespace std;
int main()
{
Time t1;
t1.setTime(12, 80, 93);
cout << "t1 ";
t1.printUniversal();
return 0;
}
规范输入时间范围
void Time::setTime(unsigned int h, unsigned int m, unsigned int s)
{
hour = (h>=0 && h<24)? h : 0;//问号前 为判断,问号后 为选择 h 或 0
minute = (m>=0 && m<60)? m : 0;
second = (s>=0 && s<60)? s : 0;
}
运行结果为