Spring 2004   Test #2

CSE1320                                                                                          Sections 501

Thursday, April 8, 2004                                                                        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 cannot post your 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.   In questions where I have given you code to use, if you find typos, assume that the code is SUPPOSED to work and just indicate what assumption you made for your answer.  This applies in all cases unless the question is specifically about the syntax of the code - in shich case there are errors on purpose.

 

 

5.   NO CHEATING!

 

 


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

 

 

1.         Which of the following is not an ADT?

 

A)        linked list

B)        queue

C)        stack

D)        struct

 

 

2.         Which of the following would not access a single number in int ar[3][5]?

 

A)        ar[1][0]

B)        **ar

C)        *(*(ar+2)+4)

D)        *(ar[3])

 

 

3.         Which of the following are two sorting algorithms discussed in class?

 

A)        bubble and squeak

B)        bubble and quick

C)        muddle and squeak

D)        muddle and quick

 

 

4.         Which of the following is NOT a characteristic of a recursive function?

 

A)        A change in return values

B)        A change in value of input parameters

C)        One or more base cases

D)        One or more calls to the function itself

 

 

5.   Name 2 types of scope and 4 out of the 5 storage classes.

                                                                                                                          {6 points total ; 1 each}

 

                                                                                                                                                          

                                                                                                                                                          

                                                                                                                                                          

 

 


6.   Given a file named “invalues.txt” containing some input data, write a code fragment to create a file variable and open this file for reading using your file variable.                                                                          {5}

 

 

 

 

 

 

 

 

 

 

 

 

 

7.   Write in words the meaning of the following declaration:                                                   {5}

 

      char *(*vol)(int [ ], float *);

 

 

 

 


8.   Define an array to hold a matrix of 3 rows and 4 columns of money values (in dollars and cents) and initialize all of the matrix values to zero.                                                                                                                 {4}

 

 

 

 

 

 

 

 

 

 

      a.   Use pointer arithmetic to put $3.25 into the 2nd row, 1st column                                {3}

 

 

 

 

 

 

      b.   Use array notation to put fourteen dollars and three cents into the 2nd column, 1st row

                                                                                                                                                              {3}

 

 

 

 

 

 

      c.   Write nested for loops to iterate through all the elements of the matrix and do the following:     {7}

            i.    If the element has a value greater than zero, then do nothing

            ii.   If the element has a zero value, then multiply the current row value by dollars and the column value by cents and store this total in the element

 

 

 

 

 

 

 

 

 

 

      Extra Credit:  Give the sum of the values in the matrix.                                                     /3/

 

 


9.   Given the function below answer the following questions:

 

      int zoom ( int b4, int a2 )

      {     if (b4 > a2)

                  return 0;

            else if (b4 == a2)

                  return b4;

            else return zoom( b4 + 1, a2 - 1) + b4 + a2;

      }

                                                                

      a.   What is the result of the call zoom(1, 5)?                                                                             {5}

 

 

 

 

      b.   What is zoom(1, 4)?                                                                                                               {3}

 

 

 

 

 

      c.   What is zoom(4, 6)?                                                                                                               {4}

 

 

 

 

 

      d.   What is zoom(x, y) calculating with regards to its inputs x and y?                               {4}

 

 

 

 

 

 

 

 

 

 

10. Write in C the following declaration:                                                                                       {5}

 

      tenn is an array of pointers to functions with two inputs, a string and a double, and a return type of the address of an int

 

 

 


11. Define an enumerated type called Seasons with the values Fall = 3, Spring = 1, Summer = 2, and Winter = 0.         {4}

 

 

 

 

 

 

      a.   Declare a variable now of the enumerated type Seasons above and an integer variable called avgtemp    {3}

 

 

 

 

 

 

      b.   Write a switch using now to switch on which does the following:                                {9}

                  for season Summer with an average temperature (avgtemp) > 91, print “Scorcher!”

                  for Summer with avgtemp <92, print “A wonderful Summer.”

                  for Fall with avgtemp > 75, print “A wonderful Fall.”

                  for Fall with 50 < avgtemp < 76, print “Nice.”

                  for Fall with avgtemp < 51, print “Brrr!”

                  for Winter, print “Brrr!”

                  for Spring with avgtemp < 51, print “Brrr!”

                  for Spring with avgtemp > 50, print “Finally!!”

 


12. Define a union type Amount that can hold either an int points or a float score                   {4}

 

 

 

 

 

13. Define a struct type named finals with the following fields:  an int numteams, an enumerated type Seasons when, a string game, a char how, two union type Amounts won and lost, and a bit field of 3 bits.                       {6}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

      a.   Define a variable of type finals UConnTenn and give it with following values:  4 teams, Spring, “NCAA women’s basketball”, ‘P’, 68, 59, 4                                                                                                             {5}

 

 

 

 

 

 

 

      b.   Define a variable of type finals SummerOlympicsMSR and give it with following values: 17 teams, Summer, “Men’s swimming relay”, ‘S’, 17.45, 17.39, 1                                                                                         {4}

 

 

 

 

 

 

 

      c.   Define a pointer Great that can point to UConnTenn and set it so that it points to that variable                             {3}

 

 

 


 

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

 

 

XC1)   Which of the following is NOT a reason why Dr. T. has given against goto or exit?

 

A)        It unnecessarily complicates the structure of the code

B)        It is an explicit crash of the program

C)        It is the result of sloppy thinking on the programmer’s part

D)        It could save time in a life-critical situation

 

 

XC2)   Which of the following is NOT required in order to build a singly-linked list?           

 

A)        A structure which contains a pointer to structures of its own type

B)        A pointer to the last structure in the list

C)        A method to link new structures into the list

D)        An external pointer to the first structure in the list

 

 

XC3)   Command line parameters are NOT:

 

A)        The commands that the program should execute

B)        Values typed in following the program invocation

C)        An int and an array of strings

D)        Two variables passed to a program by the operating system

 

 

XC4)   Define scope and storage class

 

 

 

 

 

 

 

 

 

XC5)   List at least one activity you have done at UTA this semester that was not related to any class you are taking.   (Preferably something fun!)

                                                                                          {ANY answer will receive 2 (two) points}