Sunday, February 27, 2011

Object as an argument to function

#include<iostream.h>
#include<conio.h>
 class distance
 {
 int feet;
 float inches;
 public:
 distance()
 {
 feet= 5;
 inches= 6.7;
 }
 void getdata()
 {
 cout<<"\nEnter the feet value=";
 cin>>feet;
 cout<<"\nEnter the inches value=";
 cin>>inches;
 }
 void showdata()
 {
 cout<<"\nvalue of distance is="<<feet<<"-"<<inches;
 }
 distance adddist(distance);
 };
 distance distance::adddist(distance d3)
 {
 distance temp;
 temp.feet=feet+d3.feet;
 temp.inches=inches+d3.inches;
 return temp;
 }

void main()
 { clrscr();
 distance d1,d2,d4;
 d1.showdata();
 getch();
 d1.getdata();
 getch();
 d2.getdata();
 getch();
 d4= d1.adddist(d2);
 d4.showdata();
 getch();
 }

No comments:

Post a Comment