1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mnenie [13.5K]
3 years ago
8

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: The population of town A The population of town B The growth rate of town A The growth rate of town B The program outputs: After how many years the population of town A will be greater than or equal to the population of town B The populations of both the towns at that time. (A sample input is: Population of town A
Computers and Technology
1 answer:
weeeeeb [17]3 years ago
6 0

Answer: The c++ program is given below.

#include <iostream>

using namespace std;

int main() {

float townA, townB, growthA, growthB, populationA, populationB;

    int year=0;    

cout<<"Enter present population of town A : ";

cin >> townA;  

cout<<endl<<"Enter present growth rate of town A : ";

cin >> growthA;

growthA = growthA/100;  

cout<<endl<<"Enter present population of town B : ";

cin >> townB;  

cout<<endl<<"Enter present growth rate of town B : ";

cin >> growthB;

growthB = growthB/100;  

do

{

    populationA = townA + (townA * growthA);

    populationB = townB + (townB * growthB);      

    townA = populationA;

    townB = populationB;      

    year++;      

}while(populationA < populationB);  

cout<<endl<<"After " <<year<< " years, population of town A is "<<populationA << " and population of town B is "<< population<<endl;

return 0;

}

Explanation:

All the variables for population and growth rate are declared with float datatype.

The user inputs the present population of both the towns.

The growth rate entered by the user is the percentage growth.

For example, town A has 10% growth rate as shown in the output image.

The program converts 10% into float as 10/100.

growthA = growthA/100;

growthB = growthB/100;

The above conversion is done to ease the calculations.

The year variable is declared as integer and initialized to 0.

The growth in population is computed in a do-while loop. After each growth is calculated, the year variable is incremented by 1.

The loop continues until population of town A becomes greater than or equal to population of town B as mentioned in the question.

Once the loop discontinues, the final populations of town A and town B and the years needed for this growth is displayed.

The new line is introduced using endl keyword.

The function main has return type int hence, 0 is returned at the end of the program.

You might be interested in
Trisha is looking for a new table style. What is the fastest way for her to preview how different styles in the gallery would lo
Elena-2011 [213]

Answer: The correct answer is to hover the cursor over the different styles in the gallery.

Explanation: The fastest way to preview the different styles in the style gallery is to hover the cursor over each style. This will preview the style, without making the permanent change so that you can see how it looks without changing to each individual style.

4 0
3 years ago
What is the output of the following C++ program?
KIM [24]

Answer:

Output:<em> </em><em>15 11/16 inches</em>

Explanation:

#include <iostream>

using namespace std;

////////////////////////////////////////////////////////////////////////

class InchSize {

public:

   InchSize(int wholeInches = 0, int sixteenths = 0);

   void Print() const;

   InchSize operator+(InchSize rhs);

   

private:

   int inches;

   int sixteenths;

};

InchSize InchSize::operator+(InchSize rhs) {

   InchSize totalSize;

   totalSize.inches = inches + rhs.inches;

   totalSize.sixteenths = sixteenths + rhs.sixteenths;

   

   // If sixteenths is greater than an inch, carry 1 to inches.

   if (totalSize.sixteenths >= 16) {

       totalSize.inches += 1;

       totalSize.sixteenths -= 16;

   }

   return totalSize;

}

InchSize::InchSize(int wholeInches, int sixteenthsOfInch) {

   inches = wholeInches;

   sixteenths = sixteenthsOfInch;

}

void InchSize::Print() const {

   cout<<inches<<" "<<sixteenths<<"/16 inches"<<endl;

}

////////////////////////////////////////////////////////////////////////

int main() {

   InchSize size1(5, 13);

   InchSize size2(9, 14);

   InchSize sumSize;

   sumSize = size1 + size2;

   sumSize.Print();

   return 0;

}

////////////////////////////////////////////////////////////////////////

sumSize variable was printed in the end. Print() prints the calling object's inches and sixteenths variables' values.

sumSize's inches is equal to size1 plus size2's inches.

Because the sum of sixteenths was greater than 16, sumSize's sixteenth was decreased by 1 and inches was increased by 1.

3 0
3 years ago
Enter a word: Good<br> Enter a word: morning<br> Good morning
blondinia [14]
Good Morning Everyone I-
8 0
3 years ago
Read 2 more answers
If you want to conserve ink or toner, you can instruct PowerPoint to print ____ documents.
kondor19780726 [428]
I believe the answer would be Draft Quality. (300x300 resolution).

5 0
3 years ago
Define each of the following data mining functionalities: characterization, discrimination, association and correlation analysis
Step2247 [10]

Answer:

In the clarification portion below, the definition according to the received information is summarized.

Explanation:

  • <u>Characterization:</u>

It is indeed a summary of general object characteristics in something like a target class and creates characteristic laws.

  • <u>Discrimination:</u>

Just before predefined data types have been held to a different standard from everyone else, it's indeed bias which always happens.

  • <u>Association:</u>

It's a mechanism that determines the possibility that objects in a set will co-occur.

  • <u>Classification:</u>

It is indeed duction which attributes elements to target groups or classes in a set.

  • <u>Prediction:</u>

It is solely dependent on either the interpretation of other similar values to classify data points.

  • <u>Clustering:</u>

It has been used to position the components of the information through their corresponding classes.

  • <u>Evolution Analysis:</u>

It would be for objects whose behavior varies throughout time to explain or design regularities.

5 0
3 years ago
Other questions:
  • Which mistakes are NOT highlighted by the spell checker in a word-processing document?
    15·2 answers
  • Which of the following instructions should be allowed only in kernel mode? (a) Disable all interrupts. (b) Read the time-of-day
    11·1 answer
  • The objective of an Enterprise Resource Planning (ERP) system is to create a customized software program that integrates the inf
    15·1 answer
  • It is an island country; it fought against us in World War II; it is known for sushi.
    14·2 answers
  • What Is entered into the system as input?
    13·1 answer
  • Question:
    14·1 answer
  • Question 2
    7·1 answer
  • What is the advantage of entering metadata for electronic records that you create
    7·1 answer
  • What is the most used gaming keyboard in 2022?
    8·1 answer
  • The RGB value below produces a shade of purple. What does the number 175
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!