Assignment 09

Due: Wednesday, November 15, 2017, at noon 100 points

For this assignment, you will submit multiple files containing a program written in C++.

Be sure that only the file(s) you want to submit are in that directory - make a directory for every assignment! The submit system runs just the same with multiple files. The submit system will deliver every .cpp and every .h file and every.dat file in the current directory to me. Name your files meaningful names and give them proper extensions.

Foreground: This assignment is going to be a little different from previous assignments. It will work in conjunction with hw #10 in the future. You are laying the groundwork for a bigger program here. Furthermore, this is all about penguins, something I'm sure you know nothing about. So, you're going to learn some very valuable lessons about farming, animal husbandry, the dangers of trying to breed a better penguin, the horror of successful flightless-bird-eugenics, and the potential for a new world order!! This is scary stuff! But, it's better to be at the forefront of progress than to be left behind in the dustbin of history.

Background: It's a dangerous world out there. And Hans knows it. He has decided to make a life change; he's going to start a penguin farm....breed penguins....sell them to the U.S. government...make money, get famous, maybe run for president. But before he invests all that money and divests himself of his fame as a cartoon character on the Simpsons, he's wanting a computer program that will simulate his future in penguin farming. That's where you come in. You're ultimately going to create a robust C++ program that will answer all his questions about penguin farming outcomes. Yes, you will supply the answers. In this assignment, you are going to create a few of the classes that will be used in the final programming project, assignment #10.

Thus, below, you will find a description of classes you will create for this assignment as a precursor to assignment 10. You will also write a "driver" that will test your classes for the desired functionality. The driver is described below.

The penguin class:

member variables:

  • a name

  • a weight, keeping 1 decimal point accuracy

  • an age (in days)

  • an amount for the penguin's last bowel movement

member functions:

  • a default constructor that will initialize the penguin's name to a name chosen at random from a file of names, weight of 5 lbs, age of 0.

  • another constructor that will take values for the penguin's name, weight (positive value), and age (positive value less than 1000).

  • an eat() function that returns a bool and is passed an amount of food represented by a floating point number. The call to this function will result in two outcomes. First, the penguin's weight will increase according to the function below. Second, the penguin's poop() function will be called; the amount of food passed to the eat() function is passed to this function.

      • wt = wt + 70000 log (1 + (2% of food) * epsilon / ( 165 + age/5 )), where epsilon is a random floating point value in the interval [-0.05, .10] and age no greater than 1460 (days)

  • the poop() function will ONLY be called from the eat() function. It's parameter is the amount of food that was passed to the eat() function, a float. This function returns a floating point value representing .... well, you know ... determined by the following formula:

    • amnt of ... you know = 0.005 * body weight + 98% of weight of food eaten NOTE: the .005*body weight is actually lost from the animal's weight!

  • an accessor to return the amount of the penguin's last movement

  • an overloaded insertion operator to output the object in a single line: e.g. Jerry weighs xx lbs and is yy days old

The penguin_farmer class:

member variables:

  • a name

  • an amount of food for feeding penguins; a float

  • a variable to represent money on hand; a float

member functions:

  • a constructor that will take arguments for each of the member variables

  • a feed() function that has one parameter, a penguin (to feed). This function returns a bool. This function will generate a random amount of food between and including 2.0 and 3.0 lbs., and pass this to the penguin's eat() function, which is called by the penguin passed to the eat(). Of course, the amount of food is subtracted from the farmer's available food value. If the farmer object doesn't have the amount of food so generated, then the remaining food is fed to the penguin. If the farmer object has NO food left when called upon to feed, then this function the penguin's eat() function returns false; returning true if a positive amount of food was fed. This returned value is also the return value of the feed() function. Also, in this function a tally of "fertilizer production" can be done to update the farmer's cash.

  • a yell() function that has a boolean parameter, and returns nothing. This function is to be passed the return value of the feed() function. If it is passed true, yell() does nothing. If it is passed false, then yell() outputs: "OUCH!! you dirty bird!"....or something like that. This demonstrates what happens when it's time to feed a penguin and you feed it nothing! The penguin will bite you!!

  • an overloaded insertion operator to output the object in a single line: e.g. Frank has xxx lbs of food and $yyy.yy.

Create a file of nice penguin names. You will only need maybe 10 names. Only names can be in the file; nothing else!

As for the driver: Your main function is to test your classes. So, begin by creating a penguin, testing your non-default constructor: pass "Jerry", 7, 23 to. Output it to see if it worked. Create a default penguin and output it. Create a penguin_farmer (specifically, name him Hans and give him no money and 4575 lbs of penguin food) and output it. Now, create an array of 5 (default) penguins. Put them in a loop of 365 iterations in which you will have the farmer (presumably named "Hans") feed each penguin each day (one iteration of the loop). Keep track of the total amount of .... well, you know .... stuff that the penguins produce. At the end of this simulation of farming 5 penguins for a year, output each penguin, output the total ... well, you know, output the amount of money the farmer has made (assuming he gets $0.05 for each lb of .... well, you know), and the number of times he got bitten.

Note: The above descriptions of these classes are bare minimum. You may find it necessary or desirable to add relevant member variables and/or private member functions (to help make the code better). You should NOT add other public functions.

We reserve the right to change these classes and the formulas .....

When you submit: do it.

As always, if you have questions, don't hesitate to ask your instructor or the tutor in the lab in the evenings.