Write a complete C++ program that does the following:1. Create a 2-dimensional array with 8 rows and 6 columns. Fill the array withrandom 3 digit integers.2. Create a function called findLargestSum which returns the sum of the row with thelargest sum.ex. int array[3][3] = {{3, 6, 8}, // sum = 17{2, 4, 5}, // sum = 11{1, 0, 9}}; // sum = 10If the findLargestSum function was called using this array, it would return 17.Note that the number of columns is required when passing a 2d array to a functionint findLargestSum(int array[][6], int rows, int columns);

Question
Asked Jun 4, 2019
2 views

Write a complete C++ program that does the following:
1. Create a 2-dimensional array with 8 rows and 6 columns. Fill the array with
random 3 digit integers.
2. Create a function called findLargestSum which returns the sum of the row with the
largest sum.
ex. int array[3][3] = {{3, 6, 8}, // sum = 17
{2, 4, 5}, // sum = 11
{1, 0, 9}}; // sum = 10
If the findLargestSum function was called using this array, it would return 17.
Note that the number of columns is required when passing a 2d array to a function
int findLargestSum(int array[][6], int rows, int columns);

check_circle

Expert Answer

Step 1

1)

Program plan:

  • Declare the variables “rows” and “cols” as integer
  • Assign “rows” to “8” and “cols” to “6”
  • Initialize the random seed
  • Loop to iterate the rows
  • Loop to iterate the columns
    • Generate the 3 digits random integer.

 

Step 2

Code:

//Declare and initialize the rows and columns
  const int rows = 8;
  const int cols = 6;
  int arr[rows][cols];

  //Initialize random seed:
  srand(time(NULL));
  
  //Loop to iterate the rows
  for (int i = 0; i < rows; i++)
  {
    //Loop to iterate the column
    for (int j = 0; j < cols; j++)
    {
      //generating 3 dight random integer
      arr[i][j] = 100 + (rand() % 900);
    }
  }
Step 3

2)

Program plan:

 

  • Include required packages
  • Definition of function “findLargestSum(int arr[][6], int rows, int cols)”
    • Find the largest sum of row values.
  • Definition of function “display()”.
    • Print the values.
  • Declare the variables “rows” and “cols” as integer
  • Assign “rows” to “8” and “cols” to “...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Construct npda that accept the following languages on Σ = {a, b, c}: L = {wcwR : w ∈ {a, b}∗}.

A: Non-deterministic pushdown automaton (NPDA):Given: L = {wcwR : w ∈ {a, b}∗}To construct NPDA, when “...

question_answer

Q: Hello! I am trying to write a program in Pynthon. Need help. Requirements: Write a .py file like Kev...

A: Program Plan:Import required packagesPrompt the path and the number of characters to delete from the...

question_answer

Q: When disposing disks or hard drives, it is recommended to format them (writing binary zeros) at leas...

A: Reason of formatting the disks or hard drives is as follows:

question_answer

Q: Is the following distributive law valid or invalid? Prove your answer. x XOR (y + z) = (x XOR y) + ...

A: Answer:Here, the truth table is used to get the answer for each side of the question.First take LHS,

question_answer

Q: How to implement a pluggable Adapter design pattern in Java?

A: Let’s say we have a client class called Client.java which calls method1( ) of an existing library cl...

question_answer

Q: I need to write the subnet mask, subnet address, broadcast address and valid host range for 192.168....

A: The given IP address is 192.168.100.25 with subnet mask as/30. To calculate subnet mask, subnet addr...

question_answer

Q: What is the most important thing to help with introduction to computers?

A: The most important thing in introduction to computers are,Hardware andSoftware

question_answer

Q: A common problem in health informatics is to read a message from another healthcare organization and...

A: In order to solve the problem we would follow these steps:Break the entire string into tokens separa...

question_answer

Q: I need help with understanding how to do the SQL code for the following question (attached is the CS...

A: As the table name is not shown in the picture, we are assuming the table name as Product. There are ...