Spring 2002 Test #1

CSE1320                                                                                 Sections 003 (2:30) and 501 (5:30)

Tuesday, February 5, 2002                                                                                              Dr. Tiernan

 

Name:                                                                                             Section:                                             

Student ID:                                                                                     Keyword:                                         

 

Instructions:

 

1.   Fill in your name, student ID, and section above. Choose some keyword for yourself that I can use to anonymously post grade information. If you do not choose a keyword, I will use your student ID to post grade information if needed.

 

2.   This is a closed book, closed notes test.

 

3.   The test is worth a total of 100 points. The value for each question is given either at the top of that section of questions or in curly braces to the right hand side of the question. There are extra credit questions at the end of the test worth an additional 10 points total.

 

4.   NO CHEATING!

 


Multiple choice questions are worth four {4} points each. Please circle the letter indicating your choice for the answer.

 

Use the following C function to answer questions 1 through 5.

 

      int adden( int addenda, float addendb) {

            int whole = (int) addendb;

            if ((addendb – whole) > 0.5)

                  return (addenda + whole + 1);

            else

                  return (addenda + whole);

      }

1.   Which of the following is a valid ANSI C prototype declaration for the function definition of adden?

 

A)  adden( aint, bfloat );

B)  int adden( addenda, addendb );

C)  adden( int aint, float bfloat );

D)  int adden( int, float);

 

2.   Which of the following function calls would return a result of 10?

 

A)  adden( 6, 4.7 )

B)  adden( 5, 4.7 )

C)  adden( 6, 5.1 )

D)  adden( 5, 5.1 )

 


3.   Given the function adden above, what property of C was used on addendb to assign a value to whole?

 

A)  automatic changing

B)  promotion

C)  dominating

D)  forced or explicit conversion

 

4.   Given the function adden above, if three variables are declared in the main function as follows: int operand1 = 16, operand3; float operand2 = 3.9; and the main routine has the statement operand3 = adden( operand1, operand2 ); what are the values of operand1 and operand2 after the call to adden?

 

A)  operand1 = 16 and operand2 = 3.9

B)  operand1 = 16 and operand2 = 3

C)  operand1 = 20 and operand2 = 3.9

D)  operand1 = 20 and operand2 = 3

 

5.   Given the function adden above, if we had left out the (int) in the assignment to whole, with addendb = 67.8 and the program still compiled correctly, what would you expect the program execution to assign to whole?

 

A)  Since the program compiled correctly, in execution it will have a syntax error

B)  Since the program compiled correctly, in execution whole would get 67.8

C)  Since the program compiled correctly, in execution whole would get 67

D)  Since the program compiled correctly, in execution whole would be automatically cast to float


6.   Declare a variable named tasteful as an array with 10 characters in it. Initialize all of the elements of this array as part of the declaration. You may initialize the array elements to any values that match the type of the array.                                   {8}

 

 

 

 

 

 

7.   a) Convert the following decimal number to its hexadecimal representation: 467310

                                                                                                                                                             {8}

 

 

 

 

 

b) Convert the signed hexadecimal number from above to its binary representation using a sign bit, and record it in the 16-bit space below.                     {7}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8.   Assume all the variables used in the code fragment below that are not explicitly declared, have been declared previously in the program. What combinations of values being tested could cause the final value of outcome to be 0?                                 {20}

 

int condition = 0, test, flag = 20;                       HINT: Look at each assignment to outcome

… /* other C code here */                               to see if there is ANY set of values that would

if (!flag)                                                                make it equal 0. If so, what conditions would

      outcome = condition + flag;                       have to be true to get those values? Remember

else if (!condition)                                               to think about what actions might have

            {                                                                 happened at the /*commented*/ line.

            test = ++condition * flag;

            outcome = test ^ !flag;

            }

      else if (flag | condition)

                  outcome = 0;

            else

                  outcome = test = condition *= flag;

 

List all the combinations of the values that will make outcome = 0;

 

 

 

 

 


9.   Given the declarations and the for loop below:                                                                   {10}

float array[10];

 

for ( i = 10, --i ; i ≥ 0 ; i-- ) {

array[i] = 2 * (10 – i) - 1;

}

what values will array[0] and array[6] have after the for loop has completed?

 

a[0] =                              

 

a[6] =                               

 

10. List two (2) C library files and two (2) preprocessor commands.                                       {8}

 

 

 

 

 

 

11. Define a function to calculate the slope and the y-axis-intercept from two input points on a line drawn on a Cartesian plane. Slope (typically called ‘m’) is calculated as rise over run, or the difference in y divided by the difference in x. The y-axis-intercept (typically called ‘b’) is the height at which the line crosses the y axis.          {19}

      Read in two points, given as (x1, y1) and (x2, y2), then calculate the slope and y-intercept. Have your function print as output the two input points and the equation of the line containing those points in slope-intercept form (y = mx + b).

 

 



Extra Credit questions - Worth two {2} points each.

 

XC1.   Given the function adden, used above in questions 1 through 4, what mathematical operation is essentially being performed on addendb?

 

A)  taking the floor

B)  taking the ceiling

C)  rounding

D)  squaring

 

 

XC2.   Which of the following types of operations cannot be used with floating point numbers in ANSI C?

 

A)  Arithmetic

B)  Bitwise

C)  Logical

D)  Relational

 

 

XC3.   Which of the following would not evaluate to true?

 

A)  ( 7 & 16 )

B)  ( ‘u’ – ‘s’ )

C)  ( 463.982201 )

D)  ( 9 + --8.99999999 )

 

 

XC4.   If we used the the following code fragment:

k = 100;

while !(k = 0)

      k--;

      which of the following would NOT be true?

 

A)  The value of k would decrease in every iteration of the loop.

B)  The loop would run at least 100 times.

C)  The while loop would stop when k’s value was equal to 0.

D)  The decrement operation happens after the loop test each iteration.

 

 

XC5.   Which of the following would create an array of integers with 4 in the 3rd element?

 

A)  int temps[5] = {1, 2, 3, 4};

B)  array[3] = 4;

C)  char small[3] = {4, 4, 4};

D)  int hold[4] = {4, 3, 2, 1};