Review
Using & understanding streams
Why is extraction from an input stream (operator>>) more error prone than insertion into an output stream (operator<<)?
Separate Compilation
What is the One Definition Rule (ODR)?
What are the exceptions to the ODR?
What are the exceptions to the exceptions?
What is the difference between a definition and a declaration?
Why do we need header files?
Give an example of something that shouldn't be placed in a header file. Explain why.
What is the job of the compiler? The linker?
Functions
How are value and reference parameters different? Describe the advantages and disadvantages of each.
How are inline functions different from regular functions?
What is overloading? Give an example. Why doesn't this violate the ODR?
Write a template function that initializes an array of any type with any fill value. The array, fill value, and array length are your parameters.
Write a function that returns the largest number in a file. The file name is your parameter.
Write a control loop that prompts the user for an infix expression of the form N + M, N * M, N – M, or N / M where N and M are doubles. The control loop evaluates the expression, then prints the result.
Write a template function that receives two arrays of any type, and their lengths, and returns a pointer to a new array made by concatenating the arrays.
Objects
All monsters have names and they chase heroes. Heroes have names and they fight monsters. There are two types of monsters: biters and spitters. Biters bite heroes, spitters spit poison at heroes. Draw a UML class diagram showing the relationships between heroes, monsters, biters, and spitters. Implement your class diagram in C++. (Include constructors.) For now member functions should merely print something entertaining.
Suppose we want to keep track of the total number of monsters. What changes would you make to the monster class?
Monsters live in caves. When a hero enters a cave, each monster in the cave chases him (or her). Implement a cave class. You should supply an addMonster() function and an enter() function. Also, if c is a cave, then c[i] should return the ith monster in the cave.
What are some differences between member functions and global functions?
An instance of the Dollar class represents an amount of money in US dollars. It consists of an integer number of dollars and an integer number of cents, where:
0 <= dollars
0 <= cents < 100
Implement the Dollar class so that the following client code runs:
Dollar d(3, 75); // d = $3.75
Dollar e(4, 50); // e = $4.50
Dollar f(2); // f = $2.00
Dollar g; // g = $0.00
g = d + e + f;
cout << g << '\n'; // prints $10.25