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


#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
static int platypus_count=0;
class Animal_Category {
private:
   string appearance;
   bool nurse;
   bool cold_blooded;
   bool live_on_land;
   bool live_in_water;
public:
   Animal_Category(string tappearance, bool tnurse, bool tcold_blooded, bool tlive_on_land, bool tlive_in_water)
   {
       this->appearance = tappearance;
       this->nurse = tnurse;
       this->cold_blooded = tcold_blooded;
       this->live_on_land = tlive_on_land;
       this->live_in_water = tlive_in_water;
   }
   void print() {
       cout << left << setw(15) << "Appearance :" << right << setw(15) << this->appearance << endl;
       if(this->nurse)
       cout << left << setw(15) << "Nurse :" << right << setw(15) << "YES" << endl;
       else
       cout << left << setw(15) << "Nurse :" << right << setw(15) << "NO" << endl;
       if(this->cold_blooded)
       cout << left << setw(15) << "Cold Blooded :" << right << setw(15) << "YES" << endl;
       else
       cout << left << setw(15) << "Cold Blooded :" << right << setw(15) << "NO" << endl;
       if(this->live_on_land)
       cout << left << setw(15) << "Live on Land :" << right << setw(15) << "YES"<< endl;
       else
       cout << left << setw(15) << "Live on Land :" << right << setw(15) << "NO" << endl;
       if(this->live_in_water)
       cout << left << setw(15) << "Live in Water :" << right << setw(15) << "YES" << endl;
       else
   cout << left << setw(15) << "Live in Water :" << right << setw(15) << "NO" << endl;
   }
};
class Platypus {
private:
   float weight;
   int age;
   string name;
   char gender;
   bool alive;
   bool mutant;
   Animal_Category *animal_type;
   const int mutation_rate = 2;
public:
   Platypus() {
       this->weight = 0.0;
       this->age = 0;
       this->name = "";
       this->gender =' ';
       this->alive = false;
       this->mutant = false;
       this->animal_type = NULL;
       platypus_count++;
   }
   Platypus(float tweight,int tage,string tname,char tgender)
   {
       this->weight = tweight;
       this->age = tage;
       this->name = tname;
       this->gender = tgender;
       this->alive = true;
       this-> mutant= false;
       this->animal_type = new Animal_Category("fur", true, false, true, true);
       platypus_count++;
   }
   void print()
   {
       cout << left << setw(15) << "Weight :" << right << setw(15) << this->weight << endl;
       cout << left << setw(15) << "Age :" << right << setw(15) << this->age << endl;
       cout << left << setw(15) << "Name :" << right << setw(15) << this->name << endl;
       if(this->gender=='f')
       cout << left << setw(15) << "Gender :" << right << setw(15) << "FEMALE" << endl;
       else if (this->gender == 'm')
   cout << left << setw(15) << "Gender :" << right << setw(15) << "MALE" << endl;
       if(this->alive)
       cout << left << setw(15) << "Alive :" << right << setw(15) << "YES" << endl;
       else
   cout << left << setw(15) << "Alive :" << right << setw(15) << "NO" << endl;
       this->animal_type->print();
       cout << endl;
   }
   void age_me() {
       if (alive)
       {
           this->age = age + 1;
           if (age*mutation_rate == 100)
               this->mutant = true;
           if (10 * this->weight >= 100)
               alive = false;
       }

   }
   Platypus fight(Platypus other)
   {
       if ((this->alive) && (other.alive))
       {
           int fight_val = rand() % (101);
           if (((this->weight / other.weight) * 50) >= fight_val)
               return (*this);
           else
               return (other);
       }
       cout << "Not a valid fight" << endl;
       return (*this);
   }
   void eat()
   {
       if (this->alive)
       {
           float random = ((float)rand() / (float)RAND_MAX);
           float r = random * 4.9;
           this->weight += ((r / 100)*this->weight);
       }
       else
       {
           cout << "Platypus can't eat" << endl;
       }
   }
   friend Platypus hatch(Platypus parent);
  
};
Platypus hatch(Platypus parent)
{
   if (parent.mutant)
   {
       char gen;
       int m_f = rand() % 2;
       if (m_f == 0)gen = 'f';
       else gen = 'm';
       float random = ((float)rand() / (float)RAND_MAX);
       float r = random * 0.9;
       float weight = 0.1 + r;
       return(Platypus(weight, 0, "plipo", gen));
   }
   return (Platypus());
}
int main()
{
   Platypus p1(1.5, 48, "Arin", 'f');
   p1.print();

   p1.age_me();
   p1.age_me();

   p1.print();

   Platypus p2 = hatch(p1);
   p2.print();

   p2.fight(p1).print();

   Platypus p3(10, 49, "Eric", 'm');
   p3.print();
   p3.age_me();
   p3.print();
   p3.fight(p1).print();

   p1.eat();
   p1.print();
   p3.eat();
   p3.print();
   return 1;
}



OUTPUT:

Weight : 1.5
Age : 48
Name : Arin
Gender : FEMALE
Alive : YES
Appearance : fur
Nurse : YES
Cold Blooded : NO
Live on Land : YES
Live in Water : YES

Weight : 1.5
Age : 50
Name : Arin
Gender : FEMALE
Alive : YES
Appearance : fur
Nurse : YES
Cold Blooded : NO
Live on Land : YES
Live in Water : YES

Weight : 0.607227
Age : 0
Name : plipo
Gender : MALE
Alive : YES
Appearance : fur
Nurse : YES
Cold Blooded : NO
Live on Land : YES
Live in Water : YES

Weight : 1.5
Age : 50
Name : Arin
Gender : FEMALE
Alive : YES
Appearance : fur
Nurse : YES
Cold Blooded : NO
Live on Land : YES
Live in Water : YES

Weight : 10
Age : 49
Name : Eric
Gender : MALE
Alive : YES
Appearance : fur
Nurse : YES
Cold Blooded : NO
Live on Land : YES
Live in Water : YES

Weight : 10
Age : 50
Name : Eric
Gender : MALE
Alive : NO
Appearance : fur
Nurse : YES
Cold Blooded : NO
Live on Land : YES
Live in Water : YES

Not a valid fight
Weight : 10
Age : 50
Name : Eric
Gender : MALE
Alive : NO
Appearance : fur
Nurse : YES
Cold Blooded : NO
Live on Land : YES
Live in Water : YES


Weight : 1.55944
Age : 50
Name : Arin
Gender : FEMALE
Alive : YES
Appearance : fur
Nurse : YES
Cold Blooded : NO
Live on Land : YES
Live in Water : YES

Platypus can't eat
Weight : 10
Age : 50
Name : Eric
Gender : MALE
Alive : NO
Appearance : fur
Nurse : YES
Cold Blooded : NO
Live on Land : YES
Live in Water : YES


Related Solutions

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?
Does any one know anything about assisted living facilities background information on the Long term care...
Does any one know anything about assisted living facilities background information on the Long term care organization, types of services provided by the LTC organization, individuals who receive services from the LTC organization, and reimbursement for services for the LTC.   (in one page essay need more information for study)
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