In: Computer Science
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:
Your Animal_Category class is to contain the following member functions:
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:
Member functions:
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.
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
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;
}