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

<<<<<<<<<<<<<<<<<<C programme >>>>>>>>>>>>>>>>>> Unit Conversion Description: Wr

ID: 3694874 • Letter: #

Question

<<<<<<<<<<<<<<<<<<C programme >>>>>>>>>>>>>>>>>>

Unit Conversion

Description:

Write a menu driven program with the following options:

1. Subject 1 (with atleast 5 units)

2. Subject 2 (with atleast 5 units)

3. Subject 3 (with atleast 5 units)

4. Subject 4 (with atleast 5 units)

5. Exit

Note: Go to the website http://www.onlineconversion.com and use the information from

There.

Subject means here length, temperature, etc. and the units are centimeters (cm), meters

(m), Fahrenheit, Centigrade, etc. Select any 5 units from any 4 subjects (Length,

Temperature, Speed, etc.) Found in the website mentioned above. After selecting the

Subject a sub menu needs to be shown with at least 5 units. Make last option as return to

Main menu and the program only exit from the main menu. Convert the values by giving

Options to a user which can be the 2 units and a value to be converted. Make the options

User-friendly and make all possible error checking in order to avoid mistakes. (Add 4

More subjects if you are doing the project in group of 2 students).

Save the output of each run in a file along with the details of when it was run (full date

And time). Give an option to the user for opening a new file (with new name or overwrite

The previous one) or append in a previous file.

Practice modular programming by writing functions whenever possible. Follow the

Convention concerning variable names. Insert comments wherever needed.

Hint: Use mode ‘a’ or ‘a+’ in fopen function instead of ‘w’ to append/accumulate the

Results.

Use different functions for each unit and make efficient use of files.

Explanation / Answer

#include<stdio.h>
float length();
float tempreature();
float speed();
float volume();
void main()
{
int choice=0;
float result;
printf("1.Length ");
printf("2.Tempreature ");
printf("3.Speed ");
printf("4.Volume ");
printf("Please enter your selection ");
scanf("%d", &choice);
switch(choice)
{
case 1 : length();   
case 2 : tempreature();
case 3 : speed();
case 4 : volume();
case 5 : exit;
}
printf("The result is %f", result);
printf("End of Program");

}

float length()
{
int choice,val;
char str[10];
printf("Enter the metric you want to change");
gets(str);
printf("Enter the vlaue to be converted");
scanf("%d",&val);
printf("1.Convert to feet");
printf("2.convert to meters");
printf("3.Convert to inches");
printf("4.Convert to centimeteres");
printf("5.Convert to miles");
printf("6.Exit");
printf("Please enter your choice to convert the value");
scanf("%d",&choice);
switch(choice)
{
case 1 : if (strcmp(str,"feet"))
           return val;
       else if (strcmp(str,"meters"))
       return(val*3.2808);
       else if (strcmp(str,"inches"))
       return((val* 0.083333))
       else if (strcmp(str,"cetimeteres"))
       return(val*0.03);
       else if (strcmp(str,"miles"))
       return(val * 5280.0);
       else
       exit;
case 2 : if (strcmp(str,"feet"))
           return (val*3.28084);
       else if (strcmp(str,"meters"))
       return(val);
       else if (strcmp(str,"inches"))
       return(39.3701*val);
       else if (strcmp(str,"centimeteres"))
       return(val * 100);
       else if (strcmp(str,"miles"))
       return(val*0.000621371);
       else
       exit;
case 3 : if strcmp(str,"feet")
           return(val*0.0833333);
       else if (strcmp(str,"meters"))
       return(val*0.0254);
       else if(strcmp(str,"inches"))
       return val;
       else if((strcmp(str,"centimeteres"))
       return(val*2.54);
       else if((strcmp(str,"miles"))
       return(val*0.000000157);
       else
       exit;
case 4 : if(strcmp(str,"feet"))
return(val*0.0328084);
       else if(strcmp(str,"meters"))
       return(val*0.01);
       else if(strcmp(str,"inches"))
       return(val*0.393701);
       else if(strcmp(str,"centimeteres"))
       return val;
       else if(strcmp(str,"miles"));
       return(val*0.0000006213);
       else
       exit;
case 5 : if(strcmp(str,"feet"))
return(val*5280);
       else if(strcmp(str,"meters"))
       return(val*1609.34);
       else if(strcmp(str,"inches"))
       return (val*63360);
       else if(strcmp(str,"centimeteres"))
       return(val*160934);
       else if((strcmp(str,"miles"))
       retun val;
       else
       exit;

case 6 : exit;

}
}

float tempreature()
{
int choice,val;
char str[10];
printf("Enter the metric you want to change");
gets(str);
printf("Enter the vlaue to be converted");
scanf("%d",&val);
printf("1.Celsius");
printf("2.Farenheight");
printf("3.Kelvin");
printf("4.Rankine");
printf("5.Reaumur");
printf("Please enter your choice to convert the value");
scanf("%d",&choice);
switch(choice)
{
case 1: if(strcmp(str,"celsius"))
       return val;
       else if(strcmp(str,"Farenheight"))
       return(val*32);
       else if(strcmp(str,"kelvin"))
       return(val*274.15);
       else if(strcmp(str,"rankine"))
       return(val*493.47);
       else if(strcmp(str,"reaumur"))
       return(val*0.80000);
       else
       exit;
case 2 : if(strcmp(str,"celsius"))
       return(val*-17.2222);
       else if(strcmp(str,"Farenheight"))
       return value;
       else if(strcmp(str,"kelvin"))
       return(val*255.928);
       else if(strcmp(str,"rankine"))
       return(val*460.67);
       else if(strcmp(str,"reaumur"))
       return((val-32)*(4/9));
       else
       exit;
case 3 : if(strcmp(str,"celsius"))
           return(val*-272.15);
       else if(strcmp(str,"farenheight"))
       return(val*-457.87);
       else if(strcmp(str,"kelvin"))
       return val;
       else if(strcmp(str,"rankine"))
       return(val*1.8);
       else if(strcmp(str,"reaumur"))
       return((val - 273.15)* 0.80000);
       else
       exit;
case 4: if(strcmp(str,"celsius"))
       return(val*-272.594);
       else if(strcmp(str,"farenheight"))
       return(val*-458.67);
       else if(strcmp(str,"kelvin"))
       return(val*0.555556);
       else if(strcmp(str,"rankine"))
       return val;
       else if(strcmp(str,"reaumur"))
       return((val-491.67)*(4/9));
       else
       exit;
case 5: if(strcmp(str,"celsius"))
           return(val*1);
   else if(strcmp(str,"farenheight"))
       return(val*34);
       else if(strcmp(str,"kelvin"))
           return(val*274);
       else if(strcmp(str,"rankine"))
       return(val*494);
       else if(strcmp(str,"reaumur"))
       return value;
       else
       exit;
case : exit;

}
}

float speed()
{
int choice,val;
char str[10];
printf("Enter the metric you want to change");
gets(str);
printf("Enter the vlaue to be converted");
scanf("%d",&val);
printf("1.mph");
printf("2.kph");
printf("3.mps");
printf("4.Exit");
printf("Please enter your choice to convert the value");
scanf("%d",&choice);
switch(choice)
{
case 1: if(strcmp(str,"mph"))
       return val;
       else if(strcmp(str,"kph"))
       return(val*1.60934);
       else if(strcmp(str,"mps"))
       return(val*0.44704);
       else
       exit;
case 2: if(strcmp(str,"mph"))
           return(val*0.621371);
       else if(strcmp(str,"kph"))
       return val;
       else if(strcmp(str,"mps"))
       return(val*0.277778);
       else
       exit;
case 3 : if(strcmp(str,"mph"))
           return(val*2.23694);
   else if(strcmp(str,"kph"))
       return(val*3.6);
       else if(strcmp(str,"mps"))
       return val;
       else
       exit;
case 4 : exit;

}
}

float volume()
{
int choice,val;
char str[10];
printf("Enter the metric you want to change");
gets(str);
printf("Enter the vlaue to be converted");
scanf("%d",&val);
printf("1.ounce");
printf("2.litre");
printf("3.gram");
printf("4.kilogram");
printf("5.pound");
printf("Please enter your choice to convert the value");
scanf("%d",&choice);
switch(choice)
{
case 1 : if(strcmp(str,"ounce"))
           return val;
       else if(strcmp(str,"litre"))
           return(val*0.029574);
       else if(strcmp(str,"gram"))
       return(val*28.3495);
       else if(strcmp(str,"kilogram"))
       return(val*0.0283495);
       else if(strcmp(str,"pound"))
       return(val*0.0625);
       else
       exit;
case 2 : if(strcmp(str,"ounce"))
           return(val*33.8135);
       else if(strcmp(str,"litre"))
       return val;
       else if(strcmp(str,"gram"))
       return(val*1000);
       else if(strcmp(str,"kilogram"))
       return(val*1);
       else if(strcmp(str,"pound"))
       return(val*2.20);
         
       else
       exit;
case 3 : if(strcmp(str,"ounce"))
           return(val*0.035274);
       else if(strcmp(str,"litre"))
       return(val*0.001);
       else if(strcmp(str,"gram"))
return val;
       else if(strcmp(str,"kilogram"))
       return(val*0.001);
       else if(strcmp(str,"pound"))
       return(val*0.00220462);
       else
       exit;
case 4 : if(strcmp(str,"ounce"))
           return(val*35.274);
       else if(strcmp(str,"litre"))
       return(val*1);
       else if(strcmp(str,"gram"))
       return(val*1000);
       else if(strcmp(str,"kilogram"))
           return val;
       else if(strcmp(str,"pound"))
       return(val*2.20462);
       else
       exit;
case 5 : if(strcmp(str,"ounce"))
           return(val*16);
       else if(strcmp(str,"litre"))
       return(val*0.45);
         
   else if(strcmp(str,"gram"))
       return(val*453.592);
       else if(strcmp(str,"kilogram"))
       return(val*0.453592);
       else if(strcmp(str,"pound"))
       return val;
       else
       exit;
case 6: exit;
}
}
         
The comments have not been added to the program because of the time limit.ALthough the entire logic has been maintained in the program.   
         
          
         

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