Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Consider the following declaration: double words[60]; In this declaration, identify the following: a. The array name: b. The array size: c. The data type

1. Consider the following declaration: double words[60]; In this declaration, identify the following: a. The array name: b. The array size: c. The data type of each array component: d. The range of valid indices for the array: to

2. Explain why the following declarations are invalid. a. people[82]; Answer: b. int myArray[50; Answer: c. int SIZE; double list[SIZE]; Answer: d. const int X = 50; double list[X 55]; Answer: e. int ids[-20]; Answer: f. name string[10]; Answer:

3. Write C++ statements to do the following:

a. Declare an array beta of 10 components of type double with all values initialize to zero.

b. Output the value of the first component of the array beta. Assume iostream has been included.

d. Set the value of the ninth component to 0.5 times the second component.

e. Set the value of the sixth component to the seventh component minus the third component.

f. Output the value of the last component of beta. Assume iostream has been included.

4. What is stored in myList after the following C++ code executes?

double myList[5];

myList[0] = 3.0;

myList[1] = 4.0;

for (int i = 2; i < 5; i++)

{

myList[i] = myList[i - 1] * myList[i - 2];

if (i > 3)

myList[i] = myList[i] / 2;

}

Answer:

5. Correct the following code so that it correctly sets the value of each element of myList to 3 times the elements index.

int myList[10];

for (int i = 1; i <= 10; i--)

myList[i] = 3i;

Answer:

6. Write C++ statements to define and initialize the following arrays.

a. Array heights of 10 components of type double. Initialize this array to the following values:

6.3, 1.8, 4.9, 1.2, 1.7, 6.7, 6.1, 1.10, 6.0, 1.2

b. Array weights of 7 components of type int. Initialize this array to the following values:

320, 325, 317, 340, 350, 380, 230

c. Array mySymbols of type char. Initialize this array to the following values:

'#', '^', '!', '%', '@', '&', '$'

d. Array seasons of 4 components of type string. Initialize this array to the following values:

"winter", "spring", "summer", "fall"

7. What is the output of the following C++ code?

Image

Output:

8. Suppose that you have the following function definition:

void sum(int x, int y, int & z)

{

z = x + y;

}

Consider the following declarations:

Which of the following function calls is valid? a. sum(a, b); Answer(valid/invalid):

b. sum(list1[0], list3[0], b); Answer(valid/invalid):

c. sum(list1, list3, c); Answer(valid/invalid):

d. for(int i = 0; i < 10; i++) sum(list1[i], list2[i], list3[i]); Answer(valid/invalid):

9. When an array is passed as an argument (or actual parameter) to a function, is it passed by value or reference? Answer:

10. Suppose that you have the following declaration: int list[7] = { 6, 10, 14, 18, 22 }; What is stored in each component of list? Answer:

Which of the following function calls is valid? a. sum(a, b); Answer(valid/invalid):

b. sum(list1[0], list3[0], b); Answer(valid/invalid):

c. sum(list1, list3, c); Answer(valid/invalid):

d. for(int i = 0; i < 10; i++) sum(list1[i], list2[i], list3[i]); Answer(valid/invalid):

9. When an array is passed as an argument (or actual parameter) to a function, is it passed by value or reference? Answer:

10. Suppose that you have the following declaration: int list[7] = { 6, 10, 14, 18, 22 }; What is stored in each component of list? Answer:

Which of the following function calls is valid? a. sum(a, b); Answer(valid/invalid):

b. sum(list1[0], list3[0], b); Answer(valid/invalid):

c. sum(list1, list3, c); Answer(valid/invalid):

d. for(int i = 0; i < 10; i++) sum(list1[i], list2[i], list3[i]); Answer(valid/invalid):

9. When an array is passed as an argument (or actual parameter) to a function, is it passed by value or reference? Answer:

10. Suppose that you have the following declaration: int list[7] = { 6, 10, 14, 18, 22 }; What is stored in each component of list? Answer:

11. Suppose that you have the following declaration:

int list[10] = { 35, 6, 10, 14, 17, 22, 34, 33, 34, 36 };

Using the selection sort algorithm, show all of the values in the list array after each iteration of the outer loop. You do not need to repeat the values of the array before the first iteration because it is stated above.

{ _ }

{ _ }

{ _ }

{ _ }

{ _ }

{ _ }

{ _ }

{ _ }

{ _ }

12. Mark the following statements as correct or incorrect (incorrect can be either a failure to compile or some other problem with the operation). If a statement is incorrect for some reason, explain why.

a. char str[16] = "kiwi";

strcpy(str, "apples or bananas");

Answer:

b. char str2[16] = "kiwi";

cout << strlen(str2);

Answer:

c. char str3[16];

str3[16] = "kiwi";

Answer:

d. char str4[16]; str4 = "kiwi"; Answer: e. char str5[16] = "kiwi"; str5[3] = '\0'; Answer:

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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Discuss the process involved in selection.

Answered: 1 week ago

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago