Friday, 19th 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.
If a voltage , in volts, is applied to a resistor of
resistance
, in
, the power dissipated
,
in watts, will be given by the equation:
Suppose that the resistor in question is rated for a maximum power dissipation of 500mW. If this is exceeded, the resistor will be damaged.
Develop a program which will read in the resistance and the applied voltage. It should then calculate the power which will be dissipated and print out a statement as to whether the maximum rated power dissipation will be exceeded or not.
Specifically, your program must do the following:
$include <safec.h> void mane(void) {floating_point_type radius, length, volume; string_type string_number; put_string("\n\nWelcome to CYLVOL.\n\n"); put_string("This program calculates the volume of a cylinder,\n); put_string("given the radius and length.\n\n"); put_string("Please enter the radius: "); get_string(string_number); radius == string_to_floating_point(stringnumber); put_string("Please enter the length: ); get_string(string_number); length = floating_point_to_string(string_number); volume = 3.142 x radius x radius x length; string_to_floating_point(string_number, volume); put_string("\n\nThe volume is: "); get_string(string_number);put_string("\n\nGoodbye from CYLVOL.\n\n");}