EEE1008 2012/13: Project 4. Equivalent Resistance Calculations
Consider the electrical circuit shown in the figure below:
Such circuits are often called Ladder Networks.
This circuit contains 2n resistors connected in a ``series-parallel''
way. Every resistor whose number is odd (i.e., 1,3, ..., 2n-1)
is connected in series with the group of resistors whose numbers are
greater than its number. Those resistors whose numbers are even
(i.e., 2,4, ..., 2n) are connected in parallel with the group
of resistors whose numbers are greater. For example, R(1) is in series
with the group between points (a) and (b), that is consisting of
R(2),R(3), ..., R(2n). On the other hand, R(2) is in parallel with the
group of resistors between points (a) and (c), that
is R(3),R(4), ..., R(2n). Only the last two resistors, R(2n-1)
and R(2n) are connected in series.
Design, implement and document a program that should perform the following:
- (Part 1) The program should calculate the overall
equivalent resistance of the circuit connected to a voltage
source V for a given set of values:
- The Voltage,
- Number of Resistors, and
- Individual Resistances (say, in Ohms) of Resistors
R(1),R(2), ...,R(2n).
The program should request these values from the user, input them,
validate them, and store the resistance values in an appropriate array
before performing the calculations. There should be no more than
100 input values.
All input should be read as a series of characters, and your program
should check that the entered characters are digits, and reject any input
that contains non-digits. You should write a function that performs this
task. The function should return -1 upon illegal input, and the value of
the input otherwise. You should, of course, use the Code Conversion
algorithm for this, as discussed during the lectures.
See below for more details about the input.
Hint. Make use of the formulas for series and parallel
interconnection of two resistors r(1) and r(2):
Rseries = r(1) + r(2); Rparallel = (r(1) r(2)/(r(1)+r(2).
- (Part 2) In addition to the calculations
performed for Part 1, the program should calculate the voltage
that falls across
and the current that flows through each resistor R(i)
(called V(i) and I(i), respectively),
assuming that the value of the source voltage V is entered.
The program could read the parameters of the circuit from an
input data file (for the sake of convenience) where the data is
formatted as discussed above:
24
6
100
200
100
200
100
100
i.e. the first line of the file contains the source voltage (24 in this
example) in Volts, the second line the number of resistors in the circuit
(6), and subsequent lines contain the individual resistances (in Ohms),
one value per line.
An example data file can be downloaded
here (this has an equivalent resistance of 2000 ohms).
The results should be output by the program as a list of triplets
(resistance R(i) in Ohms, voltage V(i) in Volts and current I(i) in
Amps), formatted as follows (these are the correct results for the
values listed above, you can use them for debugging your code):
100 12.00 0.12
200 12.00 0.06
100 6.00 0.06
200 6.00 0.03
100 3.00 0.03
100 3.00 0.03
i.e. one triplet per line, with the values separated by at least one space.
Note:
To read input from a file (instead of from the keyboard) enter the data
into a file (called, say, data.txt), and then enter the command
./a.exe < data.txt
(assuming your compiled program is called a.exe). This is called
I/O redirection, and saves you from typing all the input every time you
run the program. You can then use scanf in the normal manner.
Submission:
You should submit a single pdf file on Blackboard.
Your submission should have the following structure:
Objective. What is the program meant to achieve?
Pseudocode description of parts 1 and 2
Testing results: what values and choices did you use to test the
program, and whether the results were correct
Conclusion: did the program work? If not, why? How could it be
improved?
The program listing, including comments. Code will be marked
according to whether you have done extensive validation, whether
functions, arrays and variables have been used properly,
and whether the program layout is appropriate.
Example outputs, corresponding to your testing strategy