Answer to Question #327123 in C++ for Zanies

Question #327123

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:45:25-0400
#include <iostream>


class conversion {
public:
    conversion ();
    conversion(int);
    void display() const;


private:
    int feet;
    int inches;
};


conversion::conversion() : feet(0), inches(0)
{}


conversion::conversion(int x) : feet(x/12), inches(x%12)
{}


void conversion::display() const
{
    std::cout << "feet: " << feet << " inches: " << inches;
}


int main() {
    conversion distance;
    int x;


    std::cout << "Enter a distance in inches: ";
    std::cin >> x;
    distance = x;
    
    std::cout << "It is equal ";
    distance.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