1/59
Course-backed recall cards: definitions, lists, access rules and tiny C++ syntax. Say the answer before flipping and mark misses. Masks use unsigned x and a valid index k, with index 0 at the right. Use the paper quizzes for full code, reasoning and traces.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Four pillars of OOP
Inheritance, polymorphism, data abstraction, encapsulation.
Three forms of polymorphism in CS341
Virtual members, name overloading, operator overloading.
Abstract data type (ADT)
A collection of data and a set of operations on that data.
Data structure
An implementation of an ADT in a programming language.
Abstraction
Separate what something does from how it is implemented.
Encapsulation
Combine data and operations in a class and control access to the internal data.
Inheritance
A derived class gains a base-class relationship and its accessible members.
Polymorphism
A common interface, function name or operator supports different forms or implementations.
Virtual members
Virtual functions support run-time dispatch through a base-class pointer or reference.
Name overloading
Same function name, different parameter lists. Return type alone is not enough.
Operator overloading
The same operator has different implementations for different operand types.
Static polymorphism
Selection normally occurs at compile time; examples include name and operator overloading.
Dynamic polymorphism
Run-time selection of an overridden virtual method according to the actual object.
Abstract class
Has at least one remaining pure-virtual requirement; cannot be instantiated directly.
Pure abstract class
Course term for an interface whose behavioral operations are all pure virtual.
Concrete class
Has no remaining pure-virtual requirements and can be instantiated.
Pure virtual method: C++ declaration
virtual void walk(void) = 0;
Declaration
Announces an entity and its interface; a function declaration need not supply a body.
Function definition
Supplies the function's implementation body.
Header versus source in this course
.h usually declares methods; .cpp defines them. Headers can also contain inline definitions.
Three inheritance modes in CS341
Public, protected, private.
Default inheritance for a C++ class
Private: class Child : Base uses private inheritance.
Public inheritance: public/protected base members
Public remains public; protected remains protected.
Protected inheritance: public/protected base members
Both become protected in the derived class.
Private inheritance: public/protected base members
Both become private in the derived class.
Base-private members in a derived class
Not directly accessible to ordinary derived-class methods; still exist in the base subobject.
Base/derived construction order
Base then derived: BD.
Base/derived destruction order
Derived then base: DB.
Can a constructor be virtual?
No. C++ constructors cannot be virtual.
Why use a virtual base destructor?
To safely delete a derived object through a base-class pointer.
Immutable
Cannot change.
Mutable
Can change.
C++ keyword for the ordinary immutability promise
const.
const after a member-function parameter list
The function cannot modify the object's non-mutable direct state through this.
Create a heap Student through pointer student
Student * student = new Student();
Does Student * student; allocate a Student?
No. It only declares a pointer; it does not construct a Student object.
Cleanup for a single heap object
delete student; invokes its destructor and releases the allocation.
Cleanup for an array allocated with new[]
delete [] values; use array delete for an array allocation.
new
Allocates storage and constructs the object; returns a pointer.
nullptr
A null-pointer literal. Assigning it to a pointer does not delete the previous allocation.
Shallow copy of an owning pointer
Copies its address, so both objects refer to the same allocation.
Deep copy of owned data
Allocates independent storage and copies the contents.
Copy-constructor declaration for Snoopy
Snoopy(const Snoopy & other);
Why pass a copy-constructor source by reference?
To avoid recursively copying the argument; const prevents modifying the source through that reference.
Six traditional Makefile components
Comments, Rules, Dependency Lines, Shell Lines, Macros, Inference Rules.
Makefile comment
Begins with #; the rest of that line is comment text.
Makefile rule
A target/prerequisite line plus any associated shell commands; specifies what to build and how.
Makefile dependency line
target: prerequisites
Makefile target
The item to build or action to run; appears LEFT of the colon.
Makefile prerequisites (dependencies)
Inputs needed by the target; appear RIGHT of the colon.
Makefile shell line (recipe)
A command below a dependency line; ordinarily starts with a literal TAB.
Makefile macro
A named value, e.g. CXX = g++; expand it with $(CXX).
Makefile inference or pattern rule
A general build pattern, e.g. %.o: %.cpp, with a compilation command.
Bitwise &
AND: a result bit is 1 only when BOTH corresponding input bits are 1.
Bitwise |
Inclusive OR: a result bit is 1 when AT LEAST ONE corresponding input bit is 1.
Bitwise ^
Exclusive OR (XOR): a result bit is 1 when the corresponding input bits DIFFER.
Bitwise ~
One's complement: invert every bit within the type's width.
Bitwise <<
Left shift: shifts bits left by the specified number of positions.
Bitwise >>
Right shift: shifts bits right by the specified number of positions.
Four mask operations (unsigned x, valid right-index k)
mask = 1u << k; CHECK: (x & mask) != 0; SET: x |= mask; CLEAR: x &= ~mask; FLIP: x ^= mask. Index0 is rightmost.