Question
An input contains data on animals being monitored in anational park. the very first line has an integer representing thenumber of years(n) for the study. For each animal, the first inputline has the animal's name, and the second line has three values:the park's population (P) of that animal on the first day of theyear: the annual birth rate (B) of the animal: the annual deathrate (D) of that animal. The program is to calculate, for each animal, the estimatedpopulation after n years. the program should not process bad data,such as a negative birth rate, a negative death rate, or apopulation less than 2. the program must use the followingfunctions: (1) growthRate: This function takes as its parameters thebirth and death rates, and it returns the population growthrate. (2) estimatedPopulation: This function takes as its parametersthe current population, population growth rate, and n, the numberof years. it returns the estimated population after n years. Formulas: If P is the population on the first day of the year, Bis the birth rate, and D is the death rate, the estimatedpopulation at the end of the year is given by: P+B*P/100-D*P/100 The population growth rate is given by the formula: B-D Output, to a file, tells the number of years of the study,then the names and estimated populations of each animal at the endof the study. ( In case of bad data, give an appropriatemessage.) sample input file could contain: 5 Fox 300 28 15 Rabbit 525 50 40 Bald Eagle 20 -5 12 Lynx 1 20 10 An input contains data on animals being monitored in anational park. the very first line has an integer representing thenumber of years(n) for the study. For each animal, the first inputline has the animal's name, and the second line has three values:the park's population (P) of that animal on the first day of theyear: the annual birth rate (B) of the animal: the annual deathrate (D) of that animal. The program is to calculate, for each animal, the estimatedpopulation after n years. the program should not process bad data,such as a negative birth rate, a negative death rate, or apopulation less than 2. the program must use the followingfunctions: (1) growthRate: This function takes as its parameters thebirth and death rates, and it returns the population growthrate. (2) estimatedPopulation: This function takes as its parametersthe current population, population growth rate, and n, the numberof years. it returns the estimated population after n years. Formulas: If P is the population on the first day of the year, Bis the birth rate, and D is the death rate, the estimatedpopulation at the end of the year is given by: P+B*P/100-D*P/100 The population growth rate is given by the formula: B-D Output, to a file, tells the number of years of the study,then the names and estimated populations of each animal at the endof the study. ( In case of bad data, give an appropriatemessage.) sample input file could contain: 5 Fox 300 28 15 Rabbit 525 50 40 Bald Eagle 20 -5 12 Lynx 1 20 10
Explanation / Answer
/* My program is giving me infinite problem to read lines fromfile eg: Bald Eagle so i changed the anem "bald Eagle" in input.txt to"BaldEagle"..taht is working infile>>name; //this reads only 1 word infile.getline(name,256); //this has to read the whole line....butdonno why its not working with my machine or compiler Try uncommenting infile.getline(name,256); and commentinfile>>name; */ #include #include #include #include using namespace std; double growthRate(double b, double d) { return b-d; } double estimatedPopulation(int p, double growth, int n) { int i=0; while(i