Friday, 26th January 1996
The exercise consists of two parts. Marks will be divided equally between the two parts.
The two parts are independent (i.e. you do not have to complete the first in order to attempt the second, or vice versa). Therefore, it is recommended that you plan your allocation of time between the two parts carefully in advance, and stick to this allocation during the exam.
Consider the file CYLVOL0.C.
This is supposed to be a C program to calculate the volume
() of a cylinder, of radius
and length
, based on the following
equation:
It should request measurements of the relevant dimensions of the cylinder, to be input from the keyboard, calculate the volume, and display the result on the screen.
The program has various deficiencies. You are required to correct all deficiencies you can identify. For all changes that you make, the report should contain a clear statement of the change and a specific explanation of your rationale for the change. Of course, if you are making several similar or related changes, you may discuss these as a unit.
When you have reached the point where you think the program should work, then you should test it, and report on these tests. Carry out, and report on, further corrections if necessary.
Note carefully that you must not simply present a version of the program rewritten from scratch. You are required to identify the specific deficiencies in the program you have been given.
You are required to develop (code, test, debug) a C program to carry out the following calculation.
Consider a rectangular glass fish tank of length , breadth
, and
filled with water to a depth
, all in meters. Neglecting the
mass of the glass itself, the mass, in kg, will be given by the
following equation:
Suppose the tank is to be mounted on a platform which can
hold a maximum mass of 1.2 tonne. If this is exceeded, the platform will
collapse.
Develop a program which will read in the dimensions of the tank. It should then calculate and print out the mass. If this mass would exceed the maximum which the platform can support, the program should print out a suitable warning. However, if the mass does not exceed this maximum it should not print any extra message. The program should then exit.
Specifically, your program must do the following:
Hint: While attempting to compile this program you may find that the number of generated error messages is so large that the initial messages scroll off the top of the screen before you can read them. If this happens you can use the -r switch with the scc command to capture all messages in a file. Thus, the command:
scc -r myfile
would compile myfile.c, depositing all messages in a file called myfile.err. Alternatively, you can use the PFE facility for running a DOS command and capturing the output in a PFE window. This can be accessed from the Execute menu, or using the toolbar button with a small C: icon.
#include <safe-c> void start(void) { floating_point_type Radius, Length, Volume; put_string("\n\nWelcome to CYLVOL.\n\n"); put_string ( "This program calculates the volume of a cylinder," ) put_string("given the radius and length.\n\n"); put_string("Please enter the radius: "); get_string(string_number); radius = string_to_floating_point(string_number); put_string("Please enter the length: "); get_string{string_number}; length = string_to_floating_point_type(string_number); volume = 3.141e01 * radius * length; floating_point_to_string(string_number, volume); put_string("\n\nThe volume is: ); put_string(string_number); put_string("\n\nGoodbye from CYLVOL.\n\n"); }