Untitled
unknown
plain_text
a year ago
1.4 kB
6
Indexable
#include<bits/stdc++.h>
using namespace std;
class time24;
class time12{
int hh,mm;
bool am_pm;
public:
time12(int h,int m,bool am){
hh=h;
mm=m;
am_pm=am;
}
void show(){
cout<<hh<<":"<<mm<<" ";
if(am_pm){
cout<<"am"<<endl;
}
else{
cout<<"pm"<<endl;
}
}
operator time24();
};
class time24{
int hh,mm;
public:
time24(int h,int m){
hh=h;
mm=m;
}
void show(){
cout<<hh<<":"<<mm<<" hours"<<endl;
}
operator time12(){
if(hh>12){
return time12(hh-12,mm,0);
}
else if(hh==0){
return time12(12,mm,1);
}
else if(hh==12){
return time12(12,mm,0);
}
else{
return time12(hh,mm,1);
}
}
};
class timet{
int hh,mm;
public:
timet(int m=0){
hh=m/60;
mm=m%60;
}
operator int(){
return hh*60+mm;
}
void show(){
cout<<hh<<"hours"<<mm<<"minutes"<<endl;
}
};
time12::operator time24(){
if(hh==12){
if(am_pm) return time24(0,mm);
else return time24(12,mm);
}
else if(am_pm){
return time24(hh,mm);
}
else{
return time24(hh+12,mm);
}
}
int main(){
time24 x(00,00);
x.show();
time12 y=x;
y.show();
// time12 x(12,00,1);
// x.show();
// time24 y=x;
// y.show();
// timet aaa(730);
// aaa.show();
//// int s=aaa.operator int();
// int s=aaa;
// cout<<s;
}Editor is loading...
Leave a Comment