I need some help arranging these countries in a C++ program :China: 1,433,783,686India: 1,366,417,754United States: 329,064,917Indonesia: 270,625,568Pakistan: 216,565,318Brazil: 211,049,527Nigeria: 200,963,599Bangladesh: 163,046,161Russia: 145,872,256Mexico: 127,575,529Japan: 126,860,301Ethiopia: 112,078,730Philippines: 108,116,615Egypt: 100,388,073 As part of a larger program, you need to write code that will store and display the names and population values for 14 countries. Compose the code necessary to define two arrays that will be used in parallel to store the country names and their populations. Assume that a different part of the larger program is responsible for loading values into the parallel arrays you created. Write code that will display each of the country’s names and their corresponding population values.

Question
Asked Oct 6, 2019

I need some help arranging these countries in a C++ program :

China: 1,433,783,686

India: 1,366,417,754

United States: 329,064,917

Indonesia: 270,625,568

Pakistan: 216,565,318

Brazil: 211,049,527

Nigeria: 200,963,599

Bangladesh: 163,046,161

Russia: 145,872,256

Mexico: 127,575,529

Japan: 126,860,301

Ethiopia: 112,078,730

Philippines: 108,116,615

Egypt: 100,388,073

 

As part of a larger program, you need to write code that will store and display the names and population values for 14 countries. Compose the code necessary to define two arrays that will be used in parallel to store the country names and their populations. Assume that a different part of the larger program is responsible for loading values into the parallel arrays you created. Write code that will display each of the country’s names and their corresponding population values.

check_circle

Expert Answer

Step 1

Program Algorithm

  • Declare two arrays named country and population of size 14.
  • Using for loop enter the values in both the arrays.
  • Again, using for loop retrieve the value of city as well as population associated with it.
  • Also, while printing the population there should be a comma according to international number system.
Step 2

Source Code

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

string country[14];

    long population[14];

    long  c = 1;

    cout<<"Enter country name and its population"<<endl;

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

     {

         cin>>country[i];

         cin>>population[i];

     }

     cout<<"Displaying country’s names and their corresponding population values"<<endl;

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

     {

         cout<<country[i]<<":";

        if(population[i]<0) {population[i]*=-1;cout<<"-";}

        while((c*=1000)<population[i]);

        while(c>1)

        {

          int t = (population[i]%c)/(c/1000);

         cout << (((c>population[i])||(t>99))?"":((t>9)?"0":"00")) << t;

        cout << (((c/=1000)==1)?"":",");

        }

         cout<<endl;

     }

     return 0;

}

 

Step 3

Output 1

...
Enter country name and its population
China 1433783686
India 1366417754
UnitedStates 329064917
Indonesia 2706255 68
Pakistan 216565318
Brazil 211049527
Nigeria 200963599
Bangladesh 163046161
Russia 145872256
Mexico 127575529
Japan 126860301
Ethiopia 112078730
Phillipines 108116615
Egypt 100388073
help_outline

Image Transcriptionclose

Enter country name and its population China 1433783686 India 1366417754 UnitedStates 329064917 Indonesia 2706255 68 Pakistan 216565318 Brazil 211049527 Nigeria 200963599 Bangladesh 163046161 Russia 145872256 Mexico 127575529 Japan 126860301 Ethiopia 112078730 Phillipines 108116615 Egypt 100388073

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: I am having issues with C++ because this code does not work: int main() {int userNum; userNum = 5;co...

A: Explanation:A proper C++ program should include header file “&lt;iostream&gt;”, begins with “#” sign...

question_answer

Q: The print is very small. I apologize in advance for this.  With this homework that has already been ...

A: High Level DesignFrom the limited information that has been provided here, here are the suggestions:...

question_answer

Q: Describe a hypothetical work environment that would be best for CISC and which for RISC. Explain why...

A: Reduced Instruction Set Computer (RISC) is a kind of the processor, or Instruction Set Architecture ...

question_answer

Q: Using the results of the dependency diagram (attached), table of removal and partial dependency and ...

A: Entities Identified : Student , Advisor , Appointment and Department.Entity Student is having STUDEN...

question_answer

Q: In a file called CountMultiples.java, write a program that: Asks the user to enter an integer M. It...

A: Program code #1:

question_answer

Q: the question i am having trouble with is: you are designing an application at work that transmits da...

A: Design the application at work and it must transmit data records to another building within the same...

question_answer

Q: Using the initial dependency diagram (attached), remove all partial dependencies, draw the new depen...

A: According to the given dependency diagram, there is no partial dependency but there are transitive d...

question_answer

Q: Why is it important for you to know about compressed zip files and folders

A: Compressed ZIP files and foldersCompressed ZIP files are the files that pack one or more computer fi...

question_answer

Q: Using the table structures you created (in first attachment called "Table Stucture", remove all tran...

A: Click to see the answer