****THIS IS A C PROGRAMMING QUESTION*** using C language ( printf, scanf,) DO NO
ID: 3605549 • Letter: #
Question
****THIS IS A C PROGRAMMING QUESTION*** using C language ( printf, scanf,) DO NOT USE C++( which is Cout, CINN).
This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team.
(1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int vector and the ratings in another int vector. Output these vectors (i.e., output the roster). (3 pts)
Ex:
(2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing. (2 pt)
Ex:
(3) Implement the "Output roster" menu option. (1 pt)
Ex:
(4) Implement the "Add player" menu option. Prompt the user for a new player's jersey number and rating. Append the values to the two vectors. (1 pt)
Ex:
(5) Implement the "Delete player" menu option. Prompt the user for a player's jersey number. Remove the player from the roster (delete the jersey number and rating). (2 pts)
Ex:
(6) Implement the "Update player rating" menu option. Prompt the user for a player's jersey number. Prompt again for a new rating for the player, and then change that player's rating. (1 pt)
Ex:
(7) Implement the "Output players above a rating" menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value. (2 pts)
Ex:
Explanation / Answer
Given below is the code with output . Please don't forget to rate the answer. Thank you.
#include <stdio.h>
int removeJersey(int num, int jersey[], int rating[], int n);
int updatePlayer(int jer, int rat, int jersey[], int rating[], int n);
void displayAboveRating(int rat, int jersey[], int rating[], int n);
void display(int jersey[], int rating[], int n);
int main()
{
int jersey[100], rating[100];
int n = 0;
int i;
char option= ' ';
char ans[2];
int jer, rat;
//get details of 5 players
for(i = 0; i < 5; i++)
{
printf("Enter player %d's jersey number: ", (i+1));
scanf("%d", &jersey[i]);
printf("Enter players %d's rating: ", (i+1));
scanf("%d", &rating[i]);
n++;
printf(" ");
}
//display
display(jersey, rating, n);
while(1)
{
printf(" MENU ");
printf("a - Add player ");
printf("d - Delete player ");
printf("u - Update player rating ");
printf("r - Output players above a rating ");
printf("o - Output roster ");
printf("q - quit ");
printf("Choose an option: ");
scanf("%s", ans);
option = ans[0];
if(option == 'q' || option == 'Q')
break;
switch(option)
{
case 'a':
case 'A':
printf("Enter a new player's jersey number: ");
scanf("%d", &jersey[n]);
printf("Enter the player's rating: ");
scanf("%d", &rating[n]);
n++;
break;
case 'd':
case 'D':
printf("Enter the jersey number to delete: ");
scanf("%d", &jer);
if(removeJersey(jer, jersey, rating, n))
{
printf("Removed player with jersey number %d ", jer);
n--;
}
else
printf("Player with jersey number %d not found ", jer);
break;
case 'u':
case 'U':
printf("Enter a jersey number: ");
scanf("%d", &jer);
printf("Enter a new rating for player: ");
scanf("%d", &rat);
if(updatePlayer(jer, rat, jersey, rating, n))
printf("Updated rating for player with jersey number %d ", jer);
else
printf("Player with jersey number %d not found ", jer);
break;
case 'r':
case 'R':
printf("Enter a rating: ");
scanf("%d", &rat);
displayAboveRating(rat, jersey, rating, n);
break;
case 'o':
case 'O':
display(jersey, rating, n);
break;
default:
printf("Invalid menu choice! ");
}
}
}
void display(int jersey[], int rating[], int n)
{
int i ;
printf(" ROSTER: ");
for(i = 0; i < n; i++)
printf("Player %d -- Jersey number: %d, Rating: %d ", (i+1), jersey[i], rating[i] );
printf(" ");
}
int removeJersey(int num, int jersey[], int rating[], int n)
{
int i;
int found = 0;
for(i = 0; i < n; i++)
{
if(jersey[i] == num)
{
found = 1;
break;
}
}
if(found)
{
//move all other players 1 position ot left to cover the deleted player. also update rating
for(i = i+1 ; i < n; i++)
{
jersey[i-1] = jersey[i];
rating[i-1] = rating[i];
}
}
return found;
}
int updatePlayer(int jer, int rat, int jersey[], int rating[], int n)
{
int i;
for(i = 0; i < n; i++)
{
if(jersey[i] == jer)
{
rating[i] = rat;
return 1;
}
}
return 0;//when not found
}
void displayAboveRating(int rat, int jersey[], int rating[], int n)
{
int i;
for(i = 0; i < n; i++)
{
if(rating[i] > rat)
printf("Player %d -- Jersey number: %d, Rating: %d ", (i+1), jersey[i], rating[i] );
}
}
===============
Output
Enter player 1's jersey number: 84
Enter players 1's rating: 7
Enter player 2's jersey number: 23
Enter players 2's rating: 4
Enter player 3's jersey number: 4
Enter players 3's rating: 5
Enter player 4's jersey number: 30
Enter players 4's rating: 2
Enter player 5's jersey number: 66
Enter players 5's rating: 9
ROSTER:
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
Player 3 -- Jersey number: 4, Rating: 5
Player 4 -- Jersey number: 30, Rating: 2
Player 5 -- Jersey number: 66, Rating: 9
MENU
a - Add player
d - Delete player
u - Update player rating
r - Output players above a rating
o - Output roster
q - quit
Choose an option: o
ROSTER:
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
Player 3 -- Jersey number: 4, Rating: 5
Player 4 -- Jersey number: 30, Rating: 2
Player 5 -- Jersey number: 66, Rating: 9
MENU
a - Add player
d - Delete player
u - Update player rating
r - Output players above a rating
o - Output roster
q - quit
Choose an option: a
Enter a new player's jersey number: 49
Enter the player's rating: 8
MENU
a - Add player
d - Delete player
u - Update player rating
r - Output players above a rating
o - Output roster
q - quit
Choose an option: o
ROSTER:
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
Player 3 -- Jersey number: 4, Rating: 5
Player 4 -- Jersey number: 30, Rating: 2
Player 5 -- Jersey number: 66, Rating: 9
Player 6 -- Jersey number: 49, Rating: 8
MENU
a - Add player
d - Delete player
u - Update player rating
r - Output players above a rating
o - Output roster
q - quit
Choose an option: d
Enter the jersey number to delete: 4
Removed player with jersey number 4
MENU
a - Add player
d - Delete player
u - Update player rating
r - Output players above a rating
o - Output roster
q - quit
Choose an option: o
ROSTER:
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
Player 3 -- Jersey number: 30, Rating: 2
Player 4 -- Jersey number: 66, Rating: 9
Player 5 -- Jersey number: 49, Rating: 8
MENU
a - Add player
d - Delete player
u - Update player rating
r - Output players above a rating
o - Output roster
q - quit
Choose an option: u
Enter a jersey number: 23
Enter a new rating for player: 6
Updated rating for player with jersey number 23
MENU
a - Add player
d - Delete player
u - Update player rating
r - Output players above a rating
o - Output roster
q - quit
Choose an option: o
ROSTER:
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 6
Player 3 -- Jersey number: 30, Rating: 2
Player 4 -- Jersey number: 66, Rating: 9
Player 5 -- Jersey number: 49, Rating: 8
MENU
a - Add player
d - Delete player
u - Update player rating
r - Output players above a rating
o - Output roster
q - quit
Choose an option: r
Enter a rating: 5
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 6
Player 4 -- Jersey number: 66, Rating: 9
Player 5 -- Jersey number: 49, Rating: 8
MENU
a - Add player
d - Delete player
u - Update player rating
r - Output players above a rating
o - Output roster
q - quit
Choose an option: q
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.