Question

In: Computer Science

Write a program in C# for a Cricket match using Jagged Arrays. The name of the...

Write a program in C# for a Cricket match using Jagged Arrays. The name of the project will be on your name. It has the following modules:

  • Create two functions in class Cricket_Match for random numbers generation.
    • The first function generates 1-6 numbers which is known as balls played by each player.
    • The second function generates a 0-6 number which is known as the score produced against each ball by an individual player.
  • In the main show the individual player score.
  • Show the total score.

Note: Random numbers are generated using the following function:

Random rnd = new Random();

int num = rnd.Next(1, 6);//Between 1-6

Output Example

Player/Balls

1

2

3

4

5

6

Total

Player -1

4

0

2

6

Player-2

2

1

1

2

4

0

10

Player-3

1

1

1

2

2

4

11

Player-4

1

2

3

Player-5

3

1

2

6

12

Total Score

42

Solutions

Expert Solution

Below is the solution:

using System;

namespace CricketPlayerScore
{
    class Program
    {

        // Main Method
        public static void Main()
        {
          
            // Declare the Jagged Array of four elements:
            int[][] player_jagged_arr = new int[5][];

            // create the jagged array size
            player_jagged_arr[0] = new int[6];
            player_jagged_arr[1] = new int[6];
            player_jagged_arr[2] = new int[6];
            player_jagged_arr[3] = new int[6];
            player_jagged_arr[4] = new int[6];

            //call the function to generate players
            generatePlayer(player_jagged_arr);
            int sum, sumTotal=0;
            for (int n = 0; n < player_jagged_arr.Length; n++)
            {
                sum = 0;
                // Print the Player number
                System.Console.Write("Player-{0}:\t", n+1);
                for (int k = 0; k < player_jagged_arr[n].Length; k++)
                {
                  
                    int num = generateRandom();
                    player_jagged_arr[n][k] = num; //add the radom number to the jagged array
                    Console.Write("{0}\t", player_jagged_arr[n][k]); //display
                    sum += player_jagged_arr[n][k]; //sum the run
                }
                //total run sum
                sumTotal += sum;
                Console.Write("{0} ", sum);
                Console.WriteLine();
            }
            //display total run sum
            System.Console.WriteLine("Total Score\t{0}",sumTotal);
            Console.ReadLine();
        }

        private static int generateRandom()
        {
            Random rnd = new Random();
            return rnd.Next(1, 6);
        }

        //function genrates player
        private static void generatePlayer(int[][] player_jagged_arr)
        {
            System.Console.Write("Player/Balls");
            for (int n = 0; n <= player_jagged_arr.Length; n++)
            {
                System.Console.Write("\t {0}", n + 1);
            }
            System.Console.Write("\tTotal\n");
        }
    }
}

sample output:


Related Solutions

Write a program of Binary Search in C++ by using function and arrays with the explanation.
Write a program of Binary Search in C++ by using function and arrays with the explanation.
Write a program in c++ using only while and for loops . Use of arrays and...
Write a program in c++ using only while and for loops . Use of arrays and functions is not allowed. Given the first value, generate the next ten terms of the sequence like 1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, … Explaination with code is required.
A local instructor wants you to write a c++ program using arrays to calculate the average...
A local instructor wants you to write a c++ program using arrays to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60 or above...
Write a C++ program using dynamic arrays that allows the user to enter the last names...
Write a C++ program using dynamic arrays that allows the user to enter the last names of the candidates in a local election and the number of votes received by each candidate. The program must ask the user for the number of candidates and then create the appropriate arrays to hold the data. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays,...
Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays, the type of item, its cost, and the number in stock. The program should output this information in the form of a table. The output will look something like below. Also, assume for a finite number of item name of 3 Item Name Cost Number in Stock Widget 25.00 4 ... ... ... Wombet 47.50 9 Prelude to Programming (6th edition)
java programming write a program with arrays to ask the first name, last name, middle initial,...
java programming write a program with arrays to ask the first name, last name, middle initial, IDnumber and 3 test scores of 10 students. calculate the average of the 3 test scores. show the highest class average and the lowest class average. also show the average of the whole class. please use basic codes and arrays with loops the out put should look like this: sample output first name middle initial last name    ID    test score1 test score2...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
This is for c++ Write a program that works with two arrays of the same size...
This is for c++ Write a program that works with two arrays of the same size that are related to each other in some way (or parallel arrays). Your two arrays must be of different data types. For example, one array can hold values that are used in a formula that produces the contents of the second array. Some examples might be:  from a previous program, populations and the associated flowrates for those populations (an int array of populations...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT