This week's lab will consist of you writing some C++ code and turning it in to Web-CAT to ensure that it is correct. So the purpose is to write some basic code, and then use the automated grading system to have it scored. Additionally, we will be using a basic selection statement to check for input errors.
This being the first part will have you solve the following problem from Electrical engineering. We will be calculating the combined resistors connected in parallel.
To compute this, we will use the following formula:
where R1, R2 and R3 are the values for the 3 resistors.
You can see from this formula that the value for the resistors cannot be 0. You need to check for this. If any of the resistors has a value of 0, please write a message indicating this error and stop your program.
Using this formula, write a C++ program to request, calculate and display the combined resistance for the three resistors R1, R2 and R3 are connected in parallel.
The output from this formula will simply be the answer as a double.
Your job is going to be to read in a series of triples of doubles each set of doubles on a single line. You can use extraction (>>) to read each double into a variable. You will have an unknown amount of sets of triples. So you will want to use the loops we discussed this week in class, prime, test, process and re-prime. Each loop should read in three doubles compute the value of the resistance and then output that value.
In order to get this to work, you need to put your functions in a file called:
resistors.h
and you must write a function with the following signature:
void computeResistance( istream& in, ostream& out );
You may write any other function you want, but I will call the above function. The istream in will contain series of lines of three doubles separated by spaces and each line will end in a newline character. The output should be the results of the computations for each line. Each result should be on a line by itself. If any of the input lines contain a 0, then you should produce --error-- for that output line.
When you are done, zip up your resistors.h and any implementation files and turn them in for lab 3. Attached below is a main function you could use. I will also attach some input files you could use for testing. You are welcome to write your own main and your own input files.
Zip up your resistors.h and resistors.cpp and turn them in to Web-CAT. Look for Lab 3. It is due for everyone by Tuesday Feb 18 by 11:55 PM.