This document is part of the HTML publication "An Introduction to the Imperative Part of C++"

The original version was produced by Rob Miller at Imperial College London, September 1996.

Version 1.1 (modified by David Clark at Imperial College London, September 1997)

Version 1.2 (modified by Bob White at Imperial College London, September 1998)

Version 1.3, 1.4, 2.0, ..., 2.21, 3.0 (modified by William Knottenbelt at Imperial College London, September 1999-September 2023)


Introduction to C++ Programming: Exercise Sheet 2

Question 1

To convert temperatures written in Fahrenheit to Celsius (Centigrade), you subtract 32, multiply by 5 and then divide by 9. To convert Celsius to Absolute Value (Kelvin), you add 273.15. Write a program that displays a temperature conversion chart on the screen as follows:

	   Fahrenheit     Celsius        Absolute Value
	
	   0              -17.78         255.37
	   20             -6.67          266.48
	   40             4.44           277.59
	   ...            ......         ......
	   ...            ......         ......
	   300            148.89         422.04

(EXAMPLE ANSWER) (BACK TO COURSE CONTENTS)

Question 2

Alter the program for question 1 so that it prompts the user for the lowest and highest Fahrenheit temperature wanted in the table, and also prompts the user for the desired step size between rows of the table (the step size is 20 in question 1). The program should begin by explaining to the user what it does, and should appropriately echo the user's input before printing the table.

(EXAMPLE ANSWER) (BACK TO COURSE CONTENTS)

Question 3

Write a program that reads in a character <char> from the keyboard, and then displays one of the following messages: (i) if <char> is a lower case letter, the message "The upper case character corresponding to <char> is ...", (ii) if <char> is an upper case letter, the message "The lower case character corresponding to <char> is ...", or (iii) if <char> is not a letter, the message "<char> is not a letter". You will need to refer to a table of ASCII characters.

(EXAMPLE ANSWER) (BACK TO COURSE CONTENTS)

Question 4

Write a program which will raise any number x to a positive power n using a "for loop". (Is there any way to improve the efficiency of your program?)

(EXAMPLE ANSWER) (BACK TO COURSE CONTENTS)