1. (TCO 1) For the values given, what will c contain after executing the followi
ID: 3529031 • Letter: 1
Question
1. (TCO 1) For the values given, what will c contain after executing the following? int a = 11, b = 4, c = -1; c = ++a / b - 1; (Points : 5) 4 1 2 -1 2. (TCO 2) Which statement outputs a double value in a field of nine characters with three digits after the decimal point? (Points : 5) cout << 9chars << 3digits << 1.2345678; cout << fixed << setprecision(9) << 1.2345; cout << setprecision(9) << setw(3) << 1.2345; cout << setprecision(3) << setw(9) << 1.2345678; 3. (TCO 10) For readability, all statements inside an if statement body should be (Points : 5) indented the same distance as the if statement. surrounded by an open and closing parenthesis. indented by one additional tab stop more than the if statement. written on the same line. 4. (TCO 3) What is the value of beta after the following code executes if the input is 1? int beta; cin >> beta; switch(beta) { case 3: beta += 3; case 1: beta++; case 5: beta += 5; case 4: beta += 4; } (Points : 5) 14 7 2 11 5. (TCO 4) How many times does the following loop body execute? int count = 52; for(int i = 26; i >= 0; i = i - 2) { cout << count << endl; --count; } (Points : 5) 13 26 14 None of the above 6. (TCO 8) Trying to access an array element beyond the end of the array can lead to an attempt to access an address outside your program's memory space which is a (Points : 5) runtime error. linker error. compiler error. All of the above 7. (TCO 8) Setting a breakpoint on a line of code and running your program (Points : 5) causes your program to fail at the point where the breakpoint occurs. allows the debugger to stop your program just after the line containing the breakpoint executes. allows the debugger to stop your program just before the line containing the breakpoint executes. None of the above 8. (TCO 9) Testing repetition statements (Points : 5) must validate that a loop repeats the correct number of times. controlled by complex conditionals can involve many test cases. must have a test case for each condition which terminates the loop. All of the above 9. (TCO 9) Black box testing (Points : 5) is done without any knowledge of how a program is implemented. is based on the problem statement and the requirements which specify how the solution must behave. is not concerned with testing every execution path through the program code. All of the above 10. (TCO 5) When a variable is passed by reference, _______. (Points : 5) the variable can be changed by the calling and the called function the location of the variable is given to the function the called function can change the value of the calling program's variable All of the above 11. (TCO 5) When should you use reference variables as function parameters? (Points : 5) When the value of the actual parameter needs to be changed When you want to return one value from the function When you want the function to process a copy of the data None of the above 12. (TCO 6) Arrays can be passed to functions by _______. (Points : 5) reference value either reference or value All of the above 1. (TCO 5) Place function prototypes before main() to (Points : 5) avoid compilation errors. reuse the function. avoid run-time errors. avoid linker errors. 2. (TCO 5) What is wrong with this function? void calcSum(int a, int b) { return a+b; } (Points : 5) it is declared as void but returns an int. Only a single variable can be returned. "calcSum" is a reserved word. Only the data type should be declared in the parameter list. 3. (TCO 5) The function overloading feature of C++ enables _______. (Points : 5) several functions to have the same name functions to be nested functions to accept parameters other than those declared greater memory allocation for function data 4. (TCO 6) What is the range of valid subscripts for the following array? double list[10]; (Points : 5) 0 to 9 0 to 10 1 to 9 1 to 10 5. (TCO 6) Given the following array declaration, if the array is stored starting at address 2500, what is the output of the following statement? Assume the code is for a 32 bit processor such as a Pentium. char data[50] = {0}; cout << (int)(&data[25]) << endl; (Points : 5) 2525 0 2550 unknown 6. (TCO 6) What does the following function do? double calc ( double data[ ], int size ) { double s = 0; for(int i = 0; i < size; i++) { s += data[i]; } return(s / size); } (Points : 5) Returns the sum of all the values in the data array Does nothing because the data array does not exist Fails because the size of the array is not known Returns the average of the values in the data array 7. (TCO 6) The initial values of the elements of foo are _______. double foo[500] = {0.0}; (Points : 5) zero for first element, junk values for all the others junk values all zeros None of the above 8. (TCO 6) What will the third statement in the following code snippet do? const int MAX = 500; double foo[MAX] = {0.0}; foo[MAX] = 1.1; (Points : 5) assign the value 1.1 to the last array element. it compiles but causes a run-time error. cause a compiler error. None of the above 9. (TCO 5) A variable declared within a block (inside curly brackets) is visible (Points : 5) from the point of declaration onward to the end of the program. from the point of declaration onward to the end of the function. from the point of declaration onward to the end of the block. anywhere in the program. 10. (TCO 7) A C-Style string which is not null terminated will (Points : 5) cause a compiler error. cause a run-time error when processed by the strcpy function. cause a linker error. produce a correct result when processed by the strlen function. 11. (TCO 7) What does the following function call return? strcmp("Dave", "Buster"); (Points : 5) A value of 0 A negative number A positive number Nothing, this is an incorrect use of the strcmp function. 1. (TCO 7) Given the following string variable, write a statement that would insert "interesting" before the word example in str1. string str1 = "Here is an example string"; (Points : 5) 2. (TCO 7) Given the following string variable, write a statement that would locate the position of "string" in the str1 variable and store the result in an int variable named pos. string str1 = "Here is an example string"; (Points : 5) 3. (TCO 7) Create an output format statement which would generate lines in the table which appear as shown below. The Element Name Field displays an element name contained in the name variable. YYY displays an integer value from the anum variable which ranges from 1 thru 109 and should be left justified. XXX.XXXX displays an atomic weight value from the aweight variable which ranges from 1.0000 to 268.0000 and should be right justified. Use the variables shown below in your output statements. Element Name Field..YYY....XXX.XXXX char name[15]; int anum; double aweight; (Points : 5) 1. (TCO 6) Write a code fragment using ONE for-loop to calculate the sum and product of the elements of a floating point array. The array is declared as shown below. Include any other declarations and initialization statements necessary to perform the operation. Display the sum and product results after the for-loop using cout. const int MAX = 15; float values[MAX] = {98.0, 75.0, 66.5, 78.5, 83.5, 89.0, 94.0, 43.0, 99.0, 88.0, 42.5, 72.0, 59.5, 77.0, 63.5}; (Points : 20) 2. (TCO 5) Write a function that takes inputs of quarts and pints (whole numbers), then calculates and returns an output of the total number of gallons (a floating-point value). There are 4 quarts in a gallon, and 2 pints in a quart. Use appropriate parameter passing and return mechanisms. Use appropriate datatypes. For example, with inputs of 4 quarts and 4 pints, the result would be 1.5 gallons. Use proper code formatting techniques. Do not write a main routine. Your function does not do cin or cout. (Points : 15) 3. (TCO 5) Write a function that converts an input of some integer number of nickels into outputs of integer numbers of dollars, quarters, and nickels. Do not write a main function. Your function does not do cin or cout. Your function will have four parameters. Make sure you use appropriate parameter passing techniques! Your function will be a void function. There are 5 nickels in a quarter, and 20 nickels in a dollar. For example, if the total number of nickels input is 27, the results are 1 dollar, 1 quarter, and 2 nickels. (Points : 15) 1. (TCO 7) Write a function that takes a C string as an input and counts the number of vowels in the C string. Vowels must include both upper and lower case a, e, i, o, u, and y. You are not allowed to use any other functions to do this. Do not write a main function. Your function does not do any cin or cout. Remember, C strings are terminated with the '' character. Make sure to properly format all your code. (Points : 20) 2. (TCO 7) Write a function which takes one string variable (not C string) as input and appends additional information to the existing string. The function must get a first and last name from the user and add them to the original string so the final string appears as follows: original_string_content|first_name|last_name You must add the '|' character to the string as shown. Use an appropriate parameter passing mechanism. Do not write a main function. Make sure to properly format all your code. (Points : 15)Explanation / Answer
1.4 2. coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.