Monday, January 20, 2014

C++ Program to illustrate Passing and Returning Object

with 0 Comment
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class time
{
int hrs,min,sec;
public:
void gettime(int h,int m,int s)
{
hrs=h;
min=m;
sec=s;
}
void puttime();
time add(time,time);
};
void time::puttime()
{
cout<<"Time:"<<setw(2)<<setfill('0')<<hrs;
cout<<":"<<setw(2)<<setfill('0')<<min;
cout<<":"<<setw(2)<<setfill('0')<<sec;
}
time time::add(time t1,time t2)
{
time t4;
t4.sec=t1.sec+t2.sec;
t4.min=t4.sec/60;
t4.sec=t4.sec%60;
t4.min=t4.min+t1.min+t2.min;
t4.hrs=t4.min/60;
t4.min=t4.min%60;
t4.hrs=t4.hrs+t1.hrs+t2.hrs;
return t4;
}
void main()
{
time t1,t2,t3;
int h,m,s,hrs,min,sec;
clrscr();
cout<<"\nOUTPUT";
cout<<"\n*****";
cout<<"\nEnter the First Time";
cin>>hrs>>min>>sec;
cout<<"\n Enter the Second Time";
cin>>h>>m>>s;
t1.gettime(hrs,min,sec);
t2.gettime(h,m,s);
t3=t3.add(t1,t2);
cout<<"\n";
t1.puttime();
cout<<"\n";
t2.puttime();
cout<<"\n Result\n";
t3.puttime();
getch();
}


------------
OUTPUT:
------------

Illustrate Passing and Retrieving Objects
*********************************
Enter the First Time
(Hour,Minutes,Seconds)
2         45       40

Ente the Second Time
(Hour,Minutes,Seconds)
 3      30         50

Time:02:45:40
TIme:03:30:50

Result:
*****
Time: 06:16:30

0 comments:

Post a Comment

Powered by Blogger.

Blog Archive