Question

PLEASE CODE EVERYTHING IN C++ Quick Thinking: Arrays Objective: Test your knowledge in providing efficient solutions...

PLEASE CODE EVERYTHING IN C++

Quick Thinking: Arrays

Objective: Test your knowledge in providing efficient solutions for operations on arrays. What you can use only:

  • Loops
  • These variables only
    • const int SIZE = 4;
    • int variable = 0, master array [SIZE][SIZE];
    • double average = 0.0, parallel array [SIZE];
  • One conditional statement per problem if needed
  • Note: the conditional statement cannot contain an “else” or “else if’ Provide solutions to the following problem. Absolutely no hard coding can be used.

----------------------------------------------------------------------------------------------------------------------------------------------------------

1) Populate the array

using loops and a variable on

an even/odd pattern by row

Master Array

0 2 4 6
7 9 11 13
14 16 18 20
21 23 25 27

2) Compute the average value of each column in the master array and store the values in a parallel array.

3) Compute the average of the entire array

0 2 4 6
7 9 11 13
14 16 18 20
21 23 25 27

4) Compute the average of the corners.

0 2 4 6
7 9 11 13
14 16 18 20
21 23 25 27

5) Compute the average of the left-to-right diagonal

0 2 4 6
7 9 11 13
14 16 18 20
21 23 25

27

6) Compute the average of inside only

0 2 4 6
7 9 11 13
14 16 18 20
21 23 25 27

7) Compute the average of the right-to-left diagonal

0 2 4 6
7 9 11 13
14 16 18 20
21 23 25 27

8) Compute the average value of each row in the master array and store the values in a parallel array.

9) Compute the average of the boundaries

0 2 4 6
7 9 11 13
14 16 18 20
21 23 25 27

PLEASE CODE EVERYTHING IN C++

Homework Answers

Answer #1

Note: Solved Questions 1 to 7.

#include<stdio.h>
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    const int SIZE = 4;
    int variable = 0;
    int master_array[SIZE][SIZE];
    double average = 0.0;
    double parallel_array[SIZE];
// populate the master array
    for (int row = 0; row < SIZE; row ++){
      for (int col = 0 ; col < SIZE;col++ ){
        master_array[row][col] = 2*col + 7*row;  //main pattern
      }
    }
    // printing the array for checking (commment out if not required)
    for (int row = 0; row < SIZE; row ++){
      for (int col = 0 ; col < SIZE;col ++ ){
        cout << master_array[row][col]<<" ";
      }
      cout << "\n";
    }

//calculating the average for each column
  for (int col = 0; col < SIZE;col++){
    average = 0; // resetting the average variable to 0
    for (int row = 0; row < SIZE; row ++){
      average += master_array[row][col];
    }
    parallel_array[col] = average/SIZE;  // saving the value of each column's average
  }

  cout <<"The value of the parallel array : "<<"\n";
  for (int i = 0; i < SIZE; i ++){
    cout << parallel_array[i] << " ";
  }


//computing average of the whole array
  average = 0;
  for (int i = 0; i < SIZE; i++){
    for (int j = 0 ; j < SIZE; j++){
      average += master_array[i][j];
    }
  }
  average = average/(SIZE*SIZE);
  // printing the result
  cout <<"\n";
  cout << "The average of the whole array is: ";
  cout << average << "\n";

//computing the average of the corners
  average = 0;
  for (int i = 0 ; i < SIZE; i++){
    for (int j = 0; j < SIZE; j++){
      if ((i == 0 && j == 0)||(i == 0 && j == SIZE-1)||(i == SIZE-1 && j == 0 )||(i == SIZE-1 && j == SIZE-1)){
        average += master_array[i][j];
        //cout << master_array[i][j] << " "
      }
    }
  }
  //printing the average of the corners
  cout << "The average of the corners: " << average/4 << "\n ";

//computing the average of the left to right diagonal
  average = 0;
  for (int i = 0; i < SIZE; i++){
    for (int j = 0; j < SIZE; j++){
      if (i==j){
        average += master_array[i][j];
      }
    }
  }
average = average/SIZE;
cout << "The average of the left to right diagonal "<< " "<<average;

//computing the average of the inside only
average = 0;
for (int i = 0; i < SIZE; i++){
  for (int j = 0; j < SIZE; j++){
    if ((i>0 && i < SIZE-1)&&(j>0 && j < SIZE-1)){
      average += master_array[i][j];
      // cout << master_array[i][j];
    }
  }
}
  cout <<"\n";
cout << "The average of the insides only : " << average/((SIZE-2)*(SIZE-2));

//computing the average of the right-to-left diagonal
average = 0;
for (int i = 0; i < SIZE; i++){
  for (int j = 0; j < SIZE; j++){
    if (i+j == SIZE-1){
      average += master_array[i][j];
    }
  }
}
cout <<" \n";
cout <<"The average of the right to left diagonal is: "<<average/SIZE<<"\n";

 return 0;
}

Code Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
6. Using the class data (see Blackboard file - "Class Survey Data - PSS-10 and GAS")...
6. Using the class data (see Blackboard file - "Class Survey Data - PSS-10 and GAS") calculate the correlation between the GAS – Goal disengagement and the GAS – Goal reengagement scores. Write the results in a statistical statement. 7. Using the class data calculate the correlation between the GAS – Goal disengagement and the PSS-10 scores. Write the results in a statistical statement. 8. Using the class data calculate the correlation between the GAS – Goal reengagement scores and...
Hudson Marine has been an authorized dealer for C&D marine radios for the past seven years....
Hudson Marine has been an authorized dealer for C&D marine radios for the past seven years. Suppose the quarterly sales values for the seven years of historical data are as follows. Year Quarter 1 Quarter 2 Quarter 3 Quarter 4 Total Yearly Sales 1 7 13 9 4 33 2 11 20 16 6 53 3 12 25 25 11 73 4 18 28 26 16 88 5 23 35 27 21 106 6 24 37 31 18 110 7...
Assuming that the population standard deviation is unknown, calculate the 95% confidence interval of the population...
Assuming that the population standard deviation is unknown, calculate the 95% confidence interval of the population mean. The following is the data. Calculating Process should be shown by Excel (Formulas). What formulas in statistics are used? 7 21 23 24 18 16 2 19 11 6 3 13 17 9 5 12 13 17 4 14 15 25 12 24 22 14 14 20 15 11 26 17 21 11 4 13 16 14 13 14 25 23 9 15...
USING C++ The purpose of this assignment is the use of 2-dimensional arrays, reading and writing...
USING C++ The purpose of this assignment is the use of 2-dimensional arrays, reading and writing text files, writing functions, and program planning and development. You will read a data file and store all of the input data in a two dimensional array. You will perform calculations on the data and store the results in the 2 dimensional array. You will sort the array and print the results in a report. Instructions You will read in the same input file...
I need a breakdown to perform in excel for numbers 7,8,9. I am unsure of how...
I need a breakdown to perform in excel for numbers 7,8,9. I am unsure of how I calculate the times. heres the data set and the questions. Calculate the probability that a flight will depart early or on time. Calculate the probability that a flight will arrive late. Calculate the probability that a flight departs late or arrives early. DEP_Delay ARR_Delay -4 0 -3 -3 0 -5 -7 -1 8 3 -1 -5 3 8 11 6 -6 0 -5...
____________________________________________ The results of a sample of 372 subscribers to Wired magazine shows the time spent...
____________________________________________ The results of a sample of 372 subscribers to Wired magazine shows the time spent using the Internet during the week. Previous surveys have revealed that the population standard deviation is 10.95 hours. The sample data can be found in the Excel test data file. What is the probability that another sample of 372 subscribers spends less than 19.00 hours per week using the Internet? ____________________________________________ Develop a 95% confidence interval for the population mean ____________________________________________ If the editors...
Part A. In the past it has been found that the arrival time have a population...
Part A. In the past it has been found that the arrival time have a population mean value of μ = 13 and a population standard deviation of σ = 6.26. Using the given data, test whether this mean has changed. Use the critical value approach to test the hypothesis. The significance level alpha is set at 0.05 . The original data of time taken is given below. Show the process by using excel (Formulas). Part B. Test the hypothesis...
The results of a sample of 372 subscribers toWiredmagazine shows the time spent using the Internet...
The results of a sample of 372 subscribers toWiredmagazine shows the time spent using the Internet during the week. Previous surveys have revealed that the population standard deviation is 10.95 hours. The sample data can be found in the Excel test data file. What is the probability that another sample of 372 subscribers spends less than 19.00 hours per week using the Internet? Develop a 95% confidence interval for the population mean If the editors of Wiredwanted to have the...
City Code % Under 21 # of Fatals 1 16 3.822 2 7 0 3 5...
City Code % Under 21 # of Fatals 1 16 3.822 2 7 0 3 5 0.46 4 10 2.033 5 14 2.282 6 10 0.621 7 12 1.511 8 12 1.824 9 13 1.209 10 11 2.034 11 8 1.321 12 14 2.468 13 14 2.455 14 18 3.787 15 16 3.508 16 10 1.113 17 7 1.144 18 15 3.084 19 18 4.16 20 16 3.688 21 8 0.782 22 9 1.307 23 14 2.016 24 13 3.542...
Convert the Ch01_SalesSummary file to a database table in MS Access (steps: drop unnecessary titles row...
Convert the Ch01_SalesSummary file to a database table in MS Access (steps: drop unnecessary titles row and import data into Access using “External Data” Excel tab in Access). Sort the new Access database table in ascending order by any one column. Table Waitstaff Member# #Guests Hour Food Beverage Total 29 WH 0 1 8 0 4 5 28 MM 101 4 8 0 4 5 28 MM 0 2 8 5 8 15 5 LR 0 2 8 5 9...