You should be able to define or explain the following terms:
data structure
algorithm
scope of a variable
differences between passing a value, an array and a pointer to a function
object oriented programming and its major properties (e.g., abstraction,
modularity, reusability, encapsulation)
class
instance of a class (i.e., object)
function call stack
the heap
inheritance, is-a relationship
base class, derived class (a.k.a., parent class, child class)
polymorphism
pseudocode (both interpreting and writing)
You should be familiar with all aspects of basic C++ programs,
such as those you created for labs 01 and 02. This includes:
how to compile and execute C++ programs
the int, float, char, bool, string data types
variables, assignment with =, and basic arithmetic
boolean and relational operators in C++
if / else if / else statements,
while loops, and for loops
variables, including their declaration, definition, and use
functions, including their declaration, definition, and use
arrays (statically and dynamically allocated)
basic uses of cout and cin
basic uses of file streams (mostly ifstream)
purpose of #include and using namespace std;
void and its use
pointers, dereferencing, nullptr
dynamic memory management with new, delete and delete[]
classes, including their declaration and implementation as well as the
use of access control: public and private member variables, methods, constructors, destructors
C++ inheritance
virtual, pure virtual functions, and abstract classes
dot notation and arrow notation
tracing a program using a memory/stack diagram (heap and stack)
Practice problems
Write a C++ program that prompts the user for an integer n
and then prints a single output integer, the sum of the integers from 1
to n.
Write a boolean function isPrimaryColor that takes a string as an
argument and returns true if the string is "red", "yellow", or "blue", and
returns false otherwise. Then write a program that prompts
the user for a color and uses isPrimaryColor to determine if
their color is primary.
Consider the code in
examples/week-03/destructor/safeArray.cpp. Draw the stack diagram caused by the execution of the following code
myarray.setElement(7,15);
just before the "unsafe operation" performed by the code.
Include the stack and the heap.
Write a Shape abstract class with the following features:
appropriate public getColor(), setColor()
and print() accessor functions. These should be pure virtual functions.
Then write a Rectangle subclass of Shape with the following
features:
a private color (a string) data member
a private length and width (both int) data members
a constructor which takes a color, length, and width, which
it uses to initialize the data members.
accessor functions: getArea() and print(). print should output the area and color of the Rectangle, e.g. "Rectangle with area 20. Shape with color black."
Finally, write a main() function that declares a pointer p
to a Shape, creates a single Rectangle on the heap and saves the pointer to that Shape as p, and then prints the
Shape and releases its memory.