Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

17.1 PA#1 Olympic Medal Count Write a c++ program that tracks the medals won by countries participating at the Olympic Games. Your program should use

17.1 PA#1 Olympic Medal Count

Write a c++ program that tracks the medals won by countries participating at the Olympic Games.

Your program should use a structure named Country that keeps the following data for a given country (use the provided member names):

Country Name (name)

Number of gold medals awarded (gold)

Number of silver medals awarded (silver)

Number of bronze medals awarded (bronze)

The program should maintain an array of 8 countries, initialized with the following data.

Country Gold Silver Bronze
Australia 11 14 12
Canada 5 0 1
China 9 14 11
Great Britain 8 4 8
Japan 8 10 10
Netherlands 7 6 7
Russia 6 10 8
USA 10 6 7

When the program runs, it should repeat a loop that performs the following steps:

Print a numbered list of the Countries with column headers and corresponding data for each country on a separate row (see "Sample execution" below for the exact format). The "Total" column records the total number of medals awarded to that country. Use the following code to print the header. Infer the formatting of each row from this code.

 cout << left << setw(3) << "N" << setw(15) << "Country" << right << setw(10) << "Gold" << setw (10) << "Silver" << setw (10) << "Bronze" << setw(10) << "Total" << endl; 

The user is prompted enter the country number or quit (enter 0 to quit)

If the country number is not 0, then the user is prompted to enter the medal type awarded (G for gold, S for silver, and B for bronze). And, if the input is valid, the medal count for the indicated country is incremented appropriately.

The loop repeats until the user enters 0 to quit.

When the user quits the program, the program should display a message indicating the total medals awarded to all countries, and which country has the most Gold medals.

Your program must include these four functions

showResults to display the table of countries, given the array of Countries.

addMedal to update the medal counts: given the array of Countries, a country number, and a medal character, it increments the appropriate medal count. This function should NOT contain a loop, it should NOT do any input/output. The main program loop should be in main. If the country number or medal character is invalid it should do nothing (not output an error message).

totalMedals to determine the total number of medals awarded, given the array of Countries, it should NOT do any input/output. It must return an int value.

mostGoldMedals to determine which country has the most gold medals, given the array of Countries, it should NOT do any input/output. It must return the index of the country with the most gold medals. It must return an int value.

Sample execution:

N Country Gold Silver Bronze Total 1 Australia 11 14 12 37 2 Canada 5 0 1 6 3 China 9 14 11 34 4 Great Britain 8 4 8 20 5 Japan 8 10 10 28 6 Netherlands 7 6 7 20 7 Russia 6 10 8 24 8 USA 10 6 7 23 Enter the country number (0 to quit): 2 Enter the medal type (G,S, or B): S N Country Gold Silver Bronze Total 1 Australia 11 14 12 37 2 Canada 5 1 1 7 3 China 9 14 11 34 4 Great Britain 8 4 8 20 5 Japan 8 10 10 28 6 Netherlands 7 6 7 20 7 Russia 6 10 8 24 8 USA 10 6 7 23 Enter the country number (0 to quit): 0 Total medals Awarded: 193 Country with the most Gold Medals: Australia

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building The Data Warehouse

Authors: W. H. Inmon

4th Edition

0764599445, 978-0764599446

More Books

Students also viewed these Databases questions

Question

List the components of the strategic management process. page 72

Answered: 1 week ago