Answer to Question #297130 in C++ for hanc

Question #297130

The population of a town A is less than the population of town B.However, the population of



algorithmoutputs after how many years the population of town A will be greater than or equal to



flowchartthat prompts the user to enter the population and growth rate of each town. The



Population of town A =5000, growth rate of town A = 4%, populationof town B = 8000, and



town A is growing faster than the population of town B. Write algorithm usingpseudocodeand



the population of town B and the populations of both the towns at that time. (A sample input is:



growth rate of town B =2%)

1
Expert's answer
2022-02-12T16:22:16-0500
Algorithm

Function Main
    Declare Integer popA
    Declare Integer popB
    Declare Integer year
    Declare Real growA
    Declare Real growB
    
    Output "Enter the population of town A: "
    Input popA
    Output "Enter the population of town B: "
    Input popB
    Output "Enter growth rate in percent of town A: "
    Input growA
    Output "Enter growth rate in percent of town B "
    Input growB
    Assign year = 0
    If popA <= popB && growA > growB
        Loop
            Assign popA = ((growA / 100) * popA) + popA
            Assign popB = ((growB / 100) * popB) + popB
            Assign year = year+1
        Do popA <= popB
        Output "The Population of town A After " & year & " years is " & popA
        Output "The Population of town B After " & year & " years is " & popB
    False:
        Output "Does Not Compute"
    End
End


flowchart





c++ code:


#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>


using namespace std;




int main() {
    int popA;
    int popB;
    int year;
    double growA;
    double growB;
    
    cout << "Enter the population of town A: " << endl;
    cin >> popA;
    cout << "Enter the population of town B: " << endl;
    cin >> popB;
    cout << "Enter growth rate in percent of town A: " << endl;
    cin >> growA;
    cout << "Enter growth rate in percent of town B " << endl;
    cin >> growB;
    year = 0;
    if (popA <= popB && growA > growB) {
        do {
            popA = (int) (growA / 100 * popA + popA);
            popB = (int) (growB / 100 * popB + popB);
            year = year + 1;
        } while (popA <= popB);
        cout << "The Population of town A After " << year << " years is " << popA << endl;
        cout << "The Population of town B After " << year << " years is " << popB << endl;
    } else {
        cout << "Does Not Compute" << endl;
    }


	cin>>growB;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog