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

Caveats: 1. Must intialize all variables and each variable on their own line(lik

ID: 3824341 • Letter: C

Question

Caveats:

1.    Must intialize all variables and each variable on their own line(like below).

int i = 0;

int min = 0;

int intCounter = 0;

2.    Use fgets instead of scanf, wherever possible.

3.    Must use functions(function call) and comment it.

4.    Comment in the code where the bubble sort is, so she knows exactly where it is.

5. Must Contencate First and Last name into one variable that will be used in the output.

Please try to limit the use of libraries to these.

#include <math.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <stdbool.h>

Homework #9 Description: Design a program that reads and displays Player zombies kill amount, the player names, and the total average zombie kills a year. In addition display the Player's with the top and bottom kill amount l. Properly document code using the CIS 161 coding name standards 2. Use a 50 integer type array for Zombies kills. 3. Use 50 element char arrays for first and last namcs. (note: 2 dimensional arrays for cach) 4. Initialize all variables properly. 5. Use separate functions is more readable. Make sure functions are properly declared. 6. Do not use Global Variables. 7. Input: Read the first and last name for each Player and their yearly zombie Kill amount, until a blank line is inputted for Player's first name. A blank first name will be the end of the output. 8. The input request should look like the below for each Player i "Please enter Plaver l's First name:" "Plcase enter Playcr l's Last name:" ii. "Please enter Player 1's Zombie Kills per year:" iv "Please enter Player 2's First name:" v "Please cnter Player 2's Last name vi. "Please enter Player 2's Zombie Kills per year:" vii. etc. 9. output: After all of the Player's names and salaries are ved, produce output as below: recci Zombie Kills (pcr year): 80000 per year" a. "Player 1: Thomas Baker b. "Player 2: Shawn Dillard Zombie Kills(per year): 81000 per year c. etc. d. After all Players have been output as above, the following: i. "The average zombie kills is: 85000 per year" ii. "The top player is Thomas Baker at 81000" iii. "The bottom player is Shawn Dillard at 80000" 10. Sort the output ascending by Zombie Kills using the bubble sort algorithm.

Explanation / Answer


#include <stdio.h>

#include <string.h>

#include <stdlib.h>


int readPlayerInfo(char *fname,char *lname,int *noOfkills, int counter) {
   printf(" Please enter Palyer %d First Name : ",counter);

   fgets(fname,50,stdin);
   int len = strlen(fname);
        if(len > 0 && fname[len - 1] == ' '){
           fname[len - 1] = '';
        }

   //scanf("%s",fname);
   if(strcmp(fname, "")== 0 || strcmp(fname, " ")== 0 || strcmp(fname, " ")== 0 ) {
       return -1;
   }
   printf(" Please enter Palyer %d Last Name : ",counter);
   fgets(lname,50,stdin);
   //scanf("%s",lname);
   len = strlen(lname);
            if(len > 0 && lname[len - 1] == ' '){
               lname[len - 1] = '';
            }
   printf(" Please enter Palyer %d Zombie kills per year : ",counter);
   scanf("%d",noOfkills);
   getchar(); //to read new line to avoid problem with fgets
   return 1;
}

int main() {
   char fname[50][50];
   char lname[50][50];
   int zkills[50];
   int counter = 0;
   int topPlayer = -1;
   int botPlayer = -1;

   char fntemp[50];
   char lntemp[50];
   int noOfkills = 0;
   int totalkills = 0;

   printf("To end input,enter a blank space for a player's first name ");
   do {
       strcpy(fname, " ");
       strcpy(lname, " ");
       noOfkills = 0;
       if(readPlayerInfo(fntemp, lntemp,&noOfkills, counter+1) == -1)
           break;
       else {
           //printf(" %s,%s,%d",fntemp,lntemp,noOfkills);
           strcpy(fname[counter], fntemp);
           strcpy(lname[counter], lntemp);
           zkills[counter] = noOfkills;
           totalkills += noOfkills;
           if(counter == 0) {
               topPlayer = 0;
               botPlayer = 0;
           } else {
               if(zkills[topPlayer] < noOfkills)
                   topPlayer = counter;
               if(zkills[botPlayer] > noOfkills)
                   botPlayer = counter;
           }


           counter++;
       }


   } while(1);

   int i =0;
   for(i = 0; i < counter; i++) {
       printf(" Player %d: %s %s Zombile Kills (per year): %d",counter+1, fname[counter], lname[counter], zkills[counter]);
   }

   printf(" Average zombile kills : %d",(totalkills/(counter+1)));
   printf(" Top Player is : %s %s at %d ",fname[topPlayer], lname[topPlayer], zkills[topPlayer]);
   printf(" Bottom Player is : %s %s at %d ",fname[botPlayer], lname[botPlayer], zkills[botPlayer]);
   return 1;
}


-----------output-------------------

DebugChegg-cpp-current.exe
To end input,enter a blank space for a player's first name

Please enter Palyer 1 First Name : fn1

Please enter Palyer 1 Last Name : ln1

Please enter Palyer 1 Zombie kills per year : 100

Please enter Palyer 2 First Name : fn2

Please enter Palyer 2 Last Name : ln2

Please enter Palyer 2 Zombie kills per year : 200

Please enter Palyer 3 First Name : fn4

Please enter Palyer 3 Last Name : ln4

Please enter Palyer 3 Zombie kills per year : 50

Please enter Palyer 4 First Name :

Player 4:   Zombile Kills (per year): 0
Player 4:   Zombile Kills (per year): 0
Player 4:   Zombile Kills (per year): 0
Average zombile kills : 87
Top Player is : fn2 ln2 at 200
Bottom Player is : fn4 ln4 at 50

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote