Question

In: Computer Science

C++ Instructions The population of town A is less than the population of town B. However,...

C++

Instructions

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

Write a program that prompts the user to enter:

  1. The population of town A
  2. The population of town B
  3. The growth rate of town A
  4. The growth rate of town B

The program outputs:

  1. After how many years the population of town A will be greater than or equal to the population of town B
  2. The populations of both the towns at that time.

(A sample input is: Population of town A = 5,000, growth rate of town A = 4%, population of town B = 8,000, and growth rate of town B = 2%.)

Solutions

Expert Solution

Hey mate, find the code for above program below. And do refer the screenshot for proper indentation and error free execution of the code.

PROGRAM -

#include<iostream>
using namespace std;

int main()
{
    int popA,popB,year=0;    /* integer variables to store population of town A and B 
                                and assigning year=0 to take it as present year */
    
    float grA,grB;           /* float variables to store growth rate of town A and B */
    
    cout<<"The population of town A : ";
    cin>>popA;
    cout<<"The growth rate of town A in % : ";
    cin>>grA;
    cout<<'\n';
    
    cout<<"The population of town B : ";
    cin>>popB;
    cout<<"The growth rate of town B in % : ";
    cin>>grB;
    cout<<'\n';
    
    if(popA < popB && grA > grB)
    {
        while(popA < popB)
        {
            popA=((grA/100)*popA)+popA;  /* calculating population growth of town A in one year */
            popB=((grB/100)*popB)+popB;  /* calculating population growth of town B in one year */
            year=year+1;                 /* incrementing year until population of town A is greater than town B */
        }
        
        if(popA > popB){
            cout<<"After "<<year<<" years, the population of town A will be greater than population of town B\n";
        }
        else{
            cout<<"After "<<year<<" years, the population of town A will be equal to population of town B\n";
        }
        cout<<"Population of town A after "<<year<<" years : "<<popA<<'\n';
        cout<<"Population of town B after "<<year<<" years : "<<popB;
    }
    
    else
    {
        cout<<"Invalid input due to one of the following reasons:\n";
        cout<<"1.Population of town A is already greater than or equal to town B\n";
        cout<<"2.Growth rate of town A is less than town B\n";
    }
    
    return 0;
}

SAMPLE OUTPUT -


Related Solutions

The population of a town A is less than the population of town B. However, the...
The population of a town A is less than the population of town B. However, the population of town A is growing faster than the population of town B. Write a program that prompts the user to enter the population and growth rate of each town. The program outputs after how many years the population of town A will be greater than or equal to the population of town B and the populations of both the towns at that time....
Find the p-value of the test. A) Less than 0.25% B) Between 0.25% and 0.5% C)...
Find the p-value of the test. A) Less than 0.25% B) Between 0.25% and 0.5% C) Between 0.5% and 1% D) Between 1% and 2.5% E) Between 2.5% and 5% F) Between 5% and 10% G) Between 10% and 15% H) Between 15% and 20% I) Between 15% and 20% J) Bigger than 20%. Are births really evenly distributed across the days of a week? Here are data on 700 births in a hospital: Day Sun. Mon. Tue. Wed. Thu....
7) THE COSTS OF PRODUCING HATS HAVE INCREASED CONSIDERABLY, HOWEVER, THEIR EFFECT IS LESS THAN THE...
7) THE COSTS OF PRODUCING HATS HAVE INCREASED CONSIDERABLY, HOWEVER, THEIR EFFECT IS LESS THAN THE DECREASE OF TAXES FOR THE PRODUCTION OF THE SAME. Offer Increase 8) THE GOVERNMENT REDUCED TAXES FOR INDIVIDUALS, APPLIED TO THE NAME OF THESE. Demand Increases 9) COMPETITION PRICES HAVE INCREASED CONSIDERABLY, RESULTING IN AN INCREASE OF BUYERS AND THIS IN turn INCREASES THE INVENTORY MOVEMENT. HOWEVER, BUYERS 'REACTION IS GREATER THAN INVENTORY MOVEMENT. Demand Increases. Offer Increase 10) THE MANUFACTURING SECTOR OF SOLAR...
Audits and Compliance / Enterprise Security Strategy Plan Instructions: In NO LESS than 400 words, answer...
Audits and Compliance / Enterprise Security Strategy Plan Instructions: In NO LESS than 400 words, answer the following question. Compare and contrast audits and assessments. •Pick at least 3 things that are the same and 3 things that are different. •Compare the goals, the timing, and the roles that are involved.
Implementation, Operations, and Monitoring / Enterprise Security Strategy Plan Instructions: In NO LESS than 400 words,...
Implementation, Operations, and Monitoring / Enterprise Security Strategy Plan Instructions: In NO LESS than 400 words, answer the following question. Regarding the implementation of a security plan, this can be anything from the organizational change management aspects (users) or the technical implementation (information technology staff),Select 2 key areas to either engage in the normal, everyday operations of a security team, or 2 key areas to monitor, and why. Describe and evaluate each key area. 200 words requirement for each.
You wish to test the claim that the first population mean is less than the second...
You wish to test the claim that the first population mean is less than the second population meanat a significance level of α=0.001α=0.001.      Ho:μ1=μ2Ho:μ1=μ2 Ha:μ1<μ2Ha:μ1<μ2 You obtain the following two samples of data. Sample #1 Sample #2 43.3 56.2 64.2 49.7 95.4 61.0 85.0 49.1 50.9 49.1 61.0 63.2 72.7 81.7 41.4 55.8 54.5 83.6 93.5 79.2 74.9 77.8 49.8 48.8 43.5 90.5 90.5 76.2 47.7 What is the test statistic for this sample? test statistic =   Round to 3...
You wish to test the claim that the first population mean is less than the second...
You wish to test the claim that the first population mean is less than the second population mean at a significance level of α=0.01α=0.01.      Ho:μ1=μ2Ho:μ1=μ2 Ha:μ1<μ2Ha:μ1<μ2 You obtain the following two samples of data. Sample #1 Sample #2 71.2 85.7 85.4 76.5 92.2 81.3 72.7 71.8 86.8 78.3 86.3 78.7 80.3 72.2 93.3 83.2 86.8 85.3 81.6 80.5 87.8 88.6 75.4 What is the test statistic for this sample? test statistic = Round to 3 decimal places. What is...
You wish to test the claim that the first population mean is less than the second...
You wish to test the claim that the first population mean is less than the second population mean at a significance level of α=0.001α=0.001.      Ho:μ1=μ2Ho:μ1=μ2 Ha:μ1<μ2Ha:μ1<μ2 You obtain the following two samples of data. Sample #1 Sample #2 41.5 47.1 71.9 67.8 57.1 72.9 52.3 70.3 65.5 68.8 66.2 69.3 70.4 87.8 79.7 89.4 81.0 70.4 71.4 68.8 91.6 82.1 79.1 What is the test statistic for this sample? test statistic =  Round to 4 decimal places. What is the...
You wish to test the claim that the first population mean is less than the second...
You wish to test the claim that the first population mean is less than the second population mean at a significance level of α=0.01α=0.01.      Ho:μ1=μ2Ho:μ1=μ2 Ha:μ1<μ2Ha:μ1<μ2 You obtain the following two samples of data. Sample #1 Sample #2 71.2 85.7 85.4 76.5 92.2 81.3 72.7 71.8 86.8 78.3 86.3 78.7 80.3 72.2 93.3 83.2 86.8 85.3 81.6 80.5 87.8 88.6 75.4 What is the test statistic for this sample? test statistic = Round to 3 decimal places. What is...
You wish to test the claim that the first population mean is less than the second...
You wish to test the claim that the first population mean is less than the second population mean at a significance level of α=0.02α=0.02.      Ho:μ1=μ2Ho:μ1=μ2 Ha:μ1<μ2Ha:μ1<μ2 You obtain the following two samples of data. Sample #1 Sample #2 72.8 86.5 83.4 79.7 88.0 76.7 86.5 87.5 93.6 91.3 82.0 78.6 92.7 89.2 95.0 63.1 82.9 82.0 104.1 75.4 84.2 98.6 60.6 76.4 85.9 83.7 75.9 74.8 What is the test statistic for this sample? test statistic =  Round to 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT