19.    Given the code definitions:
struct courseRec {
string course;
int credits;
nodeRec* next;
};
nodeRec *listTop, *nodePtr;

used to create the following list:

Write the C++ code to do the following (declare any necessary variables):

a.  Copy the credits field from the second node to the credits field in the first node (3 pts).

b.  Create a new node containing the course "CS208", with 3 credits, and a NULL pointer (3 pts).

c.  Insert the new node into the list as the first node in the list (3 pts).

d.  Write a function to count the number of nodes in a list of this type (again, unknown length)
and pass back the integer result (5 pts).

20.  Using the node declaration:

struct nodeRec {
int data;
};

a.  Given the above node and variable definitions, and the code:

for (int count = 5; count <= 26; count += 7)
{
ptr = new nodeRec;
ptr->data = count + 1;
}
What list does the above code create?  (3 points)

b.  Using the above node and variable definitions, suppose the following linked list was built:

What is output by the code (3 pts):

while (ptr != NULL) {
if ( (ptr->value % 2) == 0 )
cout << ptr->value << "  " << endl;
}

21. Given an stack of integers that starts out empty, the following operations are performed:

int x, y;
stack.push(8);
stack.push(4);
y = stack.top();
stack.push(6);
stack.push(3);
stack.pop();
x = stack.top();

What are the values of x and y?  (3 pts)

22. Given:

class foo
{
private:
int data;
string description;
public:
int a (int num);
void b (foo f) const;
};

void c ();
int d (int value);

Of the four functions defined above, which can alter the private member variables of the a foo object? (3 pts)

23. Given:

enum babyShoes {INFANT, BABY, TODDLER};
const int NUM_TYPES = 3;
const int NUM_SIZES = 5;

int numInStock [NUM_SIZES][NUM_TYPES];

The numInStock array holds the number of shoes in stock, by size and type.
So each cell will hold the count for one particular type, in a particular size.
Assume sizes go from 0 to 4.

Using the enumerated type values in your code, write the C++ code to store the fact that the store has 56 pairs of size 3 toddler shoes in stock. (3 pts)

Excellent Solution
================

## Write a review  