Answer to Question #327125 in C++ for Zanies

Question #327125

Q3: Write a program to perform basic to class conversion [Class name: “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-11T07:49:48-0400
#include <iostream>
using namespace std;

class Conversion {
    int feet;
    int inches;
public:
    Conversion (int v=0) {
        feet = v / 12;
        inches = v % 12;
    }
    void print() {
        cout << feet << "\' " << inches << "\"";
    }
};

int main() {
    Conversion c;
    c = 200;

    cout << "Converting 200 to ";
    c.print();

    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