Question

In: Computer Science

Mr. Kent doesn't care about almost anything ... but himself and his money. So, when his...

Mr. Kent doesn't care about almost anything ... but himself and his money. So, when his power plant leaked radioactive goo that caused several species of wildlife to go extinct, he was only concerned with the public perception as it might affect his income and possible jail time.

Many rumors surfaced around the Springfield Nuclear Power Plant. One of them is high concern over the mutation rate of the rare Springfield molted platypus. With barely more than 500 left in the wild, the word "extinction" has been tossed around. So, to quell the media, Mr. Kent had 30 of them captured, dissected, and analyzed to check for signs of mutation. He found that the mutation rate is 2% each month, but when they do mutate, they become sterile and cannot reproduce. With this information, he wants to create one of those newfangled computer simulations that the press loves so much. That's where you come in!

Specifications:

In this assignment, you will create a class called Animal_Category.

Your Animal_Category class is to contain the following data members:

  • A string for appearance ( hair/fur/scale/feathers)
  • a bool for nurse (true/false)
  • a bool for cold_blooded (true/false)
  • a bool for live_on_land (true/false)
  • a bool for live_in_water (true/false)

Your Animal_Category class is to contain the following member functions:

  • a constructor with arguments
  • a print function

You will also create a class called Platypus. 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.

Your Platypus class is to contain the following data members:

  • a static int for platypus_count (to increment upon creation of a new platypus and decrement upon destruction of a platypus)
  • a float for weight
  • an int for age (months)
  • a string for name
  • a char for gender
  • a bool to indicate whether alive (or not)
  • a bool to indicate whether mutant (or not)
  • an Animal_Category for animal_type
  • a constant mutation rate that is 2%

Member functions:

  • a constructor with no arguments 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 constant 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 calculate the chance that the object will become a mutant and when needed changes the value of the corresponding data member (remember that the mutation rate is 2% each month and it should become 100% for the platypus to become 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. Again here update the value of the corresponding data member when needed.

  • 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 generated. If it is less than the fight ratio, the calling platypus survives; otherwise the other platypus survives. You must to be able to have a statement like p1.fight(p2).print() (where p1 and p2 are objects of this class)
  • 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.
  • A friend hatch function that will randomly set up a newborn platypus with alive=true, mutant=false, and age=0. Gender will randomly be 'm' or 'f' with equal probability. Weight will randomly be between 0.1 and 1.0 pounds. Name will default to “plipo”.

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.

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.

c++ language

Solutions

Expert Solution

Source Code:

#include<iostream>

using namespace std;

class platypus
{
float weight=0.0;
short age=0.0;
char name='a';
char gender='m';
bool alive=true;
bool mutant=true;

public:

platypus()
{
alive = 0;
}

platypus(char g, float w, short a, char n)
{
gender = g;
weight = w;
age = a;
name = n;
}

void print()
{
cout<<"Name is: "<<name<<"\n";
cout<<"Gender is: "<<gender<<"\n";
cout<<"Weight is: "<<weight<<"\n";
cout<<"Age is: "<<age<<"\n";

if(alive)
{
cout<<"Platypus is alive\n";
}
else
{
cout<<"Platypus is dead\n";
}

if(mutant)
{
cout<<"Platypus is mutant\n";
}
else
{
cout<<"Platypus is not mutant\n";
}

cout<<"\n";

}

void age_me()
{
age++;
/*int chance = (int)((rand() * age)%10+1)*10;
//cout<<"\n";
cout<<"It has "<<chance<<"% chance of death\n";*/

int chance = weight*10;
cout<<"It has "<<chance<<"% chance of death\n";
}

void fight(platypus p)
{
int rat = (weight/p.weight)*50;
int val = rand()%100;
//cout<<val<<"\n";
if(val<rat)
{
alive = 1;
p.alive = 0;
}
else
{
p.alive = 1;
alive = 0;
}
}

void eat()
{
if(alive)
{
weight = weight + (rand()%50)/10;
}
}

void hatch()
{
alive = true;
mutant = false;
age = 0;
int val = rand()%2;
if(val==1)
{
gender = 'm';
}
else
gender = 'f';

val = rand()%26;
name = 'a'+val;
}


};

//Driver function
int main()
{
platypus p;// = new platypus;
p.print();

platypus p1('m',5,11,'b');
//p = new platypus(m,23,10,a);
p1.print();
p1.age_me();
p1.print();

platypus p2('f',6,7,'c');
p2.print();

p1.fight(p2);
p2.print();
p1.print();

p1.hatch();
p1.print();

return 0;
}


Related Solutions

Mr. Kent doesn't care about almost anything ... but himself and his money. So, when his...
Mr. Kent doesn't care about almost anything ... but himself and his money. So, when his power plant leaked radioactive goo that caused several species of wildlife to go extinct, he was only concerned with the public perception as it might affect his income and possible jail time. Many rumors surfaced around the Springfield Nuclear Power Plant. One of them is high concern over the mutation rate of the rare Springfield molted platypus. With barely more than 500 left in...
Mr. Kent is working on the evaluation of a new project for his company. In year...
Mr. Kent is working on the evaluation of a new project for his company. In year 3 of his evaluation, he estimates that sales and cost of sold would be $5.8 million and $3.48 million, respectively. The cost of the machine is $1 million, and it would depreciate using the straight line method for a useful life of 5 years. The corporate tax rate is 35 percent. Moreover, he expects an increase in working capital from $210,000 in year 2...
1. Mr. Shaggy comes in to see his health care provider for his yearly checkup. As...
1. Mr. Shaggy comes in to see his health care provider for his yearly checkup. As you are taking     his blood pressure, he says “I don’t need that rectal examination do I ? I had prostate surgery       last year.” How do you respond? 2. Mrs. Butterworth has just returned from an endoscopic examination. She says, “Something     went wrong, I just know it. Look at my belly. I look like I am 9 months pregnant”. How do you     respond?
1. What, if anything, should be done about the deficit? Would you increase revenue? If so,...
1. What, if anything, should be done about the deficit? Would you increase revenue? If so, what taxes would you adjust? Should expenditures be slashed, what should be decreased? By how much? 2.Which has a larger effect on aggregate demand: an increase in government expenditure or an equal sized decrease in taxes?
Nursing actions when patient can no longer make decisions about his/her own care
Nursing actions when patient can no longer make decisions about his/her own care
Mr. Rashid plans to purchase the electronics itemsbased on his budget. So he needs a...
Mr. Rashid plans to purchase the electronics items based on his budget. So he needs a purchase planner which will help to calculate the price of electronics items, he can purchase based on the available amount. If Mr. Rashid enters his budget amount and chooses the numbers of electronic items from the list of available electronic items, the purchase planner will calculate the cost of electronics items based on the number of items selected, the total cost of all the...
Why is U.S. health care so costly? Why have almost all past cost controls failed? What...
Why is U.S. health care so costly? Why have almost all past cost controls failed? What are the best ways to contain health care costs, and how can we do so without harming access or quality?
why is us health care so costly? why have almost all past cost controls faild? what...
why is us health care so costly? why have almost all past cost controls faild? what are the best ways to contai. health care costs, and how can we do so without harming access or quality?
James moved to a new house so he rented his old home to Mr. Parker for...
James moved to a new house so he rented his old home to Mr. Parker for two years. Later the old house caught fire and had a $100,000 loss. The old house was valued at $400,000 and James had a $300,000 homeowner's insurance policy with an 80% coinsurance. How much will insurance company pay for his loss?
Mr. DeVito is a 48 old male who presents to his Primary Care Provider with left...
Mr. DeVito is a 48 old male who presents to his Primary Care Provider with left upper abdominal pain and complain of weakness and fatigue. The nurse immediately notes how pale his skin. A full set of vitals reveals the following: HR 82bpm, BP 142/90 mmhg, RR 16bpm, Spo2 94 on room air, Temp 101.0 F What further Nursing Assessment would you perform at this time? Upon further assessment, the nurse notes a palpable mass in the left upper quadrant,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT