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

In this program you\'ll need to store the populations of 12 countries. Define tw

ID: 3777947 • Letter: I

Question

In this program you'll need to store the populations of 12 countries.

Define two arrays that will be used in parallel to store the names of the countries and their populations.

Write a loop that uses these arrays to print each country's name and its population.

Add a loop in your main method which asks the user running it if they would like to look up a given country's population. When they indicate “No” the program terminates.

Prompt user: What country would you like to look up?

Upon user entering something the program calls the countryLookup method.

countryLookup method accepts an argument (parameter) containing what the user entered for the country to look up. The method searches country name array for the name and upon finding it returns the corresponding population from the population array. If it doesn't find the country simply return -1.

China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000

Explanation / Answer

#include <iostream>

#include <string>

int main()

{

constexpr int ARRAY_SIZE = 12 ;

std::string country[ARRAY_SIZE] ;

int population[ARRAY_SIZE] = {0};

for( int i = 0 ; i < ARRAY_SIZE ; ++i )

{

std::cout << "country: " ;

std::getline( std::cin, country[i] ) ;

std::cout << "populaion: ";

std::cin >> population[i] ;

std::cin.ignore( 1000, ' ' ) ;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote