Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Determine whether the following array declarations are valid. If a declaratio

ID: 3836041 • Letter: 5

Question

5. Determine whether the following array declarations are valid. If a declaration is valid, determine the size of the array.
a. int list[] = {18, 13, 14, 16};
b. int x[10] = {1, 7, 5, 3, 2, 8};
c. double y[4] = {2.0, 5.0, 8.0, 11.0, 14.0};
d. double lengths[] = {8.2, 3.9, 6.4, 5.7, 7.3};
e. int list[7] = {12, 13, , 14, 16, , 8};

6. What is the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int beta[7] = {3, 5};
for (int i = 2; i < 7; i++)
{
beta[i] = 3 * i + 2;
beta[i - 1] = beta[i - 1] + beta[i];
beta[i - 2] = beta[i - 2] + beta [i - 1];
}
for (int i = 0; i < 7; i++)
cout << beta[i] << " ";
cout << endl;
return 0;
}

7. Is each of the following a valid or invalid array definition? (If a definition is invalid, explain why.)
a) int numbers[10] = {0, 0, 1, 0, 0, 1, 0, 0, 1, 1};
b) int matrix[5] = {1, 2, 3, 4, 5, 6, 7};
c) double radii[10] = {3.2, 4.7};
d) int table[7] = {2, , , 27, , 45, 39};
e) char codes[] = {'A', 'X', '1', '2', 's'};
f) int blanks[];
g) char name[6] = "Joanne";

8. Given the following array definition:
int values[] = {2, 6, 10, 14};
What does each of the following display?
a) cout << values[2];
b) cout << ++values[0];
c) cout << values[1]++;
d) x = 2;
cout << values[++x];

9. Fill in the table below so it shows the contents of the following array:
int table[3][3] = {{2, 3}, {7, 9, 2}, {1}};

10. Consider the following array definition:
int values[5] = { 4, 7, 6, 8, 2 };
What does each of the following statements display?
cout << values[4] << endl; __________
cout << (values[2] + values[3]) << endl; __________
cout << ++values[1] << endl; __________

Explanation / Answer

5. Determine whether the following array declarations are valid. If a declaration is valid, determine the size of the array.
a. int list[] = {18, 13, 14, 16};
Answer: is valid
the size of the array is 4

b. int x[10] = {1, 7, 5, 3, 2, 8};
Answer: is valid
the size of the array is 10

c. double y[4] = {2.0, 5.0, 8.0, 11.0, 14.0};
Answer: Invalid. Array has more elements than the size

d. double lengths[] = {8.2, 3.9, 6.4, 5.7, 7.3};
Answer: is valid
the size of the array is 5

e. int list[7] = {12, 13, , 14, 16, , 8};
Answer: Invalid. Invalid value with comma. there should a avlue between two commas.

Question 6
Answer: 16 32 44 56 68 37 20


7. Is each of the following a valid or invalid array definition? (If a definition is invalid, explain why.)
a) int numbers[10] = {0, 0, 1, 0, 0, 1, 0, 0, 1, 1}; is valid
b) int matrix[5] = {1, 2, 3, 4, 5, 6, 7}; is invalid
c) double radii[10] = {3.2, 4.7}; is valid
d) int table[7] = {2, , , 27, , 45, 39}; is invalid
e) char codes[] = {'A', 'X', '1', '2', 's'}; is valid
f) int blanks[]; is invalid
g) char name[6] = "Joanne"; is invalid


8. Given the following array definition:
int values[] = {2, 6, 10, 14};
What does each of the following display?
a) cout << values[2]; will print 10
b) cout << ++values[0]; will print 3
c) cout << values[1]++; will print 6
d) x = 2;
cout << values[++x]; will print 14

9. Fill in the table below so it shows the contents of the following array:
int table[3][3] = {{2, 3}, {7, 9, 2}, {1}};

10. Consider the following array definition:
int values[5] = { 4, 7, 6, 8, 2 };
What does each of the following statements display?
cout << values[4] << endl; ____2______
cout << (values[2] + values[3]) << endl; _____14_____
cout << ++values[1] << endl; ____8______

2 3 0 7 9 2 1 0 0
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote