Result should match the sample runs Write a program that ask

Result should match the sample runs
\"Write a program that asks the user if he or she wants to convert from feet and inches to meters and centimeters or from meters and centimeters to feet and inches. The program then performs the desired conversion Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program

Solution

#include<iostream>
using namespace std;
class meter_centimeter
{
private:
float meter;
float centimeter;
public:
meter_centimeter():meter(0),centimeter(0){}
meter_centimeter(float met, float cmet)
{
meter = met;
centimeter = cmet;
}
void get_mc()
{
cout<<\"Enter Meters and Centimeters: \";
cin>>meter;
cin>>centimeter;
}
float return_meter(){return meter;}
float return_centimeter(){return centimeter;}
void display()
{
cout<<\"Conversion: \"<<meter<<\" meter and\"<<centimeter<<\" centimeters\"<<endl;
}
};
class feet_inch
{
private:
float inch;
float feet;
public:
feet_inch():inch(0.0),feet(0.0){}
void get_fi()
{
cout<<\"Enter Feet and inches: \";
cin>>feet;
cin>>inch;
}
feet_inch(meter_centimeter mc)
{
float meters = mc.return_meter() + mc.return_centimeter()/100;
float feets = meters *3.28;
feet = static_cast<int>(meters*3.28);
inch = static_cast<int>((feets - feet)*12);
}
operator meter_centimeter()
{
float feets = feet + inch *12;
float meters = feet/3.28;
float met = static_cast<int> (meters);
float cmet = static_cast<int>((meters - met)*100);
return meter_centimeter(met, cmet);
}
void display()
{
cout<<\"Conversion: \"<<feet<<\" feet and \"<<inch<<\"inches\"<<endl;
}
};

int main()
{
int temp;
char choice;
meter_centimeter mc;
feet_inch fi;

do
{
cout<<\"Enter 1 for feet, inches to meters, centimeters, or\"<<endl;
cout<<\"Enter 2 for meters, centimeters to feet, inches\"<<endl;
cout<<\"Enter your choice: \";
cin>>temp;
switch(temp)
{
case 1:
fi.get_fi();
mc = fi;
mc.display();
break;

case 2:
mc.get_mc();
fi = mc;
fi.display();
break;

default:
cout<<\"Enter 1 or 2 only\";
break;
}
cout<<\"Convet more Enter \'y\' or \'n\': \";
cin>>choice;
}while(choice == \'y\');
return 0;
}

Note: Here i am using do.... while loop for repeat the loop until user enter choice is no

Result should match the sample runs \
Result should match the sample runs \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site