|
//////////////////
//Time.h
/////////////////
#ifndef time_h
#define time_h
class Time{
public:
Time();
void settime(int,int,int);
void printmilitary();
private:
int hour;
int minute;
int second;
};
#endif
//////////////////////////
//Time.cpp
//////////////////////////
#include <iostream>
#include "Time.h"
using namespace std;
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;
}
//////////////////
//main.cpp
/////////////////
#include <iostream>
#include "Time.h"
using namespace std;
int main()
{
Time t;
t.printmilitary();
t.settime(13,27,6);
t.printmilitary();
return 0;
} |
|