Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 11

What is array index out of bounds? Does \(\mathrm{C}++\) check for array indices within bounds?

Problem 12

Suppose that scores is an array of 10 components of type double, and: \\[ \text { scores }=\\{2.5,3.9,4.8,6.2,6.2,7.4,7.9,8.5,8.5,9.9\\} \\] The following is supposed to ensure that the elements of scores are in nondecreasing order. However, there are errors in the code. Find and correct the errors. for (int i = 1; i <= 10; i++) if (scores[i] >= scores[i + 1]) cout << i << " and " << (i + 1) << " elements of scores are out of order." << endl;

Problem 13

Write \(\mathrm{C}++\) statements to define and initialize the following arrays. a. Array heights of 10 components of type double. Initilaize this array to the following values: 5.2,6.3,5.8,4.9,5.2,5.7,6.7,7.1,5.10,6.0. b. Array weights of 7 components of type int. Initilaize this array to the following values: 120,125,137,140,150,180,210. c. Array specialSymbols of type char. Initilaize this array to the following values: '$', '#', '%', '@', '&', '! ', '^'. d. Array seasons of 4 components of type string. Initilaize this array to the following values: "fall", "winter", "spring", "summer".

Problem 14

Determine whether the following array declarations are valid. a. \(\operatorname{int} a[5]=\\{0,4,3,2,7\\}\); b. \(\operatorname{int} b[10]=\\{0,7,3,12\\}\); c. int \(c[7]=\\{12,13,, 14,16,, 8\\}\); d. double lengths []\(=\\{12.7,13.9,18.75,20.78\\}\); e. char name \([8]=\) "Samantha";

Problem 15

Suppose that you have the following declaration: \\[ \text { int } \operatorname{list}[10]=\\{8,9,15,12,80\\}; \\] What is stored in each of the components of list.

Problem 18

Suppose that you have the following function definition. void sum(int x, int y, int& z) { z = x + y; } Consider the following declarations: int list1[10], list2[10], list3[10]; int a, b, c; Which of the following function calls is valid? a. \( \operatorname{sum}(a, b, c)\); b. sum (list1[0], list2[0], a); c. sum (list1, list2, c); d. for (int i = 1; i <= 10; i++) sum(list1[i], list2[i], list[3]);

Problem 19

What is the output of the following C++ code? double salary[5] = {25000, 36500, 85000, 62500, 97000}; double raise = 0.03; cout << fixed << showpoint << setprecision(2); for (int i = 0; i < 5; i++) cout << (i + 1) << " " << salary[i] << " " << salary[i] * raise << endl;

Problem 21

include using namespace std; int main() { int count; int alpha[5]; alpha[0] = 5; for (count = 1; count < 5; coun… # What is the output of the following program? #include using namespace std; int main() { int count; int alpha[5]; alpha[0] = 5; for (count = 1; count < 5; count++) { alpha[count] = 5 * count + 10; alpha[count - 1] = alpha[count] - 4; } cout << "List elements: "; for (count = 0; count < 5; count++) cout << alpha[count] << " "; cout << endl; return 0; }

Problem 22

include using namespace std; int main() { int j; int one[5]; int two[10]; for (j = 0; j < 5; j++) one[j] = 5 * j… # What is the output of the following program? #include using namespace std; int main() { int j; int one[5]; int two[10]; for (j = 0; j < 5; j++) one[j] = 5 * j + 3; cout << "One contains: "; for (j = 0; j < 5; j++) cout << one[j] << " "; cout << endl; for (j = 0; j < 5; j++) { two[j] = 2 * one[j] - 1; two[j + 5] = one[4 - j] + two [j]; } cout << "Two contains: "; for (j = 0; j < 10; j++) cout << two[j] << " "; cout << endl; return 0; }

Problem 23

What is the output of the following \(\mathrm{C}++\) code? const double PI = 3.14159; double cylinderRadii[5] = {3.5, 7.2, 10.5, 9.8, 6.5}; double cylinderHeights[5] = {10.7, 6.5, 12.0, 10.5, 8.0}; double cylinderVolumes[5]; cout << fixed << showpoint << setprecision(2); for (int i = 0; i < 5; i++) cylinderVolumes[i] = 2 * PI * cylinderRadii[i] * cylinderHeights[i]; for (int i = 0; i < 5; i++) cout << (i + 1) << " " << cylinderRadii[i] << " " << cylinderHeights[i] << " " << cylinderVolumes[i] << endl;

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks