Question - Systems and Computer Engineering

Download Report

Transcript Question - Systems and Computer Engineering

Exercise 2
The resistance of N resistors connected in parallel is given by the following
formula:
1
R=
(1 / R1) + (1/R2) + (1/R3) + (1/R4) …. + (1/RN)
where R is the total resistance, and RI is the resistance of the ith resistor.
You are to write a program that reads in lists of resistor values and outputs the
resistance of the corresponding parallel connections. It is suggested that you
approach this problem in three steps.
Start with a program that reads in resistor values until a negative value is entered
and then outputs the resistance of the connection. If no resistor values are
entered (i.e. a negative value is entered immediately), your program should
output a message saying that the resistance is infinite. Note that this program
will not work properly if zero is entered as a resistance value.
Once you’re happy with the first step, modify your program so that it stops
reading values upon seeing either a negative value or zero. In the second case,
your program should not perform any calculations, but should instead out a
message to the effect that there is no point in entering any further resistance
values as the total resistance must be zero.
Finally, have you program ask the user, after each list has been processed,
whether or not they want to enter another list Inputs greater than zero should be
taken as meaning “yes”, and all other inputs as meaning “no”. This is a great
opportunity for the “do while” crowd.
Note: Students who want to have their programs accept “Y” or “N”, or perhaps
“yes” and “no”, are of course welcome to try this
ECOR 1606 Copyright © 2002, Department of Systems and Computer Engineering, Carleton University
1