Summer 2002 Test #1

CSE1320                                                                                                                             Section 501

Monday, June 24 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, NO CALCULATOR 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.

 

1.   A function prototype gives:

 

A)  exact variable names for the paramenters

B)  types and numbers of parameters and the return type

C)  source code for the function

D)  all of the above

 

2.   Which of the following is not a meaningful variable name?

 

A)  variable_1

B)  delta_x

C)  last

D)  max

 

3.   Which of the following would tell us that “zebra” should be alphabetized after “aardvark”?

 

A)  strlen

B)  strcat

C)  strcpy

D)  strcmp

 

4.   Which of the following would tell us that “water buffalo” is longer than “crocodile”?

 

A)  strlen

B)  strcat

C)  strcpy

D)  strcmp

 

5.   Which of the following would we use to take “monkey” and “spider” and make a new animal, “spider monkey”?

 

A)  strlen

B)  strcat

C)  strchr

D)  strcmp

 


6.   Write a loop to calculate and print the squares of the numbers from 1 to 9, i.e. to print out 1, 4, 9, 16, …, 81. Declare any variables you use. You do not need to write an entire program, just the declarations and statements needed to answer the question.     {7}

 

 

 

 

 

 

 

 

 

 

 

 

7.   A)  Write a set of declarations and/or statements to create an array of 8 or more characters initialized to hold your full name (first middle last <use all of your names in normal order>). Do NOT use array notation.                                  {9}

 

 

 

 

 

 

      B)  Use a string function to find the length of the string stored in the array declared above and save the length of the string in variable called namelength.                {6}

 

 

 

 

 

      C)  Write a code fragment to make the pointer last point to the last letter of the string above and then decrement the pointer until it points to the FIRST letter of the LAST name. Use the declaration for last given below:               {10}

 

      char *last;

 

 

 


 

8.   Use the following declarations and the diagram to answer the four questions below:

      int pink = 42;

      int *colorptr;

      colorptr = (int *) malloc (sizeof(int) * 3);

B002

 
      int **paletteptr;

 

A)  Using pointer arithmetic, write a set of declarations and/or statements to put the values 7, 4, and 62 into the space allocated to colorptr. {6}

 

 

 

 

 

 

 

 

 

B)  Using array notation, write a set of declarations and/or statements to replace the previous values of colorptr with 24, 39, and 2.                                                                  {5}

 

 

 

 

 

C)  Write a code fragment that would set paletteptr to a value that is a pointer to pink. (This requires at least two statements.)                                                                         {8}

 

 

 

 

 

 

 

D)  In the diagram above, write in the appropriate contents (from the previous declarations and code fragments) for pink and paletteptr.                                                     {4}


 

9.   Write a function prototype declaration that has four parameters, two integers, a string, and a character, and returns a pointer to integer                                   {5}

 

 

 

 

 

 

10. Convert the following decimal number to its binary representation using a sign bit, and record it in the 16-bit space below: 540910                                                       {5}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

11. Use the following code fragment to answer the two questions below.

 

int seed = 1;

while (seed < 10) {

      int sum = 0;

      for (int i = 1; i <= (seed*2-1); i += 2)

            sum += i;

      printf(“%d \t”, sum);

      seed++;

}

 

 

A)  Write the output from the above code fragment.                                                                 {7}

 

 

 

 

 

 

B)  Describe in words what the code fragment above does. Tell what is happening in terms of the mathematics that is being performed.                                      {8}

 

The code fragment above:

 


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

 

XC1.   Which of the following will multiply the variable k by 16?

 

A)  k *= 2 *4;

B)  k = k * k * k * k;

C)  k = 2 * 2 * 2 * 2;

D)  k <<= 4;

 

 

XC2.   Which of the following is the hexadecimal representation for the decimal: 540910

 

A)  540916

B)  152116

C)  1244116

D)  124418

 

 

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

 

A)  ( 7 | 16 )

B)  ( ‘b’ – ‘e’ - 3 )

C)  ( ‘mud’ )

D)  ( 56 * 2.7 )

 

 

XC4.   If we used the the following code fragment:

for (int k=1; k <=100; k += k)

      if ((k % 2) && (k % 3))

            printf(“%d \t”, k);

 

      which of the following would NOT be true?

 

A)  The value of k would increase 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 greater than or equal to 100.

D)  The increment of k happens after the loop each iteration.

 

 

XC5.   For the code fragment in XC4, which of the following would be the output?

 

A)  1 2 3 4…<and so on through>…98 99 100

B)  1 2 4 8 16 32 64

C)  1 2 3 6 8 9 10 12 14 15 16 18 20…<and so on>…96 98 99 100

D)  1