(E) Temperatures

Goal: I will learn about the data types and arithmetic operators of C++.

Instructions: This exercise requires you to retrieve the template code from directory templates/02/temperature (copy it onto directory student/02/temperature) and open the project in Qt Creator (in the same way as on the first round).

Additional instruction

In this exercise, you can decide by yourself how many commits you will do. However, it is recommendable to do more than one of them.

Assignment

Implement into the given code template a program that prints the given temperature measurement both as Celsius and Fahrenheit degrees.

Conversions between the scales go as follows. A measurement in Celsius is converted to Fahrenheit by first multiplying the measurement with 1.8 and then adding 32 to the resulting product. The opposite conversion uses opposite calculations. A measurement in Fahrenheit is first subtracted by 32 and then the resulting difference is divided with 1,8.

The program first asks a temperature and then prints as shown in the following examples:

Enter a temperature: 0
0 degrees Celsius is 32 degrees Fahrenheit
0 degrees Fahrenheit is -17.7778 degrees Celsius
Enter a temperature: 100
100 degrees Celsius is 212 degrees Fahrenheit
100 degrees Fahrenheit is 37.7778 degrees Celsius
Enter a temperature: 212
212 degrees Celsius is 413.6 degrees Fahrenheit
212 degrees Fahrenheit is 100 degrees Celsius

You need not adjust the number of the desimals to be printed, i.e. it is enough to use the default print of floating point numbers as above.

Tips for completing the assignment:

  • The program prints two lines. Implement each print in a commit of its own.

A+ presents the exercise submission form here.