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.
#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);
}
Comments
Leave a comment