: 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 height);
void display();
};
Conversion::Conversion(int height) {
feet = height / 12;
inches = height % 12;
}
void Conversion::display() {
cout << feet <<"\' " << inches << "\"" << endl;
}
int main() {
int height;
cout << "Enter a height (inches): ";
cin >> height;
Conversion c = height;
cout << "The height is ";
c.display();
return 0;
}
Comments
Leave a comment