Exam: Repeat Students Only.

Exam: Repeat Students Only.

The examination consists of two separate exercises. Marks will be divided equally between the two exercises.

The two exercises are related, but can be attempted independently (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 exercises carefully in advance, and stick to this allocation during the exam.

Exercise 1: Analysis (50%)

The program SERIES.C is supposed to calculate the equivalent resistance of a set of separate resistors , , etc. connected in series, according to the following equation:

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.

Exercise 2: Synthesis (50%)

Develop a program to calculate the equivalent resistance of a set of separate resistors , , etc. connected in parallel, according to the following equation:

The program should initially prompt for the number of resistors; it should then prompt for the individual resistor values; it should then calculate and print out the equivalent parallel resistance. The program should repeatedly prompt for additional sets of resistors, calculating and displaying equivalent resistance for each set. This should continue until the value zero is entered as the number of resistors. The program should then terminate.

The following guidelines must be followed:

  1. The program must be appropriately divided into functions.

  2. No global variables - all variables must be local to some function. Use parameter passing and/or return values where appropriate to exchange information between functions.

  3. The program should demonstrate good coding practices with regard to spacing, indentation, comments etc.

Test this program rigorously. Record all test results.

File SERIES.C

/*********************

  series.c: A program to compute the equivalent
    resistance of a set of separate resistors connected
    in series.

  Barry McMullin.
  4th April 1996.

/*********************

#include <stdio.h>


void main(void)
{double resistors[20]; double equiv; int index;

  fprint("Welcome to SERIES.C!");

  fprint("Please enter the number of resistors: ");
  scanf("%i", how_many);

  for(index = 0; index < how_many; index++)
    fprint("Please enter resistor number %i in ohm: ", index+1);
    scanf("%lf", &resistors[index]);

fprint("Computing equivalent resistance...");
  equiv = 0.0;
    for(index = 0;
  index < how_many;
  index++)
  equiv += resistors[index];

  fprint("The equivalent resistance is: %f ohm", equiv);
  fprint("Goodbye from SERIES.C!");}


McMullin@eeng.dcu.ie
Tue Apr 9 14:32:10 GMT 1996