Major CS162 topics:
You are almost guaranteed to see questions on each of these:
Objects, Composition & Aggregation
At least one question will ask you to write a class using composition or aggregation. You should be prepared to distinguish between the two and/or select the appropriate technique based on description of the behavior we want to see.
Pointers, Stack and Heap
You will be asked to diagram memory (stack/heap) as well as reason about whether memory code is leaking or accessing bad pointers.
Container Classes
You will be asked to write code working with an array based container class (like ArrayList, etc…). Be prepared to write memory related code: constructor/destructor/copy constructor/assignment operator. Also be prepared to implement other functions on an array based container class.
Inheritance, Polymorphism & Virtual Functions
Be ready to write code/reason about:
- Inherit from an existing class and use its constructors/functions to help implement subclass
- Which version of a function will be used based on calling situation (pointer or object), type of function (virtual or not)
- Pure virtual (abstract functions)
- Type conversions and inheritance. What happens if I try to:
- Copy a Circle c into a Shape ( Shape s = c; )
- Copy a Circle* c into a Shape* ( Shape* s = c; )
- Copy a Shape s into a Circle ( Circle c = s; )
- Copy a Shape* s into a Circle* ( Circle* c = s; )
- What is the proper way to take a Shape* and check to see if it actually points to a circle?
Recursion
Implement a recursive solution to a problem involving an array, string or mathematical recipe.
Templates
Implementing a templated function or class.
Secondary topics:
One or more may appear, but you probably won't see all of them
Operator Overloading (Other than assignment operator)
Implementing a member or non-member binary operator.
Exceptions
Properly catch a possible exception, throw an existing type of exception (like out_of_range). Most likely as a secondary part of another question
Sample Questions On Topics From Second Half of Course:
1) A Path consists of a list of Point structs. The list is allocated dynamically to match the length of the path. The size of the array will always match the number of Points being stored (will not have empty or unused elements in the array).
struct Point {double x;
double y;
Point(double xVal, double yVal);
bool operator==(const Point& other) const;
};
//bodies / class Path {
private:
//keep track of array of Points
Point* points;
int numPoints;
public:
Path(int numberOfPoints);
void addPoint(const Point& p);
... more stuff here ...
}
a) Write an assignment operator (.cpp code) for Path.
b) Write a destructor for Path.
c) Write the addPoint function. It should add the new point to the end of the list. If must allocate a new storage array large enough to hold the existing points plus the new one being added.
2) Write a templated function that will take an array and its size and return the largest item (according to >) in the array.
3) Write recursive functions that do the following:
a) Sum up the items in an array of ints:
int sum(int nums[], int size);
b) Reverse a string. reverse(“foo”) should result in “oof”.
string reverse(string s);