- 论坛徽章:
- 0
|
#ifndef TIME2_H
#define TIME2_H
class time2{
public:
time2(int=0,int=0,int=0);
void setime(int,int,int);
void printmilitary();
void printstander();
private:
int hour;
int minute;
int second;
};
# endif
#include<iostream.h>
#include "time2.h"
time2::time2(int h,int m,int s){
settime(hor,mi,se);
}
void time2::setime(int h,int m int s){
hour=((h>=0&&h<24)? h:0);
minute=((m>=0&&m<24)? m:0);
second=((s>=0&&s<24)? s:0);
}
void time2::printmilitary(){
cout<<((hour<10)? "0":"" <<hour<<":"<<((minute<10)? "0":"" <<minute<<":"<<second<<endl;
}
void time2::printstander(){
cout<<((hour==0||hour==12)? "0":hour%12)<<":"<<((minute<10)? "0":"" <<minute<<":"<<second<<endl;
}
#include<iostream.h>
#include "time2"
void main(){
time2 t,
t1(1 ,
t2(18,30),
t3(18,30,0);
cout<<"the defult time output is"<<endl;
t.printmilitary();
t.printstander();
cout<<endl;
cout<<"the first time output is"<<endl;
t1.printmilitary();
t1.printstander();
cout<<endl;
cout<<"second time by defult is"<<endl;
t2.printmilitary();
t2.printstander();
cout<<endl;
cout<<"the three time by defult is"<<endl;
t3.printmilitary();
t3.printstander();
cout<<endl;
} |
|