Assignment 02

Voltage = I * R + (#animals / meters of fence) * K + 5000(only if a bull is present in the pen)

where I is the amperage of the power source, a constant in the device currently set at .05

R is the resistance: 20,000 for cows and 6,000 for sheep

K is a voltage stabilizing factor always known to be 98000

5000 volts is the minimum voltage needed (at .05 amps) to deter the average 2500 lb bull

Note: The voltage value reported by your program should always be rounded down to the nearest integer value. You are not allowed to use conditional statements (if or if-else) in the program. Think carefully how to use the information you have input from the user, how it is stored, how boolean variables are represented. It is up to you how you want to name your variables and constants. Don't think that you should copy names that your employer/teacher/mentor (see picture above) use to describe a problem. YOU are writing the code.

Your program should be "user friendly" in that it should have an opening statement or greeting, user friendly and understandable prompts, and clear and concise outputs and sign-off. Here's a good example of bad output:

enter stuff: 6000 6 1000 1

5888

Notice that there are NO prompts to speak of, and the output is completely unexplained. This is horrible output. Something like the following is much much better:

Welcome to the Volto-Matic Computa-tator®

Please enter:

resistance(20000 for cows or 6000 for sheep): 20000

how many critters in your pen: 7

length of fence (meters): 3000

bull?(1 for yes, 0 for no): 0

Voltage required: 1228v

When you submit: When you submit this, and all subsequent programs for this class, cssubmit will compile and run (assuming it compiles) your program during the submission process. Thus, when you submit, you will have to enter inputs as a user of the program. Now, in order to make the output uniform for the grader and to keep them sane, ALL OF YOU will enter the same information. For this assignment, it is:

  • resistance for cattle

  • 8 animals

  • 2500 meters of fencing

  • bull present

As always, if you have any questions about this assignment, be sure to ask your (lecture) instructor.

And don't forget to warn your cattle....

Specifications: Your program is to prompt the user for input of the anticipated resistance (an integer) with input of 20,000 for cows or 6,000 for sheep, the number of animals (an integer) in the enclosure, the meters of fence this charger will be electrifying, and whether or not a bull will be present in the pen. For this last input, your prompt should request a 0 (for no) and 1 (for yes), and the value be read into a boolean variable. These inputs are to be used in this formula:

Due: Friday, Feb. 5, 2016 at noon 100 pts

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Remember, to electronically submit a file to for this course, first change to the directory in which the file resides and then type in, at the UNIX prompt, the command:

cssubmit 1570 section_letter assignment_number

Be sure that only the file you want to submit is in that directory - make a directory for every assignment! Remember that the submit system will deliver every .cpp file in the current directory to me, so you should only have the file for hw 2 in that directory. Name your file a meaningful name and give it a .cpp extension since you will be compiling it. Also, make sure that you compile and run your program using the GNU (g++) compiler before submitting to make sure that it will work for the submit script.

Background: Agricultural Engineering, an age old employment opportunity (see picture to the right), has many new and challenging engineering problems to solve in our more 'modern' world. As an example, Cletus Spuckler owns property on which he runs cattle. He has had trouble convincing his cattle to remain within their domain, using your standard run-o-the-mill barbed-wire fencing as his first line of argument. Wanting a more secure enclosure, Cletus wishes to employ the magic of the electromotive force known as "electric shock therapy" to convince his herd that it is in their best interests to stay home. Being too cheap to buy a standard fence charger from the local farm store, he's going to build his own. But, of course, having only graduated from Thuh Furst Grade Yuniversity of Podunk, he has no prior knowledge of how electricity works and needs you to write a simple program to calculate how much "juice" to run through his electric fence. Don't worry, you don't need to understand electricity (Pphhhhfffft! who ever listens in physics class anyway?) either. The specs are contained in the discussion to follow.

Cletus is able to put the device together (we won't go there), but needs to know how to set the voltage output. As any good farmer knows, the voltage output of the charger (the force of the charge that runs in the wire) should be determined by several factors. Your program is to input that information from the user of the program, and then compute and output to the screen what the voltage setting needs to be.