wap to overload the following operators for class distance which stores the distance in feet and inches binary+ to add an object to an integer where the integer should be added to the inches value
#include<iostream>
#include<string>
using namespace std;
class Distance
{
int feet;
int inch;
public:
void getData()
{
cout<<"\nEnter feet,inch : ";
cin>>feet>>inch;
}
void putData()
{
cout<<"\nFeet="<<feet<<", Inch="<<inch;
}
//binary+ to add an object to an integer where the integer should be added to the inches value
void operator +(int inchesNumber)
{
inch+=inchesNumber;
feet += inch / 12;
inch = inch % 12;
}
};
int main(){
int inchesNumber;
Distance d1;
d1.getData();
d1.putData();
cout<<"\n\nEnter the integer to be added to the inches value: ";
cin>>inchesNumber;
d1+inchesNumber;
d1.putData();
cin>>inchesNumber;
return 0;
}
Comments
Leave a comment