Answer to Question #215894 in C++ for Akssh Kanaujia

Question #215894

Create a class called DISTANCE with data members as feet (int) and inches (float), use parameterised constructor to get the input values of the data members. Write a function to display the output. Create another class called DIST_KM with a data member kilometre (float). Use a parameterized constructor to assign input and a function to display it. In the main function, write a menu-driven program with 1. Convert feet and inches into kilometres 2.Check whether both the distances are equal or not. For option 1, write the conversion function in the source class. For option 2, create a separate object to assign the kilometres and check the equality of distances by overloading the operator (==).  [Note: 1 feet=0.00305km]


1
Expert's answer
2021-07-11T14:39:11-0400
#include <iostream>
using namespace std;


class Distance
{
    private:
        int feet;
        float inch;
        float dist;
    public:
        Distance(int f, float i){
            feet=f;
            inch=i;
            dist=feet+(inch*(1/12));
        }
        void display(){
            cout<<"\nFeet: "<<feet<<endl;
            cout<<"\nInch: "<<inch<<endl;
        }
    
};
class DIST_KM{
    private:
        float kilometre;
    public:
        DIST_KM(float k){
            kilometre=k;
        }
        void display(){
            cout<<"\nKilometers: "<<endl;
        }
       
};
int main()
{
    int ch;
    cout<<"\n1. Convert feet and inches into kilometres \n2. Check whether both the distances are equal or no\n";
    cout<<"\nEnter your choice: ";
    cin>>ch;
    
    if (ch==1){
        DIST_KM e(34);
        Distance r(21,4.5);
        e.display();
        r.display();
    }
    else if(ch==2){
       DIST_KM d1(23);
       Distance d2(12,0.22);
       d1.display();
       d2.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