Question
1. Write C++ statements to do the following: a. Declare an array beta of 20 components of type double. b. Initialize each component of the
1. Write C++ statements to do the following: a. Declare an array beta of 20 components of type double. b. Initialize each component of the array beta to 0. c. Output the value of the fifth component of the array beta. d. Set the value of the ninth component of the array beta to 70.50. e. Set the value of the twelth component of beta to four times the value of the eighth component of beta minus 15.
2. What is stored in list after the following C++ code executes? int list[10]; for (int i = 0; i < 5; i++) { list[i] = i * i - 5; if (i % 3 == 0) list[i] = list[i] + i; else list[i] = list[i] - i; }
3. 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] / 4; }
4. 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: 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. Initialize this array to the following values: 120, 125, 137, 140, 150, 180, 210. c. Array special Symbols of type char. Initialize this array to the following values: '$', '#', '%', '@', '&', '! ', '^'.
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
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; __________
11.Consider the following declaration: int beta[3][3]; What is stored in beta after each of the following statements executes? a) for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) beta[i][j] = 0; b) for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) beta[i][j] = i + j;
12.Write a statement that defines a two-dimensional array to hold three strings. Initialize the array with your first, middle, and last names.
13.Consider the following array definition. int numberArray[9][11]; a. Write a statement that assigns 145 to the first column of the first row of this array. b. Write a statement that assigns 18 to the last column of the last row of this array.
14.An application uses a two-dimensional array defined as follows. int days[29][5]; a. Write code that sums each row in the array and displays the results. b. Write code that sums each column in the array and displays the results.
15.Consider the following code. What value will be stored in s after the code executes? char name[10]; int s; strcpy(name, "Jimmy"); s = strlen(name);
16.What header file must you include in a program using string functions such as strlen and strcpy?
17.Define a two-dimensional array named temp of three rows and four columns of type int such that the first row is initialized to 6, 8, 12, 9; the second row is initialized to 17, 5, 10, 6; and the third row is initialized to 14, 13, 16, 20.
18.Given the declaration, mark the following statements as valid or invalid. If a statement is invalid, explain why. char str1[15]; char str2[15] = "Good day"; a. str1 = str2; b. if (str1 == str2) cout << " Both strings are of the same length." << endl; c. if (strlen(str1) >= strlen(str2)) str1 = str2;
19.Show the output of the following program: #include
20.Consider the following function prototypes: int test(int, char, double, int); double two(double, double); char three(int, int, char, double); Answer the following questions. a. How many parameters does the function test have? What is the type of the function test ? b. How many parameters does function two have? What is the type of function two? c. How many parameters does function three have? What is the type of function three ? d. How many actual parameters are needed to call the function test? e. What is the type of each actual parameter, and in what order should you use these parameters in a call to the function test? f. Write a C++ statement that prints the value returned by the function test with the actual parameters 5, 5, 7.3, and 'z'.
21.Write the definition of a function that takes as input three numbers and returns the sum of the first two numbers multiplied by the third number. (Assume that the three numbers are of type double.)
22.Write the definition of a function that takes as input the three numbers. The function returns true if the first number to the power of the second number equals the third number; otherwise, it returns false. (Assume that the three numbers are of type double.)
23.A program contains the following function. int cube(int num) { return num * num * num; } Write a statement that passes the value 4 to this function and assigns its return value to the variable result.
24.What is the error in following function definitions? a) void total(int value1, value2, value3) { return value1 + value2 + value3; } b) double average(int value1, int value2, int value3) { double average; average = value1 + value2 + value3 / 3; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started