1144-面向对象程序设计上机练习五(类和对象)

来源:互联网 发布:制冷系统理论计算软件 编辑:程序博客网 时间:2024/06/05 04:47
#include <bits/stdc++.h>#define Max 1010000using namespace std;class Time{private:    int hour, minute, second;    void setHour(int x)    {        if(x > 1 && x <= 12)        {            hour = x;        }        else{            hour = 12;        }    }    void setMinute(int y)    {        if(y >= 0 && y < 60)        {            minute = y;        }        else{            minute = 0;        }    }    void setSecond(int z)    {        if(z >= 0 && z < 60)        {            second = z;        }        else{            second = 0;        }    }public:    void setTime(int x, int y, int z)    {        setHour(x);        setMinute(y);        setSecond(z);    }    void showTime()    {        printf("%d:%d:%d\n",hour, minute, second);    }};int main(){    Time time;    int x, y, z;    cin >> x >> y >> z;    time.setTime(x, y, z);    time.showTime();    return 0;}
阅读全文
0 0
原创粉丝点击