Please answer each question thoughtfully and carefully.
Please use a word processor to answer the questions.
Please label your answers with the question number and part.
Please answer each question thoughtfully and carefully. I expect your answers to demonstration participation in this class.
You may use books, notes and other non-human references. You may not interact with any other person when answering these questions.
Proper use of terminology will be graded.
The test is due at the end of class.
Submission instructions are at the end of the test.
Submissions should be done through the D2L assignment folder Test 1
If you have problems submitting the test, please contact your instructor.
If you have questions, please communicate with your instructor via email.
Recursion
[6 points] A successful recursive function should have three properties. List them.
[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;
};
Dynamic Memory
[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.
[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;
};
Standard Library
[2 points] What is an iterator and what is it used for?
[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.
Exceptions
[2 points] What is an exception? When should an exception be thrown.
[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.
[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
Submit your test and the source code for the program to the D2L assignment folder Test 1 by 10:45.
If you miss this deadline, you can submit your test by email to dbennett@edinboro.edu. Depending on the circumstances, there may be a 5% penalty per minute applied for email submissions.