Time类 规范时间输入范围

例如写入 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;
}

运行结果为
在这里插入图片描述

发布了10 篇原创文章 · 获赞 0 · 访问量 23

猜你喜欢

转载自blog.csdn.net/qq_44933833/article/details/104918724