Summer 2002 Test #2

CSE1320                                                                                                                             Section 501

Monday, July 15 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 bit field

 

A)  can be used with the addressing operator

B)  is a member of a structure

C)  must be named

D)  always starts on a byte boundary in memory

 

2.   The scope of a variable

 

A)  defines how long the variable exists during program execution

B)  defines the distance from the variable to the end of the program

C)  defines the way in which the variable can be used in the program

D)  defines the part of the program that can see and use the variable

 

3.   The storage class of a variable

 

A)  defines how long the variable exists during program execution

B)  defines the distance from the variable to the end of the program

C)  defines the way in which the variable can be used in the program

D)  defines the part of the program that can see and use the variable

 

4.   Which of the following is not a storage class?

 

A)  register

B)  extern

C)  default

D)  static

 

5.   Which of the following is the best choice for structured programming?

 

A)  exit – used to give information to the user

B)  return – to finish execution of a function

C)  goto – to efficiently transfer and control the flow of execution

D)  break – used to end an incremented loop

 


6.   Write a recursive function to calculate the value of the function f given the definition below for the function. Assume that you receive one integer input x and return a long value.  {16}

 

                                          f(x-1) + x2 for x > 1

 

      f(x) =                           1                for x = 1

 

                                          0                for x ≤ 0

 

 

 

 

 

 

 

 


7.   Use the following code fragment to answer the questions below:          

 

enum done toaster;

toaster = black;

switch (toaster) {

      case burnt:        printf(“ Burnt!”);

      case black:        printf(“ Oh, yuck!”);

      case done:         printf(“ Someone made “);

      case light:          printf(“ Toast?”);

      case default:     printf(“ Jam?”);

}

 

A)  Write an enumerated type named done that would properly define the values for the variable toaster given the switch statement above.                                                  {6}

 

 

 

 

 

 

 

 

 

 

B)  Give the result of executing the code fragment above assuming it compiles correctly.                         {8}

 

 

 

 

 

 

 

 

 

C)  Using the syntax given below, write the remainder of the case for a value not such that the switch will print out the message “Broken?” when the value of toaster is not.                  {7}

 

 

switch (toaster) {

      case not:           

 

 

 

 

 

 

      case burnt:        printf(“ Burnt!”);


8.   Define a structure type named donation that contains the following information: a unique 8-digit code, a blood type (A,B,O, or AB), an rH factor (+ or -), the date in dd/mm/yyyy form, and a location code (up to 20 characters). Also declare two variables of this new type.                                                                                                                                                                                                             {11}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

9.Write the interpretation of the declaration below in words.                                                {10}

 

      long (* fun1)(double, char *[]);

 

      The variable fun1 is

 

 

 

 

 

 

 

 

 

 

10. Write the correct syntax for the prototype declaration of a function with an integer input and a string input which returns a pointer to a function with a float input and a void return value.                                                                                                                                                    {10}

 

 

 

 


11. Write a switch statement to print the astrological sign for a given date. Use the table below to write the cases. The switch must use both month and date information to correctly work.                                                                                                                                                            {12}

 

      January 21 – February 19         Aquarius       

      February 20 – March 20            Pisces

      March 21 – April 20                    Aries

      April 21 – May 21                       Taurus

      May 22 – June 21                        Gemini

      June 22 – July 23                         Cancer

      July 24 – August 23                    Leo

      August 24 – September 23        Virgo

      September 24 – October 23      Libra

      October 24 – November 22      Scorpio

      November 23 – December 21  Sagittarius

      December 22 – January 20        Capricorn

 

 

 

 


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

 

Use the the following code fragment to answer the next questions

struct toodo {

      int                   trala, whee;

      char                *whoopsy;

      float                doodles;

      char                cat, hat, sat, rat;

} seuss, ogden, *sendak;

 

XC1.   Which of the following would NOT correctly assign a value to the string member of this type of structure?

 

A)  struct toodo *cummings = ‘poodles’;

B)  ogden.whoopsey = “bedelia”;

C)  sendak->whoopsy = “frederick”;

D)  char *tenny = “harold”; sendak->whoopsy = tenny;

 

XC2.   Which of the following would NOT assign a value to the member hat assuming a character takes one byte to store?

 

A)  char *jerry = &seuss.cat ; *(jerry + 1) = ‘t’;

B)  ogden.hat = 65;

C)  sendak.hat = ‘m’;

D)  seuss.hat = ‘g’;

 

XC3.   A union

 

A)  value is meaningless if used improperly by the programmer

B)  allocates enough space for the largest member type of the union

C)  can hold multiple types of information

D)  all of the above

 

XC4.   An iteration control structure that tests at the end is a

 

A)  for loop

B)  do-while loop

C)  if statement

D)  while loop

 

XC5.   Recursion reminds me of the following animal                                                                   

 

BECAUSE:

 

 

 

 

(Any complete answer – both parts - will get two points J )