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

Write a script that will assist the user with metric conversions. Your program s

ID: 3673719 • Letter: W

Question

Write a script that will assist the user with metric conversions.

Your program should allow the user to specify the names of the units as strings (e.g., centimeters, liters, and grams, for the metric system and inches, quarts, pounds, for the English system) and should respond to simple questions such as

"How many inches are in 2 meters?"

"How many liters are in 10 quarts?"

Your program should recognize invalid conversions. For example, the question

"How many feet in 5 kilograms?" is not a meaningful question because "feet" is a unit of length whereas "kilograms" is a unit of mass?

Note: use US and Canada metrics for weight and distance.

Explanation / Answer

I have got a C++ code for metric conversion. It is written by using functions.

Code for metric conversion:

#include <iostream.h>

#include <stdlib.h>

char choosestd;

float inch1;

float inch2;

float foot;

float yard;

float mile;

float millimeter;

float centimeter;

float meter1;

float meter2;

float kilometer;

int first;

float firstfunction();

float secondfunction();

float thirdfunction();

float fourthfunction();

float fifthfunction();

float sixthfunction();

float seventhfunction();

float eigthfunction();

float ninthfunction();

float tenthfunction();

int main()

{

      clrscr();

      cout << "*-------------------------------------------------------------* ";

      cout << " ";

      cout << "To (q)uit any time type enter "q" ";

      cout << "To convert from Standard Measurments to Metric enter "1": ";

      cout << "To convert from Metric to Standard Measurments enter "2": ";

      cin >> first;

if (first == 1)

{

      int choosestd;

      cout << "What would you like to convert? ";

      cout << "(1)Inches to Millimeters: ";

      cout << "(2)Inches to Centimeters: ";

      cout << "(3)Feet to Meters: ";

      cout << "(4)Yards to Meters: ";

      cout << "(5)Miles to Kilometers: ";

      cin >> choosestd;

if (choosestd == 1)

     {

      cout << " Enter the number of inches you wish converted: ";

      cin >> inch1;

      cout << "You entered " << inch1 ;

      cout<< " inches, which equals " << firstfunction() << " millimeters. ";

      system("PAUSE");

      return main();

      }

else if     (choosestd == 2)

      {

      cout << " Enter the number of inches you wish converted: ";

      cin >> inch2;

       cout << "You entered " << inch2 << " inches, which equals " << secondfunction() << " centimeters. ";

      system("PAUSE");

      return main();

      }

else if     (choosestd == 3)

      {

      cout << " Enter the number of feet you wish converted: ";

      cin >> foot;

      cout << "You entered " << foot << " feet, which equals " << thirdfunction() << " meters. ";

      system("PAUSE");

      return main();

      }

else if     (choosestd == 4)

      {

      cout << " Enter the number of yards you wish converted: ";

      cin >> yard;

      cout << "You entered " << yard << " yards, which equals " << fourthfunction() << " meters. ";

      system("PAUSE");

      return main();

      }

else if     (choosestd == 5)

      {

      cout << " Enter the number of miles you wish converted: ";

      cin >> mile;

      cout << "You entered " << mile << " miles, which equals " << fifthfunction() << " kilometers. ";

      system("PAUSE");

      return main();

      }

else if ((choosestd != 1) || (choosestd !=2) || (choosestd !=3) || (choosestd !=4) || (choosestd !=5))

      {

      cout<<endl;

      cout << " Thank you for using this program. ";

      cout<<"endl";

      getch();

      return 0;

      }

}

else if (first == 2)

{

      int choosestd;

      cout << "What would you like to convert? ";

      cout << "(1)Millimeters to Inches: ";

      cout << "(2)Centimeters to Inches: ";

      cout << "(3)Meters to Feet: ";

      cout << "(4)Meters to Yards: ";

      cout << "(5)Kilometers to Miles: ";

      cin >> choosestd;

if (choosestd == 1)

     {

      cout << " Enter the number of millimeters you wish converted: ";

      cin >> millimeter;

      cout << "You entered " << millimeter << " millimeters, which equals " << sixthfunction() << " inches. ";

      system("PAUSE");

      return main();

      }

else if     (choosestd == 2)

      {

      cout << " Enter the number of centimeters you wish converted: ";

      cin >> centimeter;

       cout << "You entered " << centimeter << " centimeters, which equals " << seventhfunction() << " inches. ";

      system("PAUSE");

      return main();

      }

else if     (choosestd == 3)

      {

      cout << " Enter the number of meters you wish converted: ";

      cin >> meter1;

      cout << "You entered " << meter1 << " meters, which equals " << eigthfunction() << " feet. ";

      system("PAUSE");

      return main();

      }

else if     (choosestd == 4)

      {

      cout << " Enter the number of meters you wish converted: ";

      cin >> meter2;

      cout << "You entered " << meter2 << " meters, which equals " << ninthfunction() << " yards. ";

      system("PAUSE");

      return main();

      }

else if     (choosestd == 5)

      {

      cout << " Enter the number of kilometers you wish converted: ";

      cin >> kilometer;

      cout << "You entered " << kilometer << " kilometers, which equals " << tenthfunction() << " miles. ";

      system("PAUSE");

      return main();

      }

else if ((choosestd != 1) || (choosestd !=2) || (choosestd !=3) || (choosestd !=4) || (choosestd !=5))

      {

      int x;

      cout << " Thank you for using this program. ";

      cin >> x;

      return 0;

      }

}

else if ((first != 1) || (first != 2))

{

      int x;

      cout << "End Program. This program was brought to you by              http://www.mcarterbrown.com ";

      cout << "Thank you ";

      cin >> x;

      return 0;

}

}

float firstfunction()

      {

      double x;

      x = (inch1 * 25.4);

      return x;

      }

float secondfunction()

      {

      double x;

      x = (inch2 * 2.54);

      return x;

      }

float thirdfunction()

      {

      float x;

      x = (foot * .3048);

      return x;

      }

float fourthfunction()

      {

      float x;

      x = (yard * .9144);

      return x;

      }

float fifthfunction()

      {

      float x;

      x = (mile * 1.609);

      return x;

      }

float sixthfunction()

      {

      float x;

      x = (millimeter / 25.4);

      return x;

      }

float seventhfunction()

      {

      float x;

      x = (centimeter / 2.54);

      return x;

      }

float eigthfunction()

      {

      float x;

      x = (meter1 / .3048);

      return x;

      }

float ninthfunction()

      {

      float x;

      x = (meter2 / .9144);

      return x;

      }

float tenthfunction()

      {

      float x;

      x = (kilometer / 1.609);

      return x;

      }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote