/*write a c++ program to create a class time that contain hour,minute,seconds as data member.
write the member function:
1.to add two object of type time, passed as argument
2.to convert time into total number of seconds
3.to display the time into format like 23-11-2009
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class time
{
public:int h,m,s;
public:void accept();
void add(int a,int b,int c);
void convert();
void display();
};
void time::accept()
{
cout<<"\nenter hour:-";
cin>>h;
cout<<"\nenter minutes:-";
cin>>m;
cout<<"\nenter second:-";
cin>>s;
}
void time::add(int a,int b,int c)
{
cout<<"addition of two object of type time:-";
cout<<"\nhour:-"<<a;
cout<<"\nminutes:-"<<b;
cout<<"\nsecond:-"<<c;
}
void time::convert()
{
int sec=0;
cout<<"\nenter hour:-";
cin>>h;
cout<<"\nenter minutes:-";
cin>>m;
cout<<"\nenter second:-";
cin>>s;
sec=sec+(3600*h);
sec=sec+(60*m);
sec=sec+s;
cout<<"the given time into total number of second is:-"<<sec;
}
void time::display()
{
cout<<"\nenter hour:-";
cin>>h;
cout<<"\nenter minutes:-";
cin>>m;
cout<<"\nenter second:-";
cin>>s;
cout<<"\ntime into date format:"<<h<<"-"<<m<<"-"<<s;
}
int main()
{
time t1,t2,t3;
clrscr();
cout<<"\n\t\t\tfor adding two object of type time\n\n";
t1.accept();
t2.accept();
t3.h=t1.h+t2.h;
t3.m=t1.m+t2.m;
t3.s=t1.s+t2.s;
t3.add(t3.h,t3.m,t3.s);
cout<<"\n\t\t\tto convert time into total number of second\n\n";
t1.convert();
cout<<"\n\n\t\t\tto display time into date format\n\n";
t1.display();
getch();
return 0;
}
/*
for adding two object of type time
enter hour:-3
enter minutes:-6
enter second:-9
enter hour:-1
enter minutes:-2
enter second:-4
addition of two object of type time:-
hour:-4
minutes:-8
second:-13
to convert time into total number of second
enter hour:-1
enter minutes:-2
enter second:-3
the given time into total number of second is:-3723
to display time into date format
enter hour:-6
enter minutes:-3
enter second:-2
time into date format:6-3-2
*/
write the member function:
1.to add two object of type time, passed as argument
2.to convert time into total number of seconds
3.to display the time into format like 23-11-2009
*/
#include<iostream.h>
#include<conio.h>
#include<string.h>
class time
{
public:int h,m,s;
public:void accept();
void add(int a,int b,int c);
void convert();
void display();
};
void time::accept()
{
cout<<"\nenter hour:-";
cin>>h;
cout<<"\nenter minutes:-";
cin>>m;
cout<<"\nenter second:-";
cin>>s;
}
void time::add(int a,int b,int c)
{
cout<<"addition of two object of type time:-";
cout<<"\nhour:-"<<a;
cout<<"\nminutes:-"<<b;
cout<<"\nsecond:-"<<c;
}
void time::convert()
{
int sec=0;
cout<<"\nenter hour:-";
cin>>h;
cout<<"\nenter minutes:-";
cin>>m;
cout<<"\nenter second:-";
cin>>s;
sec=sec+(3600*h);
sec=sec+(60*m);
sec=sec+s;
cout<<"the given time into total number of second is:-"<<sec;
}
void time::display()
{
cout<<"\nenter hour:-";
cin>>h;
cout<<"\nenter minutes:-";
cin>>m;
cout<<"\nenter second:-";
cin>>s;
cout<<"\ntime into date format:"<<h<<"-"<<m<<"-"<<s;
}
int main()
{
time t1,t2,t3;
clrscr();
cout<<"\n\t\t\tfor adding two object of type time\n\n";
t1.accept();
t2.accept();
t3.h=t1.h+t2.h;
t3.m=t1.m+t2.m;
t3.s=t1.s+t2.s;
t3.add(t3.h,t3.m,t3.s);
cout<<"\n\t\t\tto convert time into total number of second\n\n";
t1.convert();
cout<<"\n\n\t\t\tto display time into date format\n\n";
t1.display();
getch();
return 0;
}
/*
for adding two object of type time
enter hour:-3
enter minutes:-6
enter second:-9
enter hour:-1
enter minutes:-2
enter second:-4
addition of two object of type time:-
hour:-4
minutes:-8
second:-13
to convert time into total number of second
enter hour:-1
enter minutes:-2
enter second:-3
the given time into total number of second is:-3723
to display time into date format
enter hour:-6
enter minutes:-3
enter second:-2
time into date format:6-3-2
*/
No comments:
Post a Comment