Fall 2002 Final Exam

CSE1320                                                                                                         Sections 003 and 501

Tuesday, December 10, 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 the last four digits of 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.   You may not rely on the textbook, your notes, other supporting materials or the contents of someone else’s test.

 

You may fill in the blanks on this page but

DO NOT begin the test until Dr. Tiernan indicates

that you may do so.


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

 

1.   C has built-in capabilities for

A)  linked lists

B)  boolean types

C)  dynamic memory allocation

D)  functon name overloading

 

 

 

2.   Which of the following is true?

A)  Anything you can program in C++ can be programmed in C

B)  C++ extends C to provide support for object-oriented programming

C)  C libraries are not available in C++

D)  C++ is a subset of C

 

 

 

3.   Fill in the blank                                                                                       {12 points total ; 2 each}

i)    In C++, the property that is used when a more general or higher level class is used as the basis for one or more specific classes                                                        

ii)   In C++, the ability to reuse function names and operators with different parameters                                                                                                                                                                                                                                                                                                                                                                                                                       

iii)  In software engineering, the phase in which the program designer (you) documents how the program will meet the user’s stated needs                               

iv) In C and C++, the part of the language implementation which allows you to reuse code                                                                                                                                                                                                                                                                          

v)  The type of data structure where the last element to go in is the first element to go out                                                                                                                                                                                                                                                                            

vi) In C, the system defined value which will indicate the specific type of error that has occurred                                                                                                               

 


4.   Give short answers in complete sentences to the following: {6 pts each}

A)  Define data abstraction as used in C++

 

 

 

 

 

 

 

 

 

 

 

B)  Explain why random jumps in coding (goto’s) should be avoided and what constructs allow us to write code without goto’s.

 

 

 

 

 

 

 

 

 

 

 

C)  Describe software quality giving at least three characteristics of good quality software.

 

 

 

 

 

 

 

 

 

 

 

D)  Describe the following in words:

                          void *(* putty(double, double, int))(char, float)

 

 


5.   Write a function to implement the quadratic formula:                                                       {10}

 

                                                y =                                                                                 

 

      The input parameters should be a, b, c, and two pointers to double which will be assigned by the function to the two roots found by the quadratic equation. Your function must use at least two built-in math functions from the C library. Your function should return 1 if the equation was able to be solved properly or 0 if the formula could not be solved with the given inputs.

 

 

 


6.   Given the code fragments below, describe what the code does, what type of structure is implemented, where new elements are added, where elements are removed, and a example of where such a structure might be used (i.e. give an application or problem where this structure would be useful)                          {11}

 

struct node {

      char name[25];

      int stats[10];

      struct node *prev; *next;

} *first, *last, *next_up, *new;

 

/* Assume valid C functin definition and code here */

/* Loop to build list */

/* Assume space is allocated for new, data read into its structure, and pointers set to NULL */

if (first == NULL) {

      first = new;

      last = new;

      }

else {

      new -> next = first;

      first -> prev = new;

      first = new;

      }

/* End of loop to build list */

/* Loop to remove list elements */

while (last != NULL) {

      printf(“%s %d %d\n”,name, stats[0], stats[1]);

      last = last->prev;

      free (last->next);

      last->next = NULL;

      }

printf(“No more elements in list”);

/* end of remove */

 

This code fragment                                                                                                                              

                                                                                                                                                                 

The structure is:                                                                                                                                    

                                                                                                                                                                 

Elements are added:                                                                                                                             

Elements are removed from:                                                                                                               

An application would be:                                                                                                                   

                                                                                                                                                                 


7.   Convert the C++ code below on the left to C code in the space on the right that performs the same function in the same way.                                                             {12}

 

bool func(int&, int x=10, int y=25);

main()

{

bool res;

int test, use1, use2;

cout << “Please enter an integer test value”;

cin >> test;

char entry;

cout << “Do you wish to enter values

      for x and y? Y/N”;

cin >>entry;

if (entry == ‘Y’) {

      cout << “Please enter an x value

and a y value seperated

by a comma”;

      cin >> x ;

      cin >> entry;

      cin >> y;

      res= func(test, x, y);

      }

else res = func(test);

if (res)

      cout << “func returned” << test;

else

      cout << “func returned a false values”;

}

 

bool func(int& k, int x, int y)

{

if (y ==0)

      return FALSE;

else {

      k = k * (x / y);

      return TRUE;

      }

 

}

 

 


8.   Write a function to implement the sort described below. Use the following function definition given for the sort.                                                                                    {15}

 

      int sort(int *array, int start, int end)

 

      The variable array is a pointer to the beginning of an array of integers to sort. The variable start indicates the starting element index for the sort and end gives the ending element index for the sort. The sort function should be implemented recursively as follows and will sort from smallest to largest.

 

      If there are two (2) elements, one (1) element, or zero elements in the array then there are two cases. For two elements, compare them and if the first is larger than the last, swap them. After this possible swap or when there are only 1 or 0 elements, return from the function. If there are more than 2 elements in the array then the sort function should call call another function called findmid. It should save the return value of findmid in a variable mid and then make two recursive calls to sort. The first recursive call should pass in array, start, and mid – 1. The second recursive call should pass in array, mid + 1, and end.

 

      You do not have to write the function findmid. You may assume it exists and that it’s function prototype declaration is:

 

      int findmid(int *array, int start, int end);

 

      The function findmid returns an integer that is the index value of the pivot point. The pivot point is the location in the array such that all elements below it have smaller values and all elements above it in the array have larger values. Write the function sort as defined above.

 


9.   Answer the questions below using the C++ code given.                                                     {8}

 

class x: public abc {                                                                                                                      Line 1

public:

      x();

      x(char desig, int val, char flag=’Z’, int count=0);

      ~x();                                                                                                                                         Line 2

      void disp();

private:

      int two;

      char three;

      int four;

}

 

x::disp() {

cout << one << two << three << four;

}

 

A)  What property is demonstrated in the class definition in Line 1?

 

 

 

 

 

 

B)  What data member definition (type and name of variable) would you expect to see in the data part of abc?

 

 

 

 

 

 

C)  What do we call a function like ~x in Line 2?

 

 

 

 

 

 

D)  If an object is created with x newx((‘A’ + 1), 0), what will be printed from newx.disp()?

 

 

 

 


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

 

XC1.   Which of the following is NOT a library function in C?

 

A)  time()

B)  ctime()

C)  timeval()

D)  localtime

 

XC2.   Which of the following would NOT be used for conditional compilation?

 

A)  #define

B)  #else

C)  #if

D)  #include

 

 

XC3.   Which of the following is NOT related to testing?

 

A)  debugging

B)  glass box

C)  retirement

D)  black box

 

XC4.   The operator << is:

 

A)  the bit shift right operator

B)  the stream insertion operator

C)  the double indirection operator

D)  an odd emoticon

 

 

XC5.   Write a haiku or a short poem (3 lines or less) to describe the feelings you will have when this class is over.                                     [ANY answer will receive 2 points]