Assignment 05

Due: Tuesday, February 22, 2011, at noon, 100 points

For this assignment, you will submit a single C++ compilable file containing a program written in C++. By now you all know how to submit. Be sure that the file is in its own directory.

Background: The mayhem that Trogdor wreaks upon the countryside and its peasantry is unbearable. In particular, it is unbearable to the region's civil authority, the Sheriff of county Trogdor (named for a distant relative). You see, the Sheriff collects taxes from the peasants of the region and any loss of population is a loss of tax revenue. Anything that he can do to predict how Trogdor's burninations will decimate the peasantry will help him plan his finances. So, he wants to hire you to write a program that will do just that. In short, you will use the formula in hw #2 to compute burninations, then the number of peasants burned, then the tax revenue loss, and finally output that information for the Sheriff. You are to implement the details using functions, and these functions will be detailed below. The details of the computations will also be given.

Specifications: Your program is to have the following functions. [Note: I will refer to functions in italics and follow thier names by () to signify they are functions. This is not to imply that they necessarily have empty parameter lists.]

  • a greetings() function that outputs a friendly welcome to the user of the program.

  • a get_anger_level() function that will prompt the user for Trogdor's anger level and returns that value.

  • a get_arm_diameter() function that will prompt for and read in the diameter of Trogdor's beefy arm, and then returns that value.

  • a burninations() function that you will pass anger level and diameter to, and it will calculate and return the correct value.

  • a death_count() function that will be passed the number of burninations and will return the expected number of peasant deaths. This is to be calculated in the following way. Initially, a burnination has a 20% chance of killing a peasant. But whenever a peasant is killed by a burnination, the chance of succeeding burninations killing a peasant increases by 0.1%. This is a reflection of increased majesty of burninations with each succeeding peasant death. Trogdor is emboldened by burning peasants and then spits hotter fire! To demonstrate, here's an example of how Trogdor might burninate the countryside:

    • 20% chance of death burnination death 1st no 2nd no 3rd no 4th no 5th no 6th yes 20.1% chance now 7th no 8th yes 20.2% chance now 9th no 10th no 11th no 12th no 13th yes 20.3% chance now -------- etc ------

    • So how will you generate each of these decisions? Do this: get a random number from the random number generator by calling rand(). Mod it by 1000, and the resulting value will be in the interval [0, 999]. If the result is less than 200, then "kill off" a peasant. Otherwise, no death occured. (This models a 20% death rate.) Anytime a death occurs, you have to increase that threshold (initially 200) by 1. Now remember that the parameters can change; make your code versatile.

  • a revenue_loss() function that is sent the number of peasants killed and returns the expected loss of revenues. That value is calculated thusly:

    • lost rev = Num_deaths * TAX_RATE * AVE_INCOME TAX_RATE and AVE_INCOME are currently 15% and $455.

  • an output_stats() function that you will pass pertinent information to and it will output that info to the user in a friendly and easy to read format. Here's an example:

    • Trogdor is on the rampage! with beefy arm 16 in. in diameter and anger at 105 burninations is 855 predicting 56 deaths $4556 in lost revenues (These numbers are made up and are not to be construed as valid input/calculated numbers. They're only for demo purposes.)

  • a signoff() function.

As always, be sure to use good programming practices. [SUBLTE HINT: USE CONSTANTS!!!!!!!] .... where appropriate. Here's a resource that you need to start reading: coding standards. Much of it will be meaningful in future courses, but a lot of it is pertinent NOW.

When you submit: Enter the following information

  1. 1010.5 and 5.8 for anger level and diameter, respectively.

As always, if you have questions, don't hesitate to ask your instructor or Nathan (in the lab Mon and Wed nights).