Question

In: Computer Science

In the same file, complete the following exercises in the author’s pseudocode as presented in the...

In the same file, complete the following exercises in the author’s pseudocode as presented in the
text book and material on Blackboard in this chapter, and following all requirements for good
program design that were shown in Chapter 2 and all examples since then.

At the Summer Olympic Games every four years, for historical reasons, athletes represent
National Olympic Committees (NOCs) rather than strictly countries. For the sake of convenience
in our program, let us refer to them simply as “nations”. As of the 2016 Rio Olympics, then,
there were 206 nations eligible to participate in the Olympics. Write a program that could be
used to represent the medal table for the next Olympics that will be held in Tokyo in 2020. Since
we do not know how many nations will actually participate, our program will have to plan on
there being a maximum of 225 nations (in case some more NOCs are recognized before the 2020
Olympics), but must adapt to fewer nations actually being present. So, write a program that

1. Allows a user to enter
a. The names of the nations that are participating
b. The number of gold medals that nation has won
c. The number of silver medals it has won
d. The number of bronze medals it has won
e. “ZZZ” as the nation’s name to indicate that they have finished entering input

2. Outputs a list of sentences that describe each nation’s performance, e.g., for the 2016
Olympics, to describe the performance of the United States, this program would have
output “United States won 46 gold, 37 silver, and 38 bronze
medals, for a total of 121 medals” . Below this list, the program must
output the total number of gold medals awarded, silver medals awarded and bronze
medals awarded, and total of all medals awarded.

3. Scans for and outputs
a. The names of the nations with the most and least gold medals, along with their
gold medal counts, e.g., “United States won the most gold
medals: 46”
b. Similarly, the names of the nations with the most and least silver and bronze
medals respectively

4. Allows the user to enter the name of a nation that they want to search for, and if it finds
that nation, outputs a sentence in the format shown in #2 above.

All of the above must be done by applying the concepts and algorithms shown in Chapter 6, both
in the text book and in the material provided on Blackboard, and building on what we have
learned in all the chapters before this one.

The only data that this program stores is the names of the nations, and the matching counts of
gold, silver and bronze medals. All calculations and scanning for highest and lowest, etc., must
be done by the program after the user has entered the sentinel to indicate the end of their input.
All output sentences described above must be generated when they are required.

Book this is from is "Programming Logic and Design 8th Edition" by: Joyce Farrell. Must be written in pseudocode that resembles that in the book.

this is what I have so far. It probably isn't right, but it will at least give you some structure to follow. Any help is appreciated.

Start
   Declarations
       string EXIT = ZZZ
       NATION_CAPACITY = 225
       string NATION_NAME[NATION_CAPACITY]
       num goldMedals
       num silverMedals
       num bronzeMedals
       num totalMedals
       num count
       num nextNation
       num mostGold
       num leastGold
       num mostSilver
       num leastSilver
       num mostBronze
       num leastBronze

   output "Welcome to our Medal Tracker Program."
   output "This program will allow the user to enter the name of nations participating in the olympics, allow
       the user to enter the number of gold, silver, and bronze medals that nation has won."

   output "Please enter the name of the first nation (type ", ZZZ, " to stop): "
   input nextNation

   count = 0
  
   while nextNation <> ZZZ AND count < NATION_CAPACITY
       NATION_NAME[NATION_CAPACITY] = nextNation

       output "Please enter the amount of gold medals this nation has won: "
       input goldMedals[count]

       output "Please enter the amount of silver medals this nation has won: "
       input silverMedals[count]

       output "Please enter the amount of bronze medals this nation has won: "
       input bronzeMedals[count]

       count = count + 1

       output "Please enter the next nation or ", ZZZ, " to stop: "
       input nextCustomerID
   endwhile

   output "You entered data for ", count, " nations."

   totalMedals = goldMedals + silverMedals + bronzeMedals

   output "The nation ", nextNation, " won ", goldMedals, " gold medals, ", silverMedals, " silver medals, and ", bronzeMedals, "
       bronze medals, for a total of ", totalMedals, " medals.

   mostGold =

Solutions

Expert Solution

The logic of the program is as follows:

Start

   Declarations

    string EXIT = ZZZ

    NATION_CAPACITY = 225

    string NATION_NAME[NATION_CAPACITY]

    num g #gold

    num s #silver

    num b #bronze

    num totalMedals

    num count

    num nextNation

    num mostGold

    num leastGold

    num mostSilver

    num leastSilver

    num mostBronze

    num leastBronze

   output "Welcome to our Medal Tracker Program."

   output "This program will allow the user to enter the name of nations and enter the number of gold, silver, and bronze medals that nation has won."

   output "Please enter the name of the nation (type ", ZZZ, " to stop): "

   input nextNation

  

   count = 0   

/* Function add_name adds the given country to the struct 'country' and sets the amount of every medal to 0. */

struct country *add_name(struct country *array, int len, const char *c_name)

if (len == 0)

array = malloc(sizeof(struct country)); /* When the array is created, the memory allocated for the array is the size of one 'country' struct. */

else

array = realloc(array, (len + 1) * sizeof(struct country)); /* More memory is allocated for the array. */

}

strcpy(array[len].name, c_name);

array[len].name[21] = '\0';

array[len].g = 0;

array[len].s = 0;

array[len].b = 0;

return array;

}

/* Function add_medals adds medals based on the given parameters. */

/* This function also checks if the given country has already been added to the struct 'country' and tells the users if it hasn't. */

int add_medals(struct country *array, int len, const char *c_name, signed int g, signed int s, signed int b)

{

int i = 0;

while (i < len) {

if (strcmp(array[i].name, c_name) == 0) {

array[i].g += g;

if (array[i].g < 0) { /* Here we check if the amount of the medals is less than zero and if this is the case, we set the amount of the medals to zero */

array[i].g = 0;

}

array[i].s += s;

if (array[i].s < 0) {

array[i].s = 0;

}

array[i].b += b;

if (array[i].b < 0) {

array[i].b = 0;

}

i = -1;

break;

}

i++;

}


/* Function print_medals orders the countries based on their medals and prints the countries and their medals in this order. */

int print_medals(struct country *array, int len)

{

int i;

int a;

struct country temp;

struct country c;

int d;

int flag = 0;

for (i = 0; i < len - 1; i++) {

c = array[i];

for (a = len - 1; a > i; a--) {

if (array[a].g > c.g) {

c = array[a];

d = a;

flag = 1;

}

else if (array[a].g == c.g && array[a].s > c.s) {

c = array[a];

d = a;

flag = 1;

}

else if (array[a].g == c.g && array[a].s == c.s && array[a].b > c.b) {

c = array[a];

d = a;

flag = 1;

}

else if (array[a].g == c.g && array[a].s == c.s && array[a].b == c.b && strcmp(array[a].name, c.name) < 0) {

c = array[a];

d = a;

flag = 1;

}

}

if (flag == 1) {

temp = array[i];

array[i] = c;

array[d] = temp;

}

flag = 0;

}

for (i = 0; i < len; i++) {

printf("%s, %d, %d, %d\n", array[i].name, array[i].g, array[i].s, array[i].b);

}

return 0;

}


Related Solutions

Exercises Code of Conduct Exercises Instructions:  Answer the following in complete sentences using the AICPA's revised Code...
Exercises Code of Conduct Exercises Instructions:  Answer the following in complete sentences using the AICPA's revised Code of Conduct, providing the ET references for each of your responses. For questions with multiple parts, include multiple ET references as appropriate. What are the three broad categories of safeguards identified in Part 1 of the Code, in the Conceptual Framework for members in public practice? Which category of safeguard cannot be relied upon, by itself, to reduce threats to an acceptable level?
Chapter 6 Debugging Exercises - Problem 1 The programmer intends for this pseudocode to display three...
Chapter 6 Debugging Exercises - Problem 1 The programmer intends for this pseudocode to display three random numbers in the range of 1 through 7. According to the way we've been generating random numbers in the book; however, there appears to be an error. Assume that the random() function is a built-in library function. Correct the pseudocode so that the program works as it should (This has 1 error and is easy to spot) //This program displays 3 random numbers...
Database Management System Complete the following exercises in Connolly & Begg: 4.8 The following tables from...
Database Management System Complete the following exercises in Connolly & Begg: 4.8 The following tables from part of a database held in a relational DBMS Hotel (hotelNo, hotelName, city) Room (roomNo, hotelNo, type, price) Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo) Guest (guestNo, guestName, guestAddress) a) Identify the foreign keys in this schema. b) Explain how the entity integrity rule and the referential integrity rule apply to these relations. 5.8 Describe the relations that would be produced by the following relational...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
In each of the following exercises, complete the ten-step hypothesis testing procedure. State the assumptions that...
In each of the following exercises, complete the ten-step hypothesis testing procedure. State the assumptions that are necessary for your procedure to be valid. For each exercise, as appropriate, explain why you chose a one-sided test or a two-sided test. Discuss how you think researchers or clinicians might use the results of your hypothesis test. What clinical or research decisions or actions do you think would be appropriate in light of the results of your test? The purpose of a...
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ......
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ... n - 1]) if (n = 2) and A[0] > A[1] swap A[0] and A[1] else if n > 2 m = ceiling(2n/3) STOOGESORT(A[0 ... m - 1]) STOOGESORT(A[n - m ... n - 1]) STOOGESORT(A[0 ... m - 1])
Please complete the following Professional Development exercises. Read the following Ethics case. Discuss and analyze using...
Please complete the following Professional Development exercises. Read the following Ethics case. Discuss and analyze using the ETHICAL model Paul is a 12 year old male diabetic. He maintains his personal digital assistant (PDA), hand-held device, that interfaces with his glucometer and provides information based on inputted data from him and his parents. This information is transmitted to his MD/hospital, school nurse, case manager (CM), and to the parents’ home computer. All in an attempt to better control his diabetes....
Please complete the following Professional Development exercises. Read the following Ethics case. Discuss and analyze using...
Please complete the following Professional Development exercises. Read the following Ethics case. Discuss and analyze using the ETHICAL model Paul is a 12 year old male diabetic. He maintains his personal digital assistant (PDA), hand-held device, that interfaces with his glucometer and provides information based on inputted data from him and his parents. This information is transmitted to his MD/hospital, school nurse, case manager (CM), and to the parents’ home computer. All in an attempt to better control his diabetes....
What is the functional consequence of the following (Information presented is complete) A.) Mutation that inhibits...
What is the functional consequence of the following (Information presented is complete) A.) Mutation that inhibits the expression of all t-SNARES in a cell B.) Mutation that makes all ER targetinf signal sewuences C-terminal instead of N-termina C.) Mutation of RTKs that inactivates the kinase domain D.) What is the consequence of G that binds a non-hydrolyzable GTP? E.) What is the consequence if uniquitin lysines are all mutated to tyrosines?
Complete the following exercises using C programming language. Take screenshots of the code and its output...
Complete the following exercises using C programming language. Take screenshots of the code and its output where specified and paste them into in a well-labeled Word document for submission. Scenario Assume you are the CIO of an organization with three different IT department locations with separate costs. You want a program to perform simple IT expenditure calculations. Your IT expenditure target is $35,000 per site. Site expenditures: Site 1 – $35,000. Site 2 – $37,500. Site 3 – $42,500. Exercise...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT