Show Menu

C++ Midterm 4 CS1410 Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Class Relati­onships

Class Relati­onships

all but associ­ation
can change after instan­tiation
aggreg­ation, depend­ency, associ­ation
cannot change after instan­tiation
inheri­tance, compos­ition
which relati­onships must be created when objects instan­tiated: (have shared lifetime)
inheri­tance and compos­ition
which relati­onships can be created at any convenient time (indep­endent lifetimes)
aggreg­ation, depend­ency, associ­ation
allow sharing some related objects
aggreg­ation, depend­ency, associ­ation
exclusive (no sharing)
inheri­tance, compos­ition
"is a" "is a kind of"
"has a"
aggreg­ation, compos­ition, associ­ation
aggreg­ation, compos­ition
implem­ented with dedicated computer syntax or keyword
add features to an existing (general) class without having to rewrite it.
class Foo: public Bar


A C++ stream is a flow of data from one place to another.
three stream classes commonly used:
ifstream, ofstream, fstream
ofstream sales(­"­SAL­ES.J­UN­");
output file associated with SALES.JUN
put what's in variable 'ch' in fileOut (an ofstream thing)
char s[100];­tli­ne(s, 100);
string s; getlin­e(cin, s);

Q27 ch12

delta, alpha, beta, gamma - this is the order they have to be in.


Five requir­ements: 1. inheri­tance 2. function overriding 3. up casting 4. a virtual function 5. a pointer (usually) or reference variable
virtual functions allow you to use the same function call to execute member functions of objects from different classes
deciding what function call executes after a program starts is polymo­rphism
pure virtual function
virtual void dang() = 0;
it causes it's class to be abstract and it is in the super class
an abstract class is useful when no objects should be instan­tiated from it.
An abstract class can: be a base (parent or super) class have concrete features (both variables and functions) that can be inherited by derived (child or sub) classes partic­ipate in (i.e., be the target of) an upcast partic­ipate in polymo­rphism
Object oriented model: inheri­tance, encaps­ula­tion, & polymo­rphism
overloaded function: Are defined in the same class Must have unique argument lists May have different return types
overridden functions: Are defined in two classes that are related by inheri­tance Must have the same name Must have exactly the same argument list Must have the same return type


Defa­ult: foo() no arguments
foo f1; or foo* f2 = new foo;

Conv­ers­ion: foo(int i) one argument to be turned into the class object
foo f1(3); or foo* f2 = new foo(3);

Gene­ral: foo(int x, int y) anything with more than one
Copy: foo(f­­oo& f) pointer argument
Move: foo(f­­oo&& f) double pointer

Chap 12 stuff

a)order is not signif­icant, follow the pattern: member­-na­me(­arg­ume­nt-­name)
b) must initialize inheri­tance first, this is a function call so the number, type, and order of the parameters must match the number, type, and order of the arguments in the function defini­tion: class-­nam­e(p­ara­met­ers), member­(ar­gument)
c) order is not signif­icant; must use the second argument to access the members
d) the general pattern is class-­nam­e::­fun­cti­on-­name()

first part

second part


When creating a template function, the template argument or variable is preceded by the keyword
When creating a template class, it's the same ^
The template class works with different datatypes.
Template source code is placed in a header file so that it can be included with "­nor­mal­" source code where it is compiled following the type expansion or substi­tution. (There can be more than one template argument)
When a class is "­tem­pla­tiz­ed" all member functions are placed in the header file: the functions can't be compiled until the templi­tized variable is expanded. So it can't be in a regular library
template <class T>

class FooBar
correct beginning of an operation called Foo:
template <class T>

while (true) CList<­per­son­>pe­ople; ... 
wrong because it creates a new list every time it loops.