Answer to Question #325352 in C++ for Vipin Singh Bohra

Question #325352

Write a program to perform basic to class conversion [Such as there is a class named: “conversion” with data members: feet and inches (both int)] Convert basic type(int) height in terms of total number of inches into equivalent feet and inches (class type) and display output on screen.


1
Expert's answer
2022-04-07T08:42:26-0400
#include <iostream>

using namespace std;

class Conversion
{
	int feet;
	int inches;
public:
	Conversion(int _inches = 0)
	{
		feet = 0;
		if (_inches >= 12)
		{
			feet += _inches / 12;
			inches = _inches % 12;
		}
		else
			inches = _inches;
	}
	friend ostream& operator<<(ostream&, Conversion&);
};


ostream& operator<<(ostream& os, Conversion& d)
{
	return os << "\nFeets: " << d.feet
		<< "\nInches:" << d.inches;
}




int main()
{
	int value;
	do
	{
		cout << "Please, enter inches value for conversion (0 - exit program): ";
		cin>>value;
		if (value > 0)
		{
			Conversion c(value);
			cout << c << endl;
		}
	} while (value > 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