Question: In this assignment, you will create a class called platypus using C++. Below, we will describe what will define a platypus. You will also create

In this assignment, you will create a class called platypus using C++. Below, we will describe what will define a platypus. You will also create a main function in which you will create objects of type platypus to test the functionality of your new user-defined type. You will need three files, the header file, and two .cpp files. The header file will consist of the class platypus, the first .cpp file will implement the platypus member functions, and lastly, the last .cpp file/test/driver file will be the test driver and also where "int main()" will be found.

Your platypus class is to contain the following:

Member variables:

a float for weight

a short for age (months)

a char for name initial

a char for gender

a bool to indicate whether alive (or not)

a bool to indicate whether mutant (or not)

Member functions:

a default constructor that creates a dead platypus

a constructor that you can pass values to so as to establish its gender, weight, age, and name; it will default to alive and not mutant.

a print function that will output to the screen the attributes of that platypus in a nice, easy to read format.

an age_me function that returns nothing but increments the object's age. It will also include a 2% chance that the object will become a mutant. Further, the platypus has a chance of becoming dead each time it ages. This chance is ten times the platypus' weight. A 5 pound platypus has a 50% chance of death. A 10 pound platypus (or heavier) has a 100% chance of death.

a fight function that accepts another platypus object as a parameter. It will have the calling platypus attack the other (passed in) platypus. The survivor is based on a "fight ratio": it is calculated as (calling_platypus_weight/other_platypus_weight) * 50. A random value from 1 to 100 is obtained. If it is less than the fight ratio, the calling platypus survives; otherwise the other platypus survives.

an eat function that increases the weight of the platypus by a random amount from 0.1% to 5.0% of the platypus' current weight.

Note: Think very carefully about writing the above functions and how they should be used. There are indeed circumstances when some functions should not execute. For example, a dead platypus shouldn't eat anything.

When you submit: Your program should fully test your platypus class. It must call every member function in the platypus class. It must print to the screen what it is doing and show the changes that appear when the member functions are called. The fight function will require two platypuses: one to call the fight function and one to be a parameter in the fight function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!