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

Instructions: The following programming problem can be solved by a program that

ID: 3573231 • Letter: I

Question

Instructions: The following programming problem can be solved by a program that uses three basic tasks-Input Data, Process Data, and Output Results. To process the data, it uses loops, arrays, decisions, accumulating, counting, searching and sorting techniques. Use RAPTOR to design a suitable program to solve this problem.

Problem Statement

Assume the Scores array is parallel to the Players array (both arrays are below).

Scores array

Scores[0] = 198

Scores[1] = 486

Scores[2] = 651

Scores[3] = 185

Scores[4] = 216

Scores[5] = 912

Scores[6] = 173

Scores[7] = 319

Scores[8] = 846

Scores[9] = 989

Players Array

Players[0] = "Joe"

Players[1] = "Ann"

Players[2] = "Marty"

Players[3] = "Tim"

Players[4] = "Rosy"

Players[5] = "Jane"

Players[6] = "Bob"

Players[7] = "Lily"

Players[8] = "Granny"

Players[9] = "Liz"

Write a looping program that presents the user with 3 options:

1) Sort Output by Players

2) Sort Output by Scores

3) Exit Program

When the first option is selected, sort the Players array in alphabetical order, keeping the Scores array parallel. Add code that determines the highest and lowest scores in the list. Include code to display each player’s score and name in the sorted order. Below the sorted list display the highest and lowest scores in the list and the name of the player who received that score. Your sort by Player output display should look like this:

Scores Sorted by Player:

486 Ann

173 Bob

846 Granny

912 Jane

198 Joe

319 Lily

989 Liz

651 Marty

216 Rosy

185 Tim

-----------------------------------

989 Highest Score by Liz

173 Lowest Score by Bob

When the second option is selected, sort the Scores array in numerical order, keeping the Players array parallel. Add code that determines the average score of the entire list. Include code to display each player’s score and name in the sorted order. Below the sorted list display the average of all scores in the list. Your sort by Scores output display should look like this:

Players Sorted by Scores:

173 Bob

185 Tim

198 Joe

216 Rosy

319 Lily

486 Ann

651 Marty

846 Granny

912 Jane

989 Liz

---------------------------

498 Average Score

You may use either the Bubble Sort or the Selection Sort algorithms.

You MUST use Modular Programming techniques by using Sub Modules (Sub Charts in RAPTOR) in your program. Your "main" module should not be very large.

You may NOT "hard code" the numbers for highest, lowest and average scores. These must be discovered through algorithms. If the array data is changed, these should automatically be calculated with the new data.

Explanation / Answer

PSEUDOCODE for Player Scores program

BEGIN
   DELARE
       int Scores[]
       string Players[]

   INITIALIZE  
       Scores[0] = 198
       Scores[1] = 486
       Scores[2] = 651
       Scores[3] = 185
       Scores[4] = 216
       Scores[5] = 912
       Scores[6] = 173
       Scores[7] = 319
       Scores[8] = 846
       Scores[9] = 989

       Players[0] = "Joe"
       Players[1] = "Ann"
       Players[2] = "Marty"
       Players[3] = "Tim"
       Players[4] = "Rosy"
       Players[5] = "Jane"
       Players[6] = "Bob"
       Players[7] = "Lily"
       Players[8] = "Granny"
       Players[9] = "Liz"

  
   DISPLAY "1) Sort Output by Players"
   DISPLAY "2) Sort Output by Scores"      
   DISPLAY "3) Exit Program"

   DISPLAY "Enter your option"

   READ   option

   IF option ==1
       THEN
      
  
       for(i=0 ; i<9;i++)
       {      
           for(j=0;j<9;j++)
           {  
                 
               if(strcmp(Players[i],Player[j]>0)
               {
                   temp = Player[i];
                   Player[i]=Player[j];
                   Player[j]=temp;
          
                   temp = Scores[i]
                   Scores[i]=Scores[j]
                   Scores[j]=temp
               }
           }
       }

       //Highest score index
       highest = Scores[0]
       highestScoreIndex=0;
       for(i=0;i<9;i++)
       {
           if(Scores[i]>highest)
           {
               highest=Scores[i];
               highestScoreIndex=i
           }  
       }
      

       lowest = Scores[0]
       lowestScoreOIndex=0
       for(i=0;i<9;i++)
       {
           if(Scores[i]<lowest)
           {
               lowest=Scores[i];
               lowestScoreOIndex=i
           }  
       }
              

       for(i=0;i<9;i++)
       {
           PRINT Scores[i] Player[i]
       }

       PRINT "--------------------------------"
      
  
       PRINT Scores[highestScoreIndex] Highest Score by Player[highestScoreIndex]
       PRINT Scores[lowestScoreOIndex] Lowest Score by Player[lowestScoreOIndex]
  
   ELSE IF opntion ==2
       THEN

       for(i=0 ; i<9;i++)
       {      
           for(j=0;j<9;j++)
           {  
                 
               if(Scores[i],Scores[j]>0)
               {          
                   temp = Scores[i]
                   Scores[i]=Scores[j]
                   Scores[j]=temp

                   temp = Player[i];
                   Player[i]=Player[j];
                   Player[j]=temp;

               }
           }
       }
              
       sum=0
       for(i=0;i<9;i++)
       {
           sum = sum + Scores[i]  
       }
       avg = sum/9.0

       //Print array
       for(i=0;i<9;i++)
       {
           PRINT Scores[i] Player[i]
       }
      
       PRINT "--------------------------------"
       PRINT avg + "Average Score "      
END