Your Ad Here

Monday, February 4, 2008

Pass Object As An Argument

/*C++ PROGRAM TO PASS OBJECT AS AN ARGUMEMT. The program Adds the two heights given in feet and inches. */

#include< iostream.h>
#include< conio.h>

class height
{
int feet,inches;
public:
void getht(int f,int i)
{
feet=f;
inches=i;
}
void putheight()
{
cout< < "\nHeight is:"< < feet< < "feet\t"< < inches< < "inches"< < endl;
}
void sum(height a,height b)
{
height n;
n.feet = a.feet + b.feet;
n.inches = a.inches + b.inches;
if(n.inches ==12)
{
n.feet++;
n.inches = n.inches -12;
}
cout< < endl< < "Height is "< < n.feet< < " feet and "< < n.inches< < endl;
}
};
void main()
{
height h,d,a;
clrscr();
h.getht(6,5);
a.getht(2,7);
h.putheight();
a.putheight();
d.sum(h,a);
getch();
}

/**********OUTPUT***********

Height is:6feet 5inches

Height is:2feet 7inches

Height is 9 feet and 0

*/

2 comments:

max said...

thanks good program but i try sam logic but i create display function to display the third object where tow object work as an arument but the compliler is giving error
sanjib

max said...

thanks good program but i try sam logic but i create display function to display the third object where tow object work as an arument but the compliler is giving error
sanjib

Your Ad Here