Summer 2002 Final Exam

CSE1320                                                                                                                             Section 501

Monday, August 12, 2002                                                                                                 Dr. Tiernan

 

Name:                                                                                             Section:                            501                                                                  

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.   arc and argv

 

A)  are the traditional names for the command line parameters from the operating system

B)  are the variables used to pass parameters from the main routine to another function

C)  are the values of the integer and string array sent to the main routine

D)  are the sounds programmers make when an error is detected

 

2.   Which of the following is NOT a type conversion function?

 

A)  atoi

B)  strtok

C)  strtod

D)  atol

 

3.   Operator overloading and templates are examples of what OOP characteristic?

 

A)  Data Abstraction

B)  Specification

C)  Inheritance

D)  Polymorphism

 

4.   Which of the following would NOT print a floating point value from variable flt?

 

A)  printf(“%lf”,flt);

B)  printf(“%d”,flt);

C)  printf(“%g”,flt);

D)  printf(“%LE”,flt);

 

5.   Which of the following is true about multi-dimensional arrays?

 

A)  int array1[3] would declare a 3-dimensional array of integers

B)  array2[4][5] would access the fifth row and the fourth column of an array

C)  char array3[2][2][3] would have 7 elements in it

D)  float array4[3][6] would declare an array of 3 arrays containing 6 floats

 


6.   Use the following list of files to answer parts A, B, and C.                                                 {10}

 

inputdata.txt                   output.txt

program.c                       program.h

 

A.  Write the code needed to open the input data file for reading and writing. Make sure to declare any variables you use.

 

 

 

 

B.   Write the code needed to open the output data file for appending. Make sure to declare any variables you use.

 

 

 

 

C.  Write the code needed to indicate to the program that the input file will not be used again.

 

 

 

 

7.   Using the following declarations:                                                                                           {15}

 

      struct design {

                              char *name=”fine example”;

                              int year;

                              char item[20];

                              struct design *nextexample;

      } *mackintosh, *wright;

 

rewrite the following segment of C code into C++ code. [Partial answers may receive partial credit.]

 

wright = (struct design * ) malloc (sizeof(struct design));

scanf(“%d %s”,&(wright->year), wright->item);

printf(“This is a %s of %d %s/n”, wright->name, wright->year, wright->item);

free(wright);

 

 

 


8.   Using the following declarations:                                                                                           {23}

 

      struct design {

                              char *name=”fine example”;

                              int year;

                              char item[20];

                              struct design *nextexample;

      } *mackintosh, *wright, *headdesigner;

      struct design **deco, **nouveau;

 

Write a program to read in data for 10 structs, make a singly linked list of them as they are read in, and then, when all the data has been read in, print the year data in each structure from the linked list in the order they were read in. (Make sure you read in 3 pieces of data for each struct.) [Partial answers may receive partial credit.]

 

 


9.   Using the declarations from question 8 and below, write a bubble sort to sort the array rennie by year. [Partial answers may receive partial credit.]                           {18}

 

 

      struct design rennie[25];

 

      /* Assume that valid data is read into all 25 structs in rennie                     */

      /* Sort the array rennie from earliest to latest year                                     */

 


10. Describe in words what the following code fragment will do based on the constant DEBUGGING:                                                                                                            {14}

 

int flag = 499;

 

#ifdef DEBUGGING

printf(“Debugging data will be printed as program runs.”)

int counter=0;

#define CHECKPOINT(x) printf(“At count %d, the value of flag is %d”,counter++,x);

#elif

#define CHECKPOINT(x)

#endif

 

CHECKPOINT(flag);

 

 

The code fragment:

 

 

 

 

 


Extra Credit questions

 

Use the the following code fragment to answer the next questions

int chair( int cushion, int pin) {

      if (pin >=10) {

                              printf(“No more bowling for dollars.”);

                              return 100;

      }

      else {

                              printf(“Accumulating value”);

                              return (int) cushion*(pin/10) * chair(cushion,(pin+1));

      }

}

 

XC1.   Which of the following is NOT true about the code above?                                          {2}

 

A)  It is recursive

B)  It uses a selection structure

C)  It has a computed loop in it

D)  It returns an integer

 

XC2. What value is returned to the main routine from chair if the main routine calls the function above as chair(50,9)?                                                                                                   {2}

 

A)  45

B)  450

C)  100

D)  4500

 

XC3.   Which of the following would not be a characteristic of software quality?               {2}

 

A)  Complexity

B)  Reliability

C)  Portability

D)  Maintainability

 

XC4..  List two C library functions (other than sqrt), the type of error information they return, and at least one error that can be indicated by the error information.         {4}

 

Library function

Error info type

Example of an error that can be indicated

sqrt

errno

errno = EDOM means a domain error (a negative input)