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>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdio.h>
class distance
{
//int a,b;
public:
inline float cmp(float a,float b)
{
if(a>b)
{
return a;
}else{
return b;
}
}
};
void main()
{
distance d;
float distance1,distance2,result;
clrscr();
cout<<"\nEnter first distance value:-";
cin>>distance1;
cout<<"\nEnter second distance value:-";
cin>>distance2;
// cout<<"\n Result :"<<d.cmp(distance1,distance2);
cout<<"\n Larger distance is : "<<d.cmp(distance1,distance2);
getch();
}
function.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdio.h>
class distance
{
//int a,b;
public:
inline float cmp(float a,float b)
{
if(a>b)
{
return a;
}else{
return b;
}
}
};
void main()
{
distance d;
float distance1,distance2,result;
clrscr();
cout<<"\nEnter first distance value:-";
cin>>distance1;
cout<<"\nEnter second distance value:-";
cin>>distance2;
// cout<<"\n Result :"<<d.cmp(distance1,distance2);
cout<<"\n Larger distance is : "<<d.cmp(distance1,distance2);
getch();
}