Question

In: Computer Science

#C language array must store at least 50 inputs Game Scores Assignment Outcomes: Demonstrate the ability...

#C language

array must store at least 50 inputs

Game Scores Assignment

Outcomes:

  • Demonstrate the ability to create a menu driven program.
  • Demonstrate the ability to create and use a 2D array on the stack.
  • Demonstrate the use of functions.
  • Demonstrate good programming style.

Program Specifications:

Your program will read in "game scores" from the user. Each score consists of a score for YOUR team and a score for the OTHER team. You don't need names or dates for the games. Just the scores. You'll use a 2D array to store the scores. The following menu options all need to be implemented:

***********************************************

**                 MAIN   MENU                     **

***********************************************

A) Enter game result

B) Current Record (# of wins and # of losses and # of ties)

C) Display ALL results from all games WON

D) Display ALL results ordered by opponent score from low to high.

E) Quit

Create a menu similar to the example above. The user will enter a single game result at a time.  All menu options should be implemented within programmer-defined function. Functions should be used as much as possible.

Submission Requirements:

Requirements will be same as the first assignment which will be the same for all future assignments.

YOU MAY NOT

  • Use global variables, in this or any program ever.
  • Use goto statement(s), in this or any program ever.

Solutions

Expert Solution

CODE:

#include<stdio.h>
void current_record(int game_scores[50][2],int index);
void game_won(int game_scores[50][2],int index);
void opplow_high(int game_scores[50][2],int index);
void display_all(int game_scores[50][2],int index);
void main()
{
int game_scores[50][2];
int a,index=0,quit=0;
while(1){
printf("\n1) Enter game result");
printf("\n2) Current Record (# of wins and # of losses and # of ties)");
printf("\n3) Display ALL results from all games WON");
printf("\n4) Display ALL results ordered by opponent score from low to high");
printf("\n5) Quit");
printf("\nEnter your option:");
scanf("%d",&a);
switch(a){
case 1:
printf("\nEnter your and other team score:");
scanf("%d%d",&game_scores[index][0],&game_scores[index][1]);
index++;
break;
case 2:
current_record(game_scores,index);
break;
case 3:
game_won(game_scores,index);
break;
case 4:
opplow_high(game_scores,index);
display_all(game_scores,index);
break;
case 5:
quit=1;
break;
default:
printf("\nEnter proper input...\n");
}
if(quit==1)
break;
}
}
void current_record(int game_scores[50][2],int index)
{
int i,w=0,l=0,t=0;
for(i=0;i<index;i++){
if(game_scores[i][0]==game_scores[i][1])
t++;
else if(game_scores[i][0]>game_scores[i][1])
w++;
else
l++;
}
printf("\nwin = %d\nlose = %d\ntie = %d",w,l,t);
}
void game_won(int game_scores[50][2],int index)
{
int i;
printf("\nwinning results:\n");
for(i=0;i<index;i++){
if(game_scores[i][0]>game_scores[i][1])
printf("\nyour score=%d opponent score=%d",game_scores[i][0],game_scores[i][1]);
}
}
void opplow_high(int game_scores[50][2],int index)
{
int i,j,temp[2];
for(i=0;i<index;i++){
for(j=i+1;j<index;j++){
if(game_scores[i][1]>game_scores[j][1]){
temp[0]=game_scores[j][0];
temp[1]=game_scores[j][1];
game_scores[j][0]=game_scores[i][0];
game_scores[j][1]=game_scores[i][1];
game_scores[i][0]=temp[0];
game_scores[i][1]=temp[1];
}
}
}
}
void display_all(int game_scores[50][2],int index)
{
int i,j;
for(i=0;i<index;i++){
printf("\nyour score=%d opponent score=%d",game_scores[i][0],game_scores[i][1]);
}
}

MENU DRIVEN PROGRAM:

For a given menu driven task ,we have multiple tasks to be solve .So simply we use switch class to solve the perticular task.For iterate the tasks simply we use while loop outside the switch class for multiple iterations.Each of the menu item is solved in each of the switch case.

2D ARRAY:

we can simply declare a 2 dimensional array in c like,

int array[20][20]; //we have to mention the size of the array.

if we want to initialize the array simply initalizing by using array indices .ex:array[1][1]=5;

If we want to access the array elements then called it by using array indices ex:array[2][2]

USE OF FUNCTIONS:

Functions to used to perform the same task multiple times in diffent situations.If any task which is known to execute multiple times then that code must write in a function.if we want execute that perticular code then we simply call the function.

current_record(int game_scores[50][2],int index) :display the number of wins,loses,ties.
void game_won(int game_scores[50][2],int index) :display scores which you won.
void opplow_high(int game_scores[50][2],int index) :sort the scored based on opponent score.
void display_all(int game_scores[50][2],int index) :display all the scores.

GOOD PROGRAMMING STYLE:

A good programmer must build an Algorithm before writing the code.Algorithm means a step by step process to complete a perticular task.

For Example:For a menu driven program,first programmer read the required inputs like 2d array .next Write the functions for each menu Item task .Those Functions calls put in each of switch case.For multiple iterations use while loop.


Related Solutions

C Programming Game Scores Assignment Outcome: Student will demonstrate the ability to design a menu driven...
C Programming Game Scores Assignment Outcome: Student will demonstrate the ability to design a menu driven program. Student will demonstrate the ability to create and use a 2D array on the stack. Student will demonstrate the use of functions. Student will demonstrate good programming style. Program Specifications: *********************************************** ** MAIN MENU ** *********************************************** A) Enter game results B) Current Record (# of wins and # of losses and # of ties) C) Display ALL results from all games WON D)...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to create and use menus Demonstrate the ability to create and use an array of structs Demonstrate the ability to generate and use random numbers Program Specifications: Assume that gambling Greg often goes to the Dog Racing Track. Greg loves to bet on the puppies. In each race Greg will place a wager and pick a dog. The dog information will be stored in a...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate strings. Demonstrate the ability to write well written code. Program Specifications: DESIGN and IMPLEMENT a short program that will: Allow the user to enter a string with up to 100 letters. Display the user-entered string: Forward Backward Vertical As a triangle made from the letters of the string Display the number of letters in the string. Once everything above is displayed, the program will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
In C language Assignment Extend the Game of Life assignment to load its configuration from a...
In C language Assignment Extend the Game of Life assignment to load its configuration from a file. Functional Requirements MUST load the initial state from text file MUST load the number of rounds to play from text file COULD load the grid size from the file Nonfunctional Requirements MUST compile without warnings and error Source code: life.h /* * life.h * *  Created on: Sep 20, 2020 *      Author: Joker Zhong */ #ifndef LIFE_H_ #define LIFE_H_ #define XSIZE   15 #define YSIZE   15 #define DEFAULTROUNDS...
Assignment (C language, not C ++) Start a new project to store grade information for 5...
Assignment (C language, not C ++) Start a new project to store grade information for 5 students using structures. Declare a structure called student_t that contains : First name Last name Student ID Number Percentage grade Letter grade Create the following functions: getStudentInfo(void)- Declares a single student object - Uses printf()/scanf() to get keyboard input for Name, SID, and Percentage (not Letter). - Returns a single student structure calcStudentGrade(student_t *st_ptr)- Takes the pointer to a student (to avoid making a...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
Using the C Programming language, write a program that sums an array of 50 elements. Next,...
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling. Marking:- Optimize the code for an array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT