练习5

来源:互联网 发布:免费动漫下载软件 编辑:程序博客网 时间:2024/05/29 05:10
#include <iostream>
using namespace std;
class Time{
public:
    void setTime(int newH,int newM,int newS);
    void showTime();
private:
    int hour,minute,second;
};
void Time::setTime(int newH,int newM,int newS){
    hour=newH;
    minute=newM;
    second=newS;
}
inline void Time::showTime(){
    cout<<hour<<":"<<minute<<":"<<second<<endl;
}
int main(){
    Time mytime;
    int x,y,z;
    cout<<"Please input time:";
    cin>>x>>y>>z;
    mytime.setTime(x,y,z);
    mytime.showTime();
    if(x>12){
        mytime.setTime(x-12,y,z);
        mytime.showTime();
    }
    else{
        mytime.setTime(x+12,y,z);
        mytime.showTime();
    }
    return 0;
}
0 0
原创粉丝点击