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

1. (TCO 1) For the values given, what will c contain after executing the followi

ID: 3540787 • Letter: 1

Question



1. (TCO 1) For the values given, what will c contain after executing the following?

int a = 9, b = 4, c = -2;
c *= ++a % b;

(Points : 5)      
       4
       -4
       -2
       2
     
  

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, variable names should be (Points : 5)      
       short and only use lower case letters.
       a random mix of letters and numbers for security reasons.
       very long and complex to assure uniqueness of each name.
       indicative of what value is being stored in the variable.
     
  

4.
(TCO 3) What is the value of beta after the following code executes if the input is 3?
       
int beta;
cin >> beta;
switch(beta)
{
case 3:
beta += 3;
case 1:
beta++;
break;
case 4:
beta += 4;
break;
case 5:
beta += 5;
}
(Points : 5)      
       11
       6
       7
       3
     
  

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) A reference from your code to some external resource which cannot be resolved leads to a (Points : 5)      
       runtime error.
       linker error.
       compiler error.
       All of the above
     
  

7. (TCO 8) An assertion statement (Points : 5)      
       is used to verify that some condition in your program is true.
       aborts your program if the asserted condition is false.
       outputs filename and line number information associated with a failed assertion.
       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) Which of the following statements about testing are true? (Points : 5)      
       Black box test cases can be written as soon as the problem statement and program requirements are specified.
       White box testing is typically done by the programmer as code is being developed.
       Both black box and white box testing are commonly done to fully test a program.
       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) 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
     


  


Explanation / Answer

1. (TCO 1) For the values given, what will c contain after executing the following?
    int a = 9, b = 4, c = -2;
    c *= ++a % b;
   
    ++a will be 10
    b is 4
    now (++a) % b = (10%4) = 2
    c =c*2 => c = -2*2 = -4

    so value will be -4    

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 << setprecision(3) << setw(9) << 1.2345678;
    // THIS IS STANDARD INTERFACE PROVIDED BY C++.    

3. (TCO 10) For readability, variable names should be (Points : 5)     

    indicative of what value is being stored in the variable.
   
4. (TCO 3) What is the value of beta after the following code executes if the input is 3?
      
    int beta;
    cin >> beta;
    switch(beta)
    {
    case 3:
    beta += 3;
    case 1:
    beta++;
    break;
    case 4:
    beta += 4;
    break;
    case 5:
    beta += 5;
    }

    case 3 will be executed because (beta is 3) beta = 3+3 = 6. since there is not break statement after that.
    beta+++ will be executed (thus beta will hold value 7) since there a break statement after that switch ends here.
   
    beta value will be 7.
   
    7 is answer.
   
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;
    }
   
    i starts at 26 now i>=0 till i ==0 loop executes.
    26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0
   
    TOTAL 14 times.
   
    thus 14 is answer.

6. (TCO 8) A reference from your code to some external resource which cannot be resolved leads to a (Points : 5)     
   
    runtime error.
    BECAUSE EXTERNAL RESOURCE WILL BE CHECKED AT RUN TIME. if it is not available then it leads to runtime error.

7. (TCO 8) An assertion statement (Points : 5)     
   
    All of the above
   
8. (TCO 9) White box testing (Points : 5)     

    requires knowledge of the structure of the program code.

9. (TCO 9) Which of the following statements about testing are true? (Points : 5)     
   
    Black box test cases can be written as soon as the problem statement and program requirements are specified.
    White box testing is typically done by the programmer as code is being developed.
    Both black box and white box testing are commonly done to fully test a program.
    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) Arrays are always passed into a function by location because (Points : 5)     
      
    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.
   
12. (TCO 6) Arrays can be passed to functions by _______. (Points : 5)     
    reference

    arrays can be passed to function by reference because address of array will be passed.