Answer to Question #256888 in C++ for xyz

Question #256888

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


1
Expert's answer
2021-10-26T09:14:46-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS