Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Problem 2 This program is designed to analyze the growth of two citi

ID: 1845877 • Letter: P

Question

Programming Problem 2

This program is designed to analyze the growth of two cities. Each city has a starting population and annual growth rate. The smaller city has the larger growth rate (required). Show the comparative populations of each city year by year until the smaller city has grown larger than the bigger city.

As an example, Dogville has a population of 5000 growing at 20% annually while Cattown has a population of 7000 growing at 10% annually. The projected populations are:

            Year    Dogville          Cattown

            1          6000                7700

            2          7200                8470

            3          8640                9317

            4          10368              10249

4. Identify three significant test cases including one for incorrect input (ie Small town has lower growth rate). For each of the three test cases show what inputs you will use and calculate what your expected outputs should be.

Explanation / Answer

#include <iostream>
using namespace std;
int main()
{int popA,popB;
double rateA,rateB;
int years=0;
cout<<"Enter population of Dogville: ";
cin>>popA;
cout<<"Enter growth rate of Dogville: ";
cin>>rateA;
cout<<"Enter population of Cattown: ";
cin>>popB;
cout<<"Enter growth rate of Cattown: ";
cin>>rateB;
rateA/=100.;
rateB/=100.;
cout<<"year Dogville Cattown ";

while(popA<popB)
{popA=(int)(popA*rateA+popA);
popB=(int)(popB*rateB+popB);
years++;
cout<<years<<" "<<popA<<" "<<popB<<endl;
}

system("pause");
return 0;
}