Answered step by step
Verified Expert Solution
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: points Using the fourstep development method, write a universal temperature converter C 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 ifelse ifelse chain in your program and make use of these conversion formulas:
Fahrenheit times Celsius ; Kelvin Celsius
Display the results with decimal places of accuracy. Develop the program on MS Visual Studio, debug, and run with different test cases. SOLUTION: Step : 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 : Find a Solution Prompt user for three inputs and save them into variables deg, etter, and conv. The following pseudocode will be implemented using ifelse ifelse chain. If the temperature deg is specified in Kelvin letter the conversion to Fahrenheit conv is done by degdeg ; the conversion to Celsius is done by degdeg ; If the temperature is specified in celsius, the conversion to Fahrenheit is done by degtimes deg ; the conversion to Kelvin is done by degd e g If the temperature is specified in Fahrenheit, the conversion to Celsius is done by degdeg ; the conversion to Kelvin is done by
degdeg ;
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; 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 knConverting temperature deg degree letter to degree conv & end; cout k fixed k setprecision; If the temperature deg is specified in Kelvin letter if letter k II the conversion to fahrenheit conv is done by degdeg If the conversion to Celsius is done by degdeg; 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 Else if the temperature is specified in fahrenheit, II the conversion to Celsius is done by degtheta deg ; If the conversion to kelvin is done by degdeg; II If the temperature type is specified to be anything other than c or ff or k display an error message. cout "Converted temperature is ks deg degree ek conv ex end; return ;Step : Test and Debug the Program We need to test the program at least for the following cases. CASE : f to c Converted temperature is Press any key to continue CASE : k to f Converted temperature is Fress any key to continue CASE : c to f Converted temperature is Press any key to continue CASE : f to k Converted temperature is Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started