Each solution explains what is happening and why something is being done in the comments.
4.1) Write a program to calculate and display the area of a rectangle. You should use variables to store the width, height and area, but you should set the values of the width and height variables in your code rather then some other way (such as reading them from the user). (Solution)
4.2) Extend the program you wrote for exercise 4.1 to calculate the area of the walls in a room. Use another variable length together with the previous ones. (Solution)
4.3) Modify the program you wrote in exercise 4.2 to calculate the number of tins of paint required to paint a room. (Hint: you should have another variable which stores the area that one tin of paint can cover.) (Solution)
4.4) Write a program to calculate the average of five students exam marks (each mark out of 100). Use one variable for each mark and one for the average. Print out each mark and the average. (Solution)
4.5) Write a program to print out a set of details for a member of a club. You should use separate variables to store the persons forename and surname, house number, street name, city and membership number. The house number and membership number should be stored in long variables. The format of the display should be:
<forename> <surname> : <membership number> <house number> <street name> <city>(Solution)
| Previous topic | Chapter contents | Next topic |
|---|---|---|
| Summary | User Guide contents | None |