Answer to Question #325790 in C++ for rahul

Question #325790

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-08T03:47:49-0400
#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 <<" feet " << inches << " inches" << endl;
}

int main() {
    int height;
    cout << "Enter a height (inches): ";
    cin >> height;
    conversion c = height;

    cout << "The height is ";
    c.display();


    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