Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

/*Define a class "clock" with the following members:

1.Data members:
i>.hour of int type.
ii>.min of int type.
2.Member function:
i>.read_time(int h, int m).
ii>.add_time(clock1 c1, clock1 c2).
iii>.show_time().
Write a program to input two different objects with values and print their sum.
*/
#include<ashish.h>
class clock1
{
public:
int hour;
int min;
char r;
void read_time(int, int, char);
void show_time();
void add_time(clock1 c1, clock1 c2);
};
void clock1 :: read_time(int h, int m, char a)
{
hour=h;
min=m;
r=a;
}
void clock1 :: show_time()
{
static int p=0;
if(min>=60)
{
min=min-60;
hour++;
}
if(p==1)
{
gotoxy(1,18);cout<<"The time 2 is:= "<<hour<<" hr(s) "<<min<<" min(s)";
gotoxy(25,20);cout<<hour<<" : "<<min<<" "<<r<<"m";
}
if(p==0)
{
cout<<"The time 1 is:= "<<hour<<" hr(s) "<<min<<" min(s)";
gotoxy(25,16);cout<<hour<<" : "<<min<<" "<<r<<"m";
}
p++;
}
void clock1 :: add_time(clock1 c1, clock1 c2)
{
int t, o;
t=c1.hour+c2.hour;
o=c1.min+c2.min;
if(o>=60)
{
o=o-60;
t++;
}
cout<<"The total time is:= "<<t<<"hr(s) "<<o<<"min(s)";
gotoxy(25,25);cout<<t<<" : "<<o<<" "<<r<<"m";
}

void main()
{
clock1 c1, c2, s;
int h, m;
char a;
cout<<"Enter the time 1:=";
gotoxy(25,2);cout<<"HH : MM";
gotoxy(25,4);cout<<"00 : 00 *m";
gotoxy(25,4);cin>>h;
gotoxy(30,4);cin>>m;
gotoxy(33,4);cin>>a;
c1.read_time(h, m, a);
cout<<endl<<endl;
cout<<"Enter the time 2:=";
gotoxy(25,9);cout<<"HH : MM";
gotoxy(25,11);cout<<"00 : 00 *m";
gotoxy(25,11);cin>>h;
gotoxy(30,11);cin>>m;
gotoxy(33,11);cin>>a;
c2.read_time(h, m, a);
cout<<"\n\n";
c1.show_time();
cout<<"\n\n";
c2.show_time();
cout<<"\n\n\n";
s.add_time(c1, c2);
}

You might also like