Sample Test 1CS / SE 2630

60 points

6) 1. What is the value of each, assuming: char b, *p, s[8] = "FRAGILE" ;

______a) What is the value of the expression: *(s + 1) + 1

______b) What is the value of the expression: *s - 1

______c) What is the value of b after: p = s + 7; b = *--p;

(4) 2. Name the Big 3 and give the major reason why one needs to have these defined.

(4) 3. What goes on in a code inspection? List at least three roles that people play in an inspection.

(11) 5. Create a TWord class that has two private fields: length, specifying the length of the word

and: char * word. Provide 4 methods: a default constructor that sets word to NULL and the BIG 3. Write the bodies for the default constructor, destructor, and copy constructor inline, even though the copy constructor is 2 lines long. Write the body for the operator= below the class declaration. You can use any functions from string.h.

(11) 6. Write a template version of the Queue class. Write all the bodies inline even if they are multi-line. Use the circular array method to implement the Queue. Use a value returning Remove function. Make sure to have front, rear, count, and an array called elements. Make sure to have Add, Remove, IsEmpty, and IsFull methods and a default constructor. The template has two parameters, one a class named ItemType and the other an integer named MAXQ.

(10) 7. Assuming a Vector class defined below:

(2) a) finish the declaration for operator+

(2) b) finish the declaration for operator<

(6) c) write the body for operator+ underneath the class declaration, assuming that the "sum" is the

component-wise addition of the private arrays. Sum all SIZE elements.

class Vector

{

public:

Vector operator+ ( ______

friend ostream & operator< ( ______

private:

enum { SIZE = 10 };

double v[SIZE];

};

Use the following for the next page:

struct Node

{

InfoType info;

Node * next;

Node ( InfoType x, Node *p = NULL ) { info = x; next = p; }

};

Node * list;

(14) 8. Using the declarations on the preceding page, write C++ code segments

to (make sure to free any storage that is deleted):

(2) A. Add val (of InfoType) to the front of the linked list pointed to by list.

(3) B. Remove the front node of the linked list pointed to by list. If the list is empty, do nothing.

(4) C. Remove the second node in the list pointed to by list. If there are less than two nodes, do nothing.

(5) D. Add val (of InfoType) to the end of the linked list pointed to by list. Handle the empty list case!