Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1: One Dimensional Arrays. PLEASE USE C++ language 1. Declare a one dimensional integer array vals . 2. Allocate memory for 20 integers for

Exercise 1: One Dimensional Arrays. PLEASE USE C++ language

1. Declare a one dimensional integer array vals.

2. Allocate memory for 20 integers for the array vals.

3. Write a loop to assign the first 20 even integers to the elements of vals, starting with zero in the first element.

4. Use an initializer list to declare an array numbers with the first 7 odd integers, then write a for loop to print the elements of numbers.

5. Assuming the arrays numbers and vals exist as we have defined them above. Show the result of the following computations:

a. numbers = vals; // and the code you wrote in question 4 is executed.

6. Assuming the arrays numbers and vals exist as we have defined them above. Show the result of the following computations:

a. vals = numbers;

b. The code you wrote in question 4 is executed with vals replacing numbers.

Exercise 2: Two Dimensional Arrays.

7. Use an initializer list to declare a double array nums2 with four rows, each with 7 columns, and initialize the elements of nums2 with values.

8. Write code to print the elements of nums2.

9. Assuming the arrays nums2 and vals exist as we have defined them in question 1 and question 7, what is the result of each of the following computations?

a. vals = nums2;

b. nums2[0] = vals;

c. vals = nums2[2];

10. Assuming the array valsexists as defined in question 2 above. Write code to find the sum of all the elements in vals.

11. Assuming the array nums2exists as defined in question 7 above. Write code to compute and print the average of all elements in nums2.

12. Assuming the array nums2exists as defined in question 7 above. Write code to print the elements in nums2 in row order.

13. Assuming the array nums2exists as defined in question 7 above. Write code to print the elements in nums2 in column order. You may assume the array is a square matric, i.e., the number of rows is equal to the number of columns.

14. What does the following code produce? Correct any errors.

int[][] nums3 = new int[10][];

int count=0;

for(int[] row : nums3) {

for(int col=0; col

row[col] = count++;

}

}

System.out.printf(" ");

for(int[] row : nums3) {

for(int col : row) {

System.out.printf("%2d ", col);

}

System.out.printf(" ");

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions