1. Write a C++ program using class with data member’s int feet,float inches to represent distance and define function that takes two distance values as arguments and returns the larger one.Include a main program that accepts two distance figures from the user compare them and displays the larger using Inline function.


#include<iostream.h>

#include<conio.h>
class distance
{
public:
int feet;
float inch;
public:
float get()
{
cout<<“\nEnter the distance in Feet: \n”;
cin>>feet;
cout<<“\nEnter the distance in Inches: \n”;
cin>>inch;
inch=inch+(feet*12);
return inch;
}
void operator>(distance &a)
{
if(inch>a.inch)
{
cout<<“\n\nFirst distance is gretter: “<<inch;
}
else
{
cout<<“\n\nSecond distance is greter: “<<a.inch;
}
}
inline float compare(distance &m)
{
return inch>m.inch?inch:m.inch;
}
public: void disp()
{
cout<<inch;
}
};
void main()
{
distance d1,d2,d3;
clrscr();
d1.get();
d2.get();
cout<<“\n\nFirst Distace: “;
d1.disp();
cout<<“\n\nSecond Distace: “;
d2.disp();
d1>d2;
cout<<“\n\nGretter Distance: “<<d1.compare(d2);
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s