Question

In: Computer Science

Problem: Design and write a C language program that can be used as a unit converter...

Problem:

Design and write a C language program that can be used as a unit converter application. Your unit converter should contain at least four unit categories, for example: length, mass, temperature, and time. The program should display the main menu that contains unit categories that are available, and the user will be prompted to select a unit category first. After the unit category has been selected the program should then display another menu (i.e., a submenu) that contains at least three units or more for the chosen unit category. For example, if the mass unit category is selected, the units shown in its submenu could be: kilogram, pound, and ounce. The user will be prompted next to enter a value (i.e., a floating point number) to be converted, as well as the two units from the submenu. The first unit is the unit to be converted, while the second unit is the unit to which the first unit will be converted. After these two units are selected, the program will compute and display the result of the conversion. The program will then prompt the user to return to the main menu and repeat the same process, or terminate the program. Program requirements: It is required to use the following C language constructs: · User-Defined Functions . switch/case · Loops · Decisions

Solutions

Expert Solution

Please upvote ,comment for any query i will update , Thanks .

Note : check attached image for output and program Code compiled and tested in Code blocks C IDE.

Program :

/*
length have three unit convrsion meter ,centimeter ,milimeter
mass have three unit kilogram ,ounce ,pound
temperature have three unit fahrenheit ,celsius ,kelvin
time also have three unit conversion seconds, minutes ,hours
*/

#include<stdio.h>
#include<conio.h>


float tempConversion()
{
float value;
int first,second;
printf("Enter value to convert:"); //prompt user for float value to convert
scanf("%f",&value);
printf("1. value is fahrenheit\n"); //prompt user to choice unit of value entered by him
printf("2. value is celsius\n");
printf("3. value is kelvin\n");
printf("Enter choice:");
scanf("%d",&first);

switch(first)
{
case 1:
printf("1. to convert in celsius\n"); //prompt to convert in
printf("2. to convert in kelvin\n");
break;
case 2:
printf("1. to convert in fahrenheit\n");
printf("2. to convert in kelvin\n");
break;
case 3:
printf("1. to convert in fahrenheit\n");
printf("2. to convert in celsius\n");
break;
default:
break;
}
printf("Enter choice:"); //choice of unit to convert in
scanf("%d",&second);

if(first==1 && second==1) //value is fahrenheit and convert in celsius
{
float celsius= (0.55555555555555555555555555555556 *(value - 32));
printf("fahrenheit value %.2f in celsius is:%.2f\n",value,celsius);printf("\n");
}
else if(first==1 && second==2) //value is fahrenheit and convert in kelvin
{
float kelvin =(0.55555555555555555555555555555556 *(value- 32) + 273);
printf("fahrenheit value %.2f in kelvin is:%.2f\n",value,kelvin);printf("\n");
}
else if(first==2 && second==1) //value is celsius and convert in fahrenheit
{
float fah= 1.8*value + 32;
printf("celsius value %.2f in fahrenheit is:%.2f\n",value,fah);printf("\n");
}
else if(first==2 && second==2) //value is celsius convert in kelvin
{
float kelvin = value+ 273;
printf("celsius value %.2f in kelvin is:%.2f",value,kelvin);printf("\n");
}
else if(first==3 && second==1) //kevin to fah
{
float fah= (1.8* (value - 273) + 32);
printf("kelvin value %.2f in fahrenheit is:%.2f",value,fah);printf("\n");

}
else if(first==3 && second==2) //kelvin to celsius
{
float celsius= value - 273;
printf("kelvin value %.2f in celsius is:%.2f",value,celsius);printf("\n");
}

}

float lengthConversion()
{
float value;
int first,second;
printf("Enter value to convert:");
scanf("%f",&value);
printf("1. value is meter\n");
printf("2. value is centimeter\n");
printf("3. value is milimeter\n");
printf("Enter choice:");
scanf("%d",&first);

switch(first)
{
case 1:
printf("1. to convert in centimeter\n");
printf("2. to convert in milimeter\n");
break;
case 2:
printf("1. to convert in meter\n");
printf("2. to convert in milimeter\n");
break;
case 3:
printf("1. to convert in meter\n");
printf("2. to convert in centimeter\n");
break;
default:
break;
}
printf("Enter choice:");
scanf("%d",&second);

if(first==1 && second==1)
{
printf("meter value %.2f in centimeter is:%.2f",value,value*100);printf("\n");
}
else if(first==1 && second==2)
{
printf("meter value %.2f in milimeter is:%.2f",value,value*1000);printf("\n");
}
else if(first==2 && second==1)
{
printf("meter value %.2f in milimeter is:%.2f",value,value/100.0);printf("\n");
}
else if(first==2 && second==2)
{
printf("meter value %.2f in milimeter is:%.2f",value,value*10);printf("\n");
}
else if(first==3 && second==1)
{
printf("meter value %.2f in milimeter is:%.2f",value,value/1000.0);printf("\n");
}
else if(first==3 && second==2)
{
printf("meter value %.2f in milimeter is:%.2f",value,value/10.0);printf("\n");
}

}

float massConversion()
{
float value;
int first,second;
printf("Enter value to convert:");
scanf("%f",&value);
printf("1. value is kilogram\n");
printf("2. value is ounce\n");
printf("3. value is pound\n");
printf("Enter choice:");
scanf("%d",&first);

switch(first)
{
case 1:
printf("1. to convert in ounce\n");
printf("2. to convert in pound\n");
break;
case 2:
printf("1. to convert in kilogram\n");
printf("2. to convert in pound\n");
break;
case 3:
printf("1. to convert in kilogram\n");
printf("2. to convert in ounce\n");
break;
default:
break;
}
printf("Enter choice:");
scanf("%d",&second);

if(first==1 && second==1)
{
float ounce=value*35.274;
printf("kilogram value %.2f in ounce is:%.2f",value,ounce);printf("\n");
}
else if(first==1 && second==2)
{
float pound=value*2.205;
printf("kilogram value %.2f in pound is:%.2f",value,pound);printf("\n");
}
else if(first==2 && second==1)
{
float kg=value/35.274;
printf("ounce value %.2f in kilogram is:%.2f",value,kg);printf("\n");
}
else if(first==2 && second==2)
{
float pd=value/16;
printf("ounce value %.2f in pound is:%.2f",value,pd);printf("\n");
}
else if(first==3 && second==1)
{
float kg=value/2.205;
printf("pound value %.2f in kilogram is:%.2f",value,kg);printf("\n");

}
else if(first==3 && second==2)
{
float ounce=value*16;
printf("pound value %.2f in ounce is:%.2f",value,ounce);printf("\n");
}

}

float timeConversion()
{
float value;
int first,second;
printf("Enter value to convert:");
scanf("%f",&value);
printf("1. value is seconds\n");
printf("2. value is minutes\n");
printf("3. value is hours\n");
printf("Enter choice:");
scanf("%d",&first);

switch(first)
{
case 1:
printf("1. to convert in minutes\n");
printf("2. to convert in hours\n");
break;
case 2:
printf("1. to convert in seconds\n");
printf("2. to convert in hours\n");
break;
case 3:
printf("1. to convert in seconds\n");
printf("2. to convert in minutes\n");
break;
default:
break;
}
printf("Enter choice:");
scanf("%d",&second);

if(first==1 && second==1)
{
printf("seconds value %.2f in minutes is:%.2f",value,value/60.0);printf("\n");
}
else if(first==1 && second==2)
{
printf("seconds value %.2f in hours is:%.2f",value,value/3600.0);printf("\n");
}
else if(first==2 && second==1)
{
printf("minutes value %.2f in seconds is:%.2f",value,value*60);printf("\n");
}
else if(first==2 && second==2)
{
printf("minutes value %.2f in hours is:%.2f",value,value/60.0);printf("\n");
}
else if(first==3 && second==1)
{
printf("hours value %.2f in seconds is:%.2f",value,value*60*60);
printf("\n"); //choice for length
}
else if(first==3 && second==2)
{
printf("hours value %.2f in minutes is:%.2f",value,value*60);
printf("\n");
}

}
int main()
{
int exitFlag=0;
while(1)
{
int choice;


printf("1. length conversion\n");
printf("2. mass conversion\n");
printf("3. temperature conversion\n");
printf("4. time conversion\n");
printf("5. Exit\n");
printf("Enter choice:");
scanf("%d",&choice);

if(choice==1) //choice for length
{
int newChoice;
lengthConversion(); //convert and display the unit
while(1)
{
printf("1. return to main menu\n"); //again prompt user for choice
printf("2. repeat same process\n");
printf("3. terminate program\n");
scanf("%d",&newChoice);

if(newChoice==1)
{
break; //return to main menu
}
else if(newChoice==2)
{
lengthConversion(); //again convert values
}
else
{
exitFlag=1; //terminate the program
break;

}

}


}
else if(choice==2) //choice for mass
{

int newChoice;
massConversion();
while(1)
{
printf("1. return to main menu\n");
printf("2. repeat same process\n");
printf("3. terminate program\n");
scanf("%d",&newChoice);

if(newChoice==1)
{
break;
}
else if(newChoice==2)
{
massConversion();
}
else
{
exitFlag=1;
break;

}

}

}
else if(choice==3) //temperature choice
{
int newChoice;
tempConversion();
while(1)
{
printf("1. return to main menu\n");
printf("2. repeat same process\n");
printf("3. terminate program\n");
scanf("%d",&newChoice);

if(newChoice==1)
{
break;
}
else if(newChoice==2)
{
tempConversion();
}
else
{
exitFlag=1;
break;

}

}


}
else if(choice==4) //time conversion
{
int newChoice;
timeConversion();
while(1)
{
printf("1. return to main menu\n");
printf("2. repeat same process\n");
printf("3. terminate program\n");
scanf("%d",&newChoice);

if(newChoice==1)
{
break;
}
else if(newChoice==2)
{
timeConversion();
}
else
{
exitFlag=1;
break;

}

}

}
else if(choice==5)
{
printf("bye ,see you again later!\n"); //terminate program for main menu
break;
}
else
{
printf("Invalid choice\n"); //prompt user for invalid choice
}

if(exitFlag) //when exit flag is one terminate the program from sub menu
{
printf("good bye ,See you again later!\n");
exitFlag=0;
break;
}

}


}

Output :


Related Solutions

write c++ program. 1. Time converter 2. Length Converter 3. weight Converter 4.Currency Converter 5. Temprature...
write c++ program. 1. Time converter 2. Length Converter 3. weight Converter 4.Currency Converter 5. Temprature Converter (C to F and F to C) time converter (minutes to second, second to minutes, hours to seconds, seconds to hours, minutes to hours, hours to minutes)
C++ Language Problem 2 (Save and Get Info) : Write a program that asks for the...
C++ Language Problem 2 (Save and Get Info) : Write a program that asks for the user's name, phone number, and address. The program then saves all information in a data file (each information in one line) named list.txt. Finally, the program reads the information from the file and displays it on the screen  in the following format: Name: User's Name   Phone Number: User's Phone Number   Address: User's Street Address User's City, State, and Zip Code
Write an assembly language program which will capture 250 data samples from the ADC0804 converter and...
Write an assembly language program which will capture 250 data samples from the ADC0804 converter and store this data in external RAM starting at 2000H. Identify your selected port pins to the converter. The program must be an interrupt driven
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop For example: Fib(1) = 1, Fib(2) = 2, Fib(3) = Fib(1) + Fib(2) = 3, Fib(4) = Fib(2) + Fib(3)...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking...
Please answer with code for C language Problem: Counting Numbers Write a program that keeps taking integers until the user enters -100. In the end, the program should display the count of positive, negative (excluding that -100) and zeros entered. Sample Input/Output 1: Input the number: 0 2 3 -9 -6 -4 -100 Number of positive numbers: 2 Number of Negative numbers: 3 Number of Zero: 1
(Use the string class to solve the problem) Write a program (in c++) that can be...
(Use the string class to solve the problem) Write a program (in c++) that can be used to train the user to use less sexist language by suggesting alternative versions of sentences given by the user. The program will ask for a sentence, read the sentence into a string variable, and replace all occurrences of masculine pronouns with gender-neutral pronouns. For example, it will replace “he” with “she or he”, and “him” with “her or him”. Be sure to preserve...
C++ Write a program that can be used to calculate the federal tax. The tax is...
C++ Write a program that can be used to calculate the federal tax. The tax is calculated as follows: for single people, the standard exemption is $4,000; for married people, the standard exemption is $7,000. A person can also put up to 6% of his or her gross income in a pension plan. the tax rates are as follows: if the taxable income is: Between $0 and $15,000, the tax rate is 15%. Between $15,001 and 40,000 the tax rate...
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
Write a program to create a tree randomly. You can use C++ programming language. The input...
Write a program to create a tree randomly. You can use C++ programming language. The input is the number of vertices in the tree, and the output is an adjacent list of the tree. (Managed to complete this assignment with a binary tree. But, was told I needed a general tree instead)
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT