Exam 1: Class Section D

Exam 1: Class Section D

Thursday, 25th 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.

Part 1: Analysis (50%)

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.

Part 2: Synthesis (50%)

You are required to develop (code, test, debug) a C program to carry out the following calculation.

If a voltage , in amperes, is applied to a resistor of resistance , in , the power dissipated , in watts, will be given by the equation:

Develop a program which will read a value for the resistance, and then print out a table showing the power dissipated for values of current from 0A to 1A inclusive, in steps of 100mA.

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.

File CYLVOL0.C

#include <safe-c.h>


void main(void)
{
  floating_type radius
  floating_type length
  floating_type volume
  string_type string_number

  {
    put_string("\n\nWelcome to CYCVOL.\n\n");
    put_string("This program calculates the radius of a cylinder,\n");
    put_string("given the volume and length.\n\n");
}
put_string("Please enter the radius: ") getstring(string_number);
string_to_floating_point(string_number);

{put_string("Please enter the length: ") getstring(string_number);
length = string_to_floating_point(string_number);
volume = pi * radius * length * 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");
}


McMullin@eeng.dcu.ie
Fri Mar 29 09:08:21 GMT 1996