Implementation of a Unit Conversion Program in C with Flowchart

Verified

Added on  2022/09/29

|5
|762
|14
Homework Assignment
AI Summary
This assignment presents a C programming solution for a unit conversion program. The program allows users to convert between units of length, mass, temperature, and time. The solution includes the C source code, a flowchart illustrating the program's logic, and pseudocode outlining the steps involved. The program utilizes functions for each type of conversion, making it modular and easy to understand. The user interface prompts the user to select the type of conversion, input the units and value, and then displays the converted result. The code handles various unit combinations and provides accurate conversions. This comprehensive solution helps students grasp programming concepts and apply them to solve practical problems.
Document Page
Flow chart:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Pseudo code:
int v;
char unit1, unit2, boolVal;
float val, resultFinal;
resultFinal = 0;
Initialize variables
unit1, unit2, boolVal as char
val and resultFinal as float
do loop
print Please select the conversion to be performed from below options:
print 1 Length 2 : Mass 3 : Temperature 4 : Time
Input v
Case based on v
case 1:
print "You selected option Length"
print select units (unit1 and unit2) to get converted, only first letter
print enter unit1
input unit1
print enter unit2
input unit 2
print enter value to be converted
input val
resultFinal = conversionLength(unit1, unit2, val)
print "Your conversion result is "
printf val, unit1, resultFinal, unit2
case 2:
print "You selected option Mass"
print select units (unit1 and unit2) to get converted, only first letter
print enter unit1
input unit1
print enter unit2
input unit 2
print enter value to be converted
input val
resultFinal = conversionMass(unit1, unit2, val)
print "Your conversion result is "
printf val, unit1, resultFinal, unit2
Document Page
case 3:
print "You selected option Temperature"
print select units (unit1 and unit2) to get converted, only first letter
print enter unit1
input unit1
print enter unit2
input unit 2
print enter value to be converted
input val
resultFinal = conversionTemp(unit1, unit2, val)
print "Your conversion result is "
printf val, unit1, resultFinal, unit2
case 4:
print "You selected option Time"
print select units (unit1 and unit2) to get converted, only first letter
print enter unit1
input unit1
print enter unit2
input unit 2
print enter value to be converted
input val
resultFinal = conversionTime(unit1, unit2, val)
print "Your conversion result is "
printf val, unit1, resultFinal, unit2
print "Do you want to continue Y/N"
end loop check boolval=y or Y
function conversionLength(unit1, unit2, val)
{
result = 0
if (unit1 == 'M')
if (unit2 == 'C')
result = 100 * val
else
result = 3.28 * val
else if (unit1 = 'C')
if (unit2 == 'M')
result = val / 100;
else
result = 0.0328084 * val
else if (unit1 == 'F')
if (unit2 == 'M')
result = 0.3048 * val
else
result = 30.48 * val
Document Page
return result
}
function conversionMass( unit1, unit2, val)
{
if (unit1 == 'K')
if (unit2 == 'P')
result = 2.20462 * val
else
result = 35.274 * val
else if (unit1 = 'P')
if (unit2 == 'K')
result = 0.45 * val
else
result = 16 * val
else if (unit1 == 'O')
if (unit2 == 'K')
result = 0.02 * val
else
result = 0.06 * val
return result
}
Function conversionTemp( unit1, unit2, val)
{
if (unit1 == 'C')
if (unit2 == 'F')
result = (val * 9 / 5) + 32
else
result = val + 273.15;
else if (unit1 == 'F')
if (unit2 == 'C')
result = (val - 32) * 5 / 9
else
result = val;
else if (unit1 == 'K')
if (unit2 == 'C')
result = val - 273.15
else
result = (val - 273.15) * 9 / 5 + 32
return result
}
function conversionTime( unit1, unit2, val)
{
if (unit1 == 'S')
if (unit2 == 'M')
result = val / 60
else
result = val / 3600
else if (unit1 == 'M')
if (unit2 == 'S')
result = val * 60
else
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
result = val / 60
else if (unit1 == 'H')
if (unit2 == 'M')
result = val * 60
else
result = val * 3600
return result
}
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]