Create a class distance which contains feet and inch as a data member. Overhead = =, operator for the same class.Create necessary functions and constructors too.
CODING:
#include<iostream.h>
#include<conio.h>
class distance
{
float feet,inch;
public:
void get()
{
cout<<"Enter the Feet:";
cin>>feet;
cout<<"Enter the Inch:";
cin>>inch;
}
void disp()
{
cout<<"Enter the Feet:"<<feet;
cout<<"Enter the Inch:"<<inch;
}
void operator ==(distance &);
};
void distance::operator ==(distance &s1)
{
if(feet==s1.feet && inch==s1.inch)
cout<<"Both DISTANCE SAME.";
else
cout<<"DISTANCE ARE NOT SAME.";
}
void main()
{
float a,b;
distance o1,o2;
clrscr();
cout<<"FIRST DISTANCE:\n";o1.get();
cout<<"SECOND DISTANCE:\n";o2.get();
o1==o2;
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class distance
{
float feet,inch;
public:
void get()
{
cout<<"Enter the Feet:";
cin>>feet;
cout<<"Enter the Inch:";
cin>>inch;
}
void disp()
{
cout<<"Enter the Feet:"<<feet;
cout<<"Enter the Inch:"<<inch;
}
void operator ==(distance &);
};
void distance::operator ==(distance &s1)
{
if(feet==s1.feet && inch==s1.inch)
cout<<"Both DISTANCE SAME.";
else
cout<<"DISTANCE ARE NOT SAME.";
}
void main()
{
float a,b;
distance o1,o2;
clrscr();
cout<<"FIRST DISTANCE:\n";o1.get();
cout<<"SECOND DISTANCE:\n";o2.get();
o1==o2;
getch();
}
Comments
Post a Comment