You should be able to define or explain the following terms:
- data structure
- algorithm
- scope of a variable
- copy by value, copy by reference
- class
- instance of a class
- function call stack
- the heap
- inheritance
- base class, derived class, superclass, subclass
- polymorphism
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, and string data types
- variables, assignment with =, arithmetic and boolean expressions,
- if / else if / else statements, while loops, for loops
- variables, including their declaration, definition, and use
- functions, including their declaration, definition, and use
- arrays
- basic uses of cout and cin
- #include and using namespace std;
- void and its use
- pointers
- dynamic memory management with new and delete
- classes, including the declaration and implementation of
public, private, and protected data members and functions
- base and derived classes
- static_cast<TYPE>(VALUE)
- make (but not the details of Makefiles)
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.
- Draw a memory diagram for
cs35/inclass/w02/inheritance/testPerson.cc as it executes.
Include the stack and the heap.
- Write an Animal class with the following features:
- private type (a string) and weight (a float) data members.
- a constructor which takes two appropriate parameters, which it
uses to initialize the type and weight of the Animal.
- appropriate public getType(), getWeight(),
and print() accessor functions
Then write a Pet subclass of Animal with the following
features:
- a private name (a string) data member
- a constructor which takes a type, a name, and a weight, which
it uses to initialize the type, name, and weight of the Pet
- appropriate public getName() and print()
accessor functions, such
that the Pet print() function will be executed when a
Pet-as-Animal's print() function is called.
Finally, write a main() function that declares a pointer p
to an Animal, creates a single Pet on the heap and saves
the pointer to that Pet as p, and then prints the
Pet and releases its memory. (For my inadequate representation,
I heartily apologize to anyone with a pet rock...)