Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the following program to implement the user interface of the preceding

ID: 3749230 • Letter: C

Question

Complete the following program to implement the user interface of the preceding exercise (above). For simplicity, only the units cm, m, and in are supported. Pleas stay in this format only.

From unit (in, ft, mi, mm, am, m, kom, oz, lb, g, kg, tsp, tbsp, pint, gal, again, uit): in To unit: cnm Enter value: l n2.54 cm From unit (in, ft, mi, mm, cm, m, kom, oz, lb,g, kg, tsp, tbsp, pint, gal, again, uit): again Enter value: 2 2 in S,08 cm From unit (in, ft, mi, mm, cm, m, kom, oz, lb,g, kg, tsp, thsp, pint, gal, again, quit): quit (Program exits)

Explanation / Answer

PROGRAM:

#include <iostream> // for cin, cout
#include <string>
#include <cmath>
using namespace std;
int main()
{
char init_unit[2], sec_unit[2]; //declaration of the conversion units
double conv_val; //declaration of the number to be converted
// Welcome message
cout<< "km m cm mm km m cm mm km m cm mm km m cm mm km m cm mm "
<< "| | "
<< "| Welcome to Topiloe Metric unit converter | "
<< "| | "
<< "km m cm mm km m cm mm km m cm mm km m cm mm km m cm mm ";
//request conversion unit
cout<<"Enter initial conversion unit (mm, cm, m, km): "; //user enters units
cin>>init_unit;
if (init_unit != 'mm'||init_unit !='cm'||init_unit !='m'||init_unit !='km')
{
cerr<<"--> Sorry, unit to convert from is invalid "
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else
{
cout<<"Enter unit to convert to (mm, cm, m, km): "; //user enters units
cin>>sec_unit;
}
if (sec_unit != 'mm'||sec_unit != 'cm'||sec_unit != 'm'||sec_unit != 'km')
{
cout<<"--> Sorry, unit to convert TO is invalid "
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'mm' && sec_unit == 'cm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val*10<<" "<<sec_unit<<endl //cm=mm*10
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'mm' && sec_unit == 'm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val*100<<" "<<sec_unit<<endl //m=mm*100
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'mm' && sec_unit == 'km')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val*100000<<" "<<sec_unit<<endl //km=100000*mm
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'cm' && sec_unit == 'mm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val/10<<" "<<sec_unit<<endl //cm=mm*10
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'cm' && sec_unit == 'm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val*10<<" "<<sec_unit<<endl //cm=m*10
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'cm' && sec_unit == 'mm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val/10<<" "<<sec_unit<<endl //cm=mm*10
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'cm' && sec_unit == 'm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val*10<<" "<<sec_unit<<endl //m=cm*10
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'cm' && sec_unit == 'km')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val*10000<<" "<<sec_unit<<endl //km=10000*cm
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'm' && sec_unit == 'mm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val/100<<" "<<sec_unit<<endl //m=mm*100
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'm' && sec_unit == 'cm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val/10<<" "<<sec_unit<<endl //m=cm*10
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'm' && sec_unit == 'km')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val*1000<<" "<<sec_unit<<endl //km=1000*m
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'km' && sec_unit == 'mm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val/100000<<" "<<sec_unit<<endl //km=100000*mm
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'km' && sec_unit == 'cm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val/10000<<" "<<sec_unit<<endl //km=10000*cm
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
else if (init_unit == 'km' && sec_unit == 'm')
{
cout<<"Enter numerical value to convert: ";
cin>>conv_val;
cout<<"Result of conversion: "<<conv_val<<" is equivalent to "<<conv_val/1000<<" "<<sec_unit<<endl //km=1000*m
<<"Thank you for using Topiloe Metric Unit converter Program ";
}
}