Using C++ program please HAND IN LABORATORY TASK: #17( if you get an A grade you
ID: 3595989 • Letter: U
Question
Using C++ program please
HAND IN LABORATORY TASK: #17( if you get an A grade your earn 20pts for AVG) FOX HEAVEN an island off the coast of Costa Rica near Isla Sorna (REPORTS OF STRANGE CREATURES ON THIS ISLAND) Write a program to study the population of foxes ON Fox Heaven Island as the years go by with the following conditions. BE SURE TO DOA FLOW CHART FIRST AND HAND IN WITH THE PROGRAM You study the island and count the foxes at 20 with a lot of rabbits, namely 13,000 rabbits Looks like plenty of rabbits to keep this island going for a long time. So in your study you find information About the fox and rabbit reproduction and build this program to predict the future for the island As follows If every thing is ok, ie a GOOD YEAR foxes can survive by eating 208 rabbits for the year That means that a good year is if the total number of rabbits is greater than the number of present foxes times the 208 rabbits, if the present number of rabbits falls below the good year then it's a BAD YEAR AND AND FOXES WOULD NEED TO EAT ONLY 52 RABBITS TO JUST SURVIVE very skinny. In a good year the rabbit population goes down by number eaten # foxes *208 and the remaining rabbits goes up by 50% And the foxes population increases 15% of the previous years value but if year is bad (#of rabbitsExplanation / Answer
Q1: Code for problem 1
#include <iostream>
using namespace std;
int main()
{
int foxes=20;
int rabbits=13000;
int year=1;
int good=0;
int bad=0;
int die;
cout<<"Year "<<"Foxes "<<"Rabbits"<<endl;
while(year<=30)
{
cout<<year<<" "<<foxes<<" "<<rabbits<<endl;
if(rabbits>foxes*208 && foxes!=0)
{
rabbits-=foxes*208;
foxes=foxes*1.15;
rabbits*=1.5;
good++;
}
else if(rabbits<foxes*208 && foxes!=0)
{
rabbits-=foxes*52;
foxes=foxes*1.03;
rabbits*=1.5;
bad++;
}
if(rabbits<0)
{
foxes=0;
rabbits=0;
die=year;
break;
}
year++;
}
cout<<"Good years="<<good<<" "<<"Bad years="<<bad<<" "<<"Dies in the year="<<die<<endl;
}
There can be two interpretations of year in which they die as in the year in which there is not sufficient rabbits to feed the foxes(I have written code according to this.) or the next year of this because the foxes would have vanished in that year
Q2: Code Including the change(if we assume that foxes are killed before they have reproduced)
#include <iostream>
using namespace std;
int main()
{
int foxes=20;
int rabbits=13000;
int year=1;
int good=0;
int bad=0;
int die=0;
cout<<"Year "<<"Foxes "<<"Rabbits"<<endl;
while(year<=30)
{
int killed=0;
cout<<year<<" "<<foxes<<" "<<rabbits<<endl;
if(rabbits>foxes*208 && foxes>0)
{
rabbits-=foxes*208;
killed=foxes*0.05;
foxes=foxes-killed;
foxes=foxes*1.15;
rabbits*=1.5;
//the code should work according to me.
good++;
}
else if(rabbits<foxes*208 && foxes>0)
{
rabbits-=foxes*52;
foxes=foxes*1.03;
rabbits*=1.5;
bad++;
}
if(rabbits<0)
{
foxes=0;
rabbits=0;
die=year;
break;
}
year++;
}
cout<<"Good years="<<good<<" "<<"Bad years="<<bad<<" "<<"Dies in the year="<<die<<endl;
}
If you want that foxes are killed after they have reproduced then you just have to change the order of statements in for if statement.
The killers actually made the good years increased in numbers as the foxes had 5 good years and 3 bad years earlier but now they had 7 good years and 1 bad year before they don't have enough rabbits to survive.
Q3
If 10% of foxes are killed every good year then foxes will survive with 30 good years
It is assumed that if foxes=21.245(say) then we have only 21 foxes.I hope that you understand that I have taken integer lower than the foxes value.
So the output in the case where 10% foxes are killed the foxes remain 20 because of this truncation.
Please do upvote my answer by giving it a thumbs up.
Thank You.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.