じかんしゅつりょく

4295 ワード

//
// main.cpp
// time
//
// Created by     on 1/18/16.
// Copyright © 2016    . All rights reserved.
//

#include <iostream>
using namespace std;

class time {
public:
    time();
    void settime(int , int , int);
    void printMilitary();
    void printstandard();
private:
    int hour;
    int minute;
    int second;
};

time::time() { hour = minute = second = 0; }

void time::settime(int h, int m, int s) {
    hour = (h >= 0 && h < 24) ? h : 0;
    minute = (m >= 0 && m < 60) ? m : 0;
    second = (s >= 0 && s < 60) ? s : 0;
}

void time::printMilitary() {
    cout << ( hour < 10 ? "0" : "") << hour <<":"
    << ( minute < 10 ? "0" : "") << minute << "
"
; } void time::printstandard() { cout << ((hour == 0 || hour == 12 ) ? 12 : hour % 12 ) << ":" << (minute < 10 ? "0" : "") << minute << ":" << (second < 10 ? "0" : "") << second << ( hour < 12 ? "AM" : "PM" ) << "
"
; } int main() { class time t; cout << "The military time is "; t.printMilitary(); cout << "The standard time is "; t.printstandard(); int h, m, s; cin >> h >> m >> s; t.settime(h, m, s); cout << "The military time is "; t.printMilitary(); cout << "The standard time is "; t.printstandard(); return 0; }