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

1. (TCO 1) Suppose a, b, and c are int variables and a=5 and b=6. What is the va

ID: 3630805 • Letter: 1

Question

1. (TCO 1) Suppose a, b, and c are int variables and a=5 and b=6. What is the value of a after this statement executes: a = (a + 4) % b++; (Points : 5)
2
3
1
1.5


2. (TCO 2) Which statement outputs a double value in a field of eight characters with four digits after the decimal point? (Points : 5)
cout << 8chars << 4digits << 1.23456;
cout << fixed << setprecision(4) << 1.23456;
cout << setprecision(4) << setw(8) << 1.2345678;
cout >> setprecision(8) >> 4chars >> 1.2345;


3. (TCO 10) For readability, all statements inside a loop body should be (Points : 5)
indented the same distance as the loop control statement.
indented by one additional tab stop more than the loop control statement.
surrounded by an open and closing parenthesis.
written on the same line.


4.
(TCO 3) What is the value of beta after the following code executes if the input is 5?

int beta;
cin >> beta;
switch(beta)
{
case 5:
beta += 5;
case 1:
beta++;
case 5:
beta += 5;
break;
case 4:
beta += 4;
}
(Points : 5)
16
11
7
20


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) When a program is stopped at a breakpoint, you can use the debugger to (Points : 5)
examine program variables.
change the value of program variables.
set new breakpoints or clear existing breakpoints.
All of the above


8. (TCO 9) White box testing (Points : 5)
is done without any knowledge of how a program was implemented.
requires knowledge of the structure of the program code.
is not concerned with testing every execution path through the program code.
None of the above


9. (TCO 9) When doing feature testing, _______. (Points : 5)
a test case is based on how a correct solution to the problem would respond to given inputs
the tester focuses on the selection and repetition statements in the program code
test cases cannot be written until the program code is complete
None of the above


10. (TCO 5) When a variable is passed by reference as a function argument, (Points : 5)
its value is copied
it can have its value both read and modified by the function
it is protected from being modified by the function
All of the above


11. (TCO 5) Arrays are always passed into a function by location because (Points : 5)
passing an array by value would require changing every element of the array.
it is much quicker to pass location information than to create a copy of the entire array which would be needed for pass by value.
a function should never need a private copy of an array to work on.
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

13. (TCO 5) Advantages of incorporating functions into your program include: (Points : 5)
Someone else can write one of the functions while you're writing another.
You can reuse them.
They can make your program more readable.
All of the above


14.
(TCO 5) What is the output of the following code?

void func(int x[ ])
{
x[0] = x[0] * 3;
x[1] = x[1] * 3;
x[2] = x[2] * 3;
}
int main( )
{
int x[ ] = {1, 2, 3};
func(x);
cout << x[0] << " " << x[1] << " " << x[2] << endl;
}
(Points : 5)
1 2 3
3 4 5
3 6 9
3 3 3


15.
(TCO 5) The code below is an example of what type of function?


int abs(int num)
{
if (num == 0)
num = -num;
return num;
}
(Points : 5)
Value-returning
Void
Subroutine
None of the above


16. (TCO 6) What is the range of valid subscripts for the following array?

char name[99];

(Points : 5)
1 to 99
0 to 98
1 to 98
0 to 99


17. (TCO 6) Given the following array declaration, if the array is stored starting at address 1000, what is the output of the following statement? Assume the code is for a 32 bit processor such as a Pentium.

double data[25] = {0.0};
cout << &data[10] << endl;

(Points : 5)
0.0
1080
1010
unknown


18.
(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


19. (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


20. (TCO 6) Using the variable max in the following way _______.

int max;
cin >> max;
double foo[max] = {0.0};

(Points : 5)
lets the user specify the array size during execution
will cause a run-time error
will cause a compiler error
None of the above


21. (TCO 5) A variable declared before all blocks in a program is (Points : 5)
visible to all functions defined in the program.
visible only to main.
visible only to the first block after it is declared.
not visible to any functions; it will cause a compile error.


22. (TCO 7) A null-terminated character array (Points : 5)
will cause a compiler error.
is a C-style string.
will cause a run-time error.
All of the above


23. (TCO 7) Which of the following correctly initializes the name array with the name Jack Jones? (Points : 5)
char name[15] = "Jack Jones";
char name[ ] = "Jack Jones";
char name[ ] = {'J', 'a', 'c', 'k', ' ', 'J', 'o', 'n', 'e', 's', ''};
All of the above

Explanation / Answer

1) -4 2)cout