Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the same code in the question? PROGRAMMING PROBLEM: [ 4 + 1 5 + 4 * 4 points ] Using the four - step

Using the same code in the question? PROGRAMMING PROBLEM: [4+15+4*4 points ] Using the four-step development method, write a universal temperature converter C+1 program that accepts a temperature in Celsius, Fahrenheit, or Kelvin and converts to the desired unit. If the user enters a letter following the temperature number as f, the program is to treat the number entered as a temperature in degrees Fahrenheit, and so on for the other units of temperature. As specified by the user, convert the temperature number to the equivalent degrees Celsius, Fahrenheit, or Kelvin, and display a suitable message. If the letter is neither f nor c nor k, the program is to display a message that the data entered is incorrect and terminate. Use an if-else if-else chain in your program and make use of these conversion formulas:
[ Fahrenheit =(9/5)\times Celsius +32; Kelvin = Celsius +273.15]
Display the results with 2 decimal places of accuracy. Develop the program on MS Visual Studio, debug, and run with different test cases. SOLUTION: Step 1: Analyze the problem There are three user inputs: temperature, its type (Fahrenheit or Celsius or Kelvin), and conversion to Celsius or Fahrenheit or Kelvin. The temperature is a real number and as such needs to be defined as double deg; The type of the temperature needs to be entered as a character ' c ',' f ', or ' k ' by the user. Thus, it can be declared as char letter; The desired conversion to ' c ',' P, or ' k ' can be represented by char conv; The output will be the converted temperature to be displayed with its appropriate type. We will reuse the "temp" variable defined for input as the output variable.Step 2: Find a Solution Prompt user for three inputs and save them into variables deg, 1etter, and conv. The following pseudo-code will be implemented using if-else if-else chain. If the temperature (deg) is specified in Kelvin (letter), the conversion to Fahrenheit (conv) is done by deg=(9/5)^*(deg-273.15)+32 ; the conversion to Celsius is done by deg=deg-273.15 ; If the temperature is specified in celsius, the conversion to Fahrenheit is done by deg=(9/5)\times deg+32 ; the conversion to Kelvin is done by deg=d e g+273.15 If the temperature is specified in Fahrenheit, the conversion to Celsius is done by deg=(5/9)*(deg-32) ; the conversion to Kelvin is done by
deg=(5/9)4(deg-32)+27315 ;
If the temperature type is specified to be anything other than ' c ' or ' f ' or ' k ', display an error message. We will set the formatting of the display of converted temperature to have two digits of accuracy after the decimal point. cout k fixed < setprecision(2); So, we must include the using namespace std; int main(){ double deg; // temperature value in Fahrenheit or Celsius or Kelvin char letter, conv; // letter f for Fahrenheit, c for Celsius, k for Kelvin If Prompt user for three inputs and save them into variables deg, letter, and conv. /f You may perform input data validation for extra credit cout k<"'nConverting temperature "<< deg <<" degree "<< letter <<" to degree "<< conv &<"..."<< end1; cout k< fixed k< setprecision(2); 1/ If the temperature (deg) is specified in Kelvin (letter), if ( letter =' k '){ II the conversion to fahrenheit (conv) is done by deg=(9.8/5)^*(deg-273.15)+32 If the conversion to Celsius is done by deg=deg-273.15; } If otherwise, if the temperature is specified in Celsius, /J the conversion to Fahrirenheit is done by II the conversion to kelvin is done by 11 Else if the temperature is specified in fahrenheit, II the conversion to Celsius is done by deg=(5/9.\theta )^*(deg-32) ; If the conversion to kelvin is done by deg=(5/9.8)^*(deg-32)+273.15; II If the temperature type is specified to be anything other than " c ' or 'ff' or ' k ',11 display an error message. cout < "Converted temperature is " ks deg <<" degree " ek conv ex end1; return 0;Step 4: Test and Debug the Program We need to test the program at least for the following cases. CASE 1: 98.4 f to c Converted temperature is Press any key to continue ... CASE 2: 273.15 k to f Converted temperature is Fress any key to continue ... CASE 3: -40 c to f Converted temperature is Press any key to continue ... CASE 4:-459.67 f to k Converted temperature is Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions