Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Project 2 - Use a vector to sort countries by area (15 points) Below is a list of the 12 countries in South America, including
Project 2 - Use a vector to sort countries by area (15 points)
Below is a list of the 12 countries in South America, including their population and area:
Name | Population (in 1,000's) | Area (sq. miles) |
---|---|---|
Argentina | 43,132 | 1,074,000 |
Bolivia | 10,520 | 424,200 |
Brazil | 204,519 | 3,286,000 |
Chile | 18,006 | 292,260 |
Columbia | 48,529 | 448,800 |
Ecuador | 16,279 | 109,843 |
Guyana | 747 | 83,000 |
Paraguay | 7,003 | 157,048 |
Peru | 31,153 | 496,200 |
Suriname | 560 | 63,252 |
Uruguay | 3,310 | 68,037 |
Venezuela | 30,620 | 353,831 |
Create a class called Country.
- The properties (variables) of each country will be its name, population, and area.
- Put the definitions of those properties and prototypes of functions in a header file with a guard.
- Put the function definitions in a .cpp file.
- Functions should include a constructor and "getters" for each property of the class.
Then, similar to what you did in project 1:
- Create an empty vector of Country elements (make this a global variable).
- In main, in alphabetic order, create a Country object for each of the countries in South America.
- as each is created insert it into the vector in ascending order based on the country's area.
- consider writing a function which takes a Country object and inserts it into the vector appropriately.
- Once the vector is filled, print a report showing each country.
- At the top of the report, put headings at the top of each column.
- Do not use pop_back. Instead, simply use a loop to access and print the values of each country in the vector, starting with element #0.
- Inside the loop, use the cout object to align columns:
- The name of the country should be left-aligned (padded to the right)
- The population and area should be right-aligned (padded to the left)
- The first part of your report might look like the following:
Country Population Area --------- ---------- ---------- Suriname 560 63252 Uruguay 3310 68037 Guyana 747 83000 Ecuador 16279 109843 . . . . . . . .
- After all countries have been printed, show totals for the population and area columns.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started