Midterm Exam, CSCI 330, Spring 2021


  1. Recursion
    1. [6 points] A successful recursive function should have three properties. List them.
    2. [5 points] Write a recursive function that takes a pointer to a standard linked list and prints that list out in order. The list is constructed from NodeT and DataT has the stream insertion operator implemented.
      struct NodeT {
         DataT data;
         NodeT * next;
      };
  2. Dynamic Memory
    1. [12 points] A class containing dynamic memory must have three additional methods.
      • Name each
      • Describe when each is called.
      • Describe what each must do
      • Describe the parameters to each and how they should be passed.
    2. [10 points] Write a function that takes a pointer to the head of a linked list and returns a copy of this list. This list is constructed from tye type NodeT.
      struct NodeT {
         DataT data;
         NodeT * next;
      };
  3. Standard Library
    1. [2 points] What is an iterator and what is it used for?
    2. [5 points] Write a program that reads in the words stored in a file words.dat and prints them in alphabetic order. A word is a series of characters surrounded by whitespace. You should employ the standard library.
  4. Exceptions
    1. [2 points] What is an exception? When should an exception be thrown.
    2. [4 points] Write a function which takes two integers a numerator and denominator and divides the numerator by the denominator. If the numerator is non-zero and the denominator is zero, throw a domain error. If both the numerator and denominator are zero, it should throw a out_of_range error.
    3. [4 points] Write a segment of code that calls the function written in the previous section. It should catch and handle all possible exceptions individually.

Submission Instructions