A+ Answers

1.    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).
2.  Using the node declaration:
                        struct nodeRec {
                                    int data;
                                    nodeRec* link;
                        nodeRec *head, *ptr;
            a.  Given the above node and variable definitions, and the code:
            What list does the above code create?  (3 points)
                        (Sample format for answer:    head à 86 à 31 à NULL)
            b.  Using the above node and variable definitions, suppose the following linked list was built:
            What is output by the code (3 pts):
3.         Given an stack of integers that starts out empty, the following operations are performed:
                        int x, y;
                        y = stack.top();
                        x = stack.top();
            What are the values of x and y?  (3 pts)       
4.         Given:

    class foo



        int data;

        string description;


         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)

5.         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)