Lessons - 3003
C++
Unit 1: Entry-Level / Review / Tutorials
Week 1 8/23-25 Essentials
Course overview, Relevant programming environments and tools, especially in the context of software engineering
Learning Outcomes
What an IDE is
How to install and configure your IDE
What programming tools you can use during this course
Build tools
Discussion / Mindfulness
Introduction
OpenEDG
Register
Part 1 - Module 0
Installing and setting up programming environment
Read slowly and carefully, take notes
Exam Topics
Tutorial / Practice Activity
Readings
Lesson
Ice breaker
Age - differences
Location - study, carpool
Number of courses this semester - time commitment
Hours of work - time commitment
Planned major / minor
Level of comfort
Course and assignments overview
Certification benefits and options
Success strategies
Grit
Growth Mindset
Time management / Outlook Calendar
Sign in to browser
OpenEDG (see above)
Sign in to One Drive - video
Textbook / Resources
Programming environments and tools
Mindfulness
Engage with next module resources before next class every week
Week 2 8/30-9/1 Basics Review
Programming Concepts and API / frameworks / libraries / packages
Learning Outcomes
the difference between machine and high-level languages;
the machine code and compilation;
variables, integers, characters;
comments;
the basics of flow control;
dealing with streams and basic I/O operations;
writing simple programs.
Discussion / Mindfulness
OpenEDG
Part 1 - Module 1. Introduction to computer programming
Topics
1.1 Different languages for different purposes
1.2 Your first program
1.3 Integer values, integer variables and comments
1.4 Numbers and their operators
1.5 Other kind of data: characters
1.6 Flow control: how to make simple decisions?
1.7 Connecting with the real world: input and output
Assignments
Module 1 Quiz
Module 1 Test
Exam Topics
Absolute basics
machine and high-level programming languages, compilation process,
obtaining the machine code: compilation process,
writing simple programs,
variables,
integers: values, literals, operators,
characters: values, literals, operators,
dealing with streams and basic input/output operations
Tutorial / Practice Activity
Walkthrough: Create a traditional Windows Desktop application (C++)
Requires Universal Windows Platform development workload, see Visual Studio page for details
Readings
Chapter 2 C++ Basics: Functions and Files
Chapter 3 Debugging C++ Programs
Chapter 4 Fundamental Data Types
Chapter 5 Operators
Resources
C++ for Complete Beginners videos (watch as needed)
Introduction to number systems and binary (10:00) Khan Academy
Header files (4:38)
API wikibooks
Windows API wikipedia
Web APIs - Introduction w3schools
Lesson
Grit and Growth Mindset
OpenEDG and Reading Review
Poll
A namespace is an abstract container or environment created to hold a logical grouping of unique entities (blocks). A namespace is a region that allows you to declare names inside of it for the purpose of disambiguation. The namespace provides a scope (called namespace scope) to the names declared inside of it -- which simply means that any name declared inside the namespace won’t be mistaken for identical names in other scopes.
Avoid using directives (such as using namespace std;) at the top of your program.
Functions: arguments, parameters (image), scope illustration, benefits, ordering and prototypes,
Number systems, bits, bytes (Bit manipulation and converting between number systems next week)
Variables (descriptive names, declaration (close to use), assignment, initialization, concept, state diagram), data types, operators
Be sure to use your editor’s auto-formatting feature to keep your formatting consistent and make your code easier to read. Visual Studio: Hold down the Control key and then press K, followed by D.
Errors and debugging
Don't use magic numbers (numbers without context)
mod, unary, conditional. logical
Make a program - meal, tax, and tip
IPO, flowchart, pseudocode
Variable declaration: int a = 20; int myint(3.14); int myint1{3.14};
Function, prototype, header file
Debug it with breakpoints
APIs
Resources above
Create a traditional Windows Desktop application (C++) or work on project or HackerRank
Week 3 9/8-13 - Flow control and data aggregates
More data types
Learning Outcomes
how to control the flow of the program;
more data types;
conditional instructions: if, else, switch;
loops and controlling the loop execution;
logic, bitwise and arithmetic operators;
vectors, multidimensional arrays;
declaring and initializing structures.
Discussion / Mindfulness
Benefits of mindfulness
OpenEDG
Part 1 - Module 2. Advanced flow control and data aggregates
Topics
2.1 The conditional statement
2.2 More types and when we use them
2.3 Loops
2.4 Boolean algebra and computer logic
2.5 switch
2.6 Vectors
2.7 Initiators
2.8 Multidimensional arrays
2.9 Structures
2.10 Declaring and initializing structures
Assignments
Module 2 Quiz
Module 2 Test
Exam Topics
Flow control and more data types
how to control the flow of the program
floating point types: values, literals, operators,
more integer types: values and literals,
loops and controlling the loop execution,
logic, bitwise and arithmetic operators.
Tutorial / Practice Activity
Get started with C++/WinRT / Meet C++/WinRT 2.0 (through 8:45)
Readings
Resources
Meet C++/WinRT 2.0: Faster and smarter in the open (55:02)
Add C++/WinRT extension
You might need to update the NuGet Packages after right clicking project
Tools > NuGet Package Manager > Package Manager Console
Data structures cplusplus
Tag vs. Type Names explanation of "tag"
Lesson
Discussion Review
Previous tutorial review
Open from GitHub
Improve readme
OpenEDG and Reading Review
C++ provides 6 bit manipulation operators, often called bitwise operators
if / else - always use (), use a trailing else
switch - use default
arrays
arrays of arrays - table
structures - aggregate many different data types into one identifier
Hackerrank problem collaboration / demonstration Bitwise AND (in C++ 14)
Hackerrank contest problem Bitwise Operators (in C)
APIs
You don't need thorough understanding of them
OOP of the week: Make a struct diagram and code a struct
Week 4 9/15-20 Pointers, functions and memory
Parameter passing, dereferencing
Learning Outcomes
designing, declaring, and invoking functions;
pointers;
different methods of passing parameters and their purpose;
default parameters;
inline functions;
overloaded functions;
sorting;
memory on demand.
Discussion / Mindfulness
OpenEDG
Part 1 - Module 3. Extending expressive power: pointers, functions and memory
Topics
3.1 Pointers
3.2 Pointers vs arrays
3.3 Functions
3.4 Declaring and defining functions
3.5 Transferring data to and from functions
3.6 Default parameters
3.7 Inline functions
3.8 Overloaded functions
3.9 Sorting
3.10 Memory on demand
Assignments
Module 3 Quiz
Module 3 Test
Exam Topics
Functions
functions,
declaring and invoking functions,
side effects,
different methods of passing parameters and their purpose,
default parameters,
inline functions,
overloaded functions.
Tutorial / Practice Activity
Readings
Resources
Lesson
Discussion
Gratitude, one positive thing, mindfulness
OpenEDG and Reading Review
functions
different methods of passing parameters (value, reference, address) and their purpose
default parameters, inline functions, overloaded functions
Review / Muddiest Point Clarification
bitwise operators
struct
OOP of the week: Make a class diagram with methods
Blazor
Week 5 9/22-27 Data: Arrays of pointers and Conversion
Strings intro
Learning Outcomes
arrays of pointers;
conversions;
strings: declarations, initializations, assignments;
strings as an example of objects: (methods and properties)
using and declaring namespaces;
dealing with exceptions.
Discussion / Mindfulness
OpenEDG
Part 1 - Module 4. Accessing various kinds of data
Topics
4.1 Arrays of pointers
4.2 Conversions
4.3 Strings - the basics
Exam Topics
Accessing data and dealing with exceptions
converting values of different types,
strings: declarations, initializations, assignments,
Tutorial / Practice Activity
Blazor: Modify a project in Visual Studio
Readings
Resources
Lesson
Discussion Review
OpenEDG and Reading Review
pointers to pointers
A conversion is the act of changing the nature of the data without (if possible) changing the value. One of the simplest examples of conversion is a change of data type.
A string is a set of characters
Review / Muddiest Point Clarification
OOP of the week: private fields, gets and sets
Blazor
Week 6 9/29-10/4 Data
Strings as objects, namespaces, exceptions
Learning Outcomes
Integrate a class in a cpp file with private fields and public methods
Discussion / Mindfulness
OpenEDG
Part 1 - Module 4. Accessing various kinds of data cont.
Topics
4.4 Strings - continued
4.5 Strings - temporary summation
4.6 Name spaces
Assignments
Module 4 Quiz
Module 4 Test
Course 1 Summary Test
Exam Topics
Accessing data and dealing with exceptions
string as an example of object: introducing methods and properties,
namespaces: using and declaring,
dealing with exceptions
Tutorial / Practice Activity
Input/output with files: Writing operations and Reading from a file
In Visual Studio Solution Explorer you may need to click Show All Files
Readings
Chapter 22 std::string
Chapter 23 Input and Output (I/O)
Resources
Lesson
SA Updates - ShellHacks
Discussion Review (10 minutes)
Muddiest Point Clarification
HTML & CSS
IPO
Getters and setters (in OOP of the week)
OpenEDG and Reading Review (20 minutes)
std::string
namespaces
Input and Output (I/O)
Blazor + break time (60 minutes)
API example
In a Chrome tab signed in to Canvas -> three dots -> More tools -> Developer tools -> Console -> paste $.getJSON("/api/v1/courses", function(data) { console.log(data); });
Console application that writes to a file and reads from a file (20 minutes)
OOP of the week: private fields, public methods, review overload (15 minutes)
Work on Hackerrank exercises (20 minutes)
Unit 2: Intermediate / Associate Level / Independent Project
Week 7 10/6-11 The essentials of OOP
Modularity (classes and packages)
Learning Outcomes
LO1. Design and implement a class. [Usage]
LO4. Compare and contrast (1) the procedural/functional approach (defining a function for each operation with the function body providing a case for each data variant) and (2) the object-oriented approach (defining a class for each data variant with the class definition providing a method for each operation). Understand both as defining a matrix of operations and variants. [Assessment]
Discussion / Mindfulness
How?
It starts with breathing. The most basic way to do mindful breathing is simply to focus your attention on your breath, the inhale and exhale.
Mindful breathing Stop Breathe Think
OpenEDG
Part 2 - Module 1. The essentials of OOP
Topics
1.1 The basic concepts of OOP;
1.2 A stack: the procedural approach vs. OOP;
1.3 The anatomy of classes;
Exam Topics
Fundamentals of the object-oriented approach
class
objects
class components
constructors
Tutorial / Practice Activity / Project
Project Planning
Integrate a class with a constructor in a header file
Readings
Chapter 12 Basic object-oriented programming sections 1 - 5
Resources
Lesson
Discussion Review
Tutorial Review: readme and comments
Muddiest Point Clarification
OpenEDG and Reading Review
Subclasses / inheritance introduction
The long tail of the content vs. importance graph
Procedural vs object-oriented approach
A stack: the procedural approach vs. OOP
Code it and comment it
Class can contain full function definition or prototype
Put it in a header file
Briefly compare and contrast procedural vs. OOP in writing
OOP of the week: review overload, constructors and destructors
Find, design, and code a class you will use in your project
Visual Studio Class Designer - add component
Week 8 10/13-18 The essentials of OOP
Encapsulation
Learning Outcomes
LO6. Use object-oriented encapsulation mechanisms such as interfaces and private members. [Usage]
Discussion / Mindfulness
OpenEDG
Part 2 - Module 1. The essentials of OOP cont.
Topics
1.4 Static components;
1.5 Objects vs. pointers, and objects inside objects.
Assignments
Module 1 Quiz
Module 1 Test
Exam Topics
Fundamentals of the object-oriented approach
referring to objects
static members
classes and their friends
Tutorial / Practice Activity / Project
Integrate an initialization list
Integrate code that utilizes friend
Readings
Resources
C++ Encapsulation w3schools
Lesson
Discussion Review
OpenEDG and Reading Review
Composition - "has a" relationship
Pillars of OOP
Add class Date in a separate file
For classes used in only one file that aren’t generally reusable, define them directly in the single .cpp file they’re used in.
For classes used in multiple files, or intended for general reuse, define them in a .h file that has the same name as the class.
Trivial member functions (trivial constructors or destructors, access functions, etc…) can be defined inside the class.
Non-trivial member functions should be defined in a .cpp file that has the same name as the class.
Visual Studio right click Header Files, Add Class
Write a method to get date in ISO format
static - belonging to the class, not an object
Static Fields
Box count and Bank account examples
Static Function Members
Can be called even when there are no objects
Encapsulation is also called information hiding.
Friends
Friend function - can access the private members of a class as though it were a member of that class
Add Accumulator class to a program
Friend class - can access private and protected members of other class in which it is declared as friend
Practice question #15 class diagrams and state / memory diagram
Encapsulation definitions from SEVOCAB
(1) software development technique that consists of isolating a system function or a set of data and operations on those data within a module and providing precise specifications for the module (ISO/IEC/IEEE 24765:2017 Systems and software engineering-Vocabulary)
(2) concept that access to the names, meanings, and values of the responsibilities of a class is entirely separated from access to their realization (IEEE 1320.2-1998 (R2004) IEEE Standard for Conceptual Modeling Language Syntax and Semantics for IDEF1X97 (IDEFobject), 3.1.54)
(3) idea that a module has an outside that is distinct from its inside, that it has an external interface and an internal implementation (ISO/IEC/IEEE 24765:2017 Systems and software engineering-Vocabulary)
Week 9 10/20-25 Inheritance
Class hierarchies
Learning Outcomes
LO2. Use subclassing to design simple class hierarchies that allow code to be reused for distinct subclasses. [Usage]
Discussion / Mindfulness
OpenEDG
Part 2 - Module 2. Inheritance
Topics
2.1 Class hierarchies;
2.2 Classes, inheritance, and type compatibility
Exam Topics
Class hierarchy
base class, superclass, subclass,
inheritance: how it works,
types of inheritance,
inheriting different class components,
multiple inheritance.
Tutorial / Practice Activity / Project
Integrate inheritance
Readings
Resources
Lesson
Discussion Review
OpenEDG and Reading Review
Inheritance- "is a" relationship
Vocabulary: base / super / parent and derived / sub / child
public, private, and protected with members and classes in the visibility inheritance model
Public inheritance is by far the most commonly used type of inheritance.
Superclass pointer objects can hold references to subclass objects
static_cast and dynamic_cast (We’ll return to this issue soon.)
downcasting and upcasting
Multiple inheritance - causes more problems than it fixes.
Other inheritance info
Practice question #14 class diagrams and state / memory diagram
Week 10 10/27-11/1 Polymorphism
Virtual functions
Learning Outcomes
LO3. Correctly reason about control flow in a program using dynamic dispatch. [Usage]
LO5. Explain the relationship between object-oriented inheritance (code-sharing and overriding) and subtyping (the idea of a subtype being usable in a context that expects the supertype). [Familiarity]
Discussion / Mindfulness
OpenEDG
Part 2 - Module 2. Inheritance cont.
Topics
2.3 Polymorphism and virtual methods;
2.4 Objects as parameters, and dynamic casting;
2.5 Various supplements;
2.6 The const keyword;
2.7 Friendship in the C++ world.
Assignments
Module 2 Quiz
Module 2 Test
Exam Topics
More on classes
polymorphism: the notion and the purpose,
virtual methods: declaration and usage,
inheriting virtual methods,
abstraction and abstract classes.
Tutorial / Practice Activity / Project
Milestone 1
Integrate polymorphism
Readings
Resources
Polymorphism cplusplus.com
C++ virtual function javatpoint.com
Lesson
Discussion Review
OpenEDG and Reading Review
Overriding
override specifier - if the function does not override a base class function, the compiler will flag the function as an error
final specifier - not overridable
Downcasting: Treat a pointer to a superclass as a pointer to its subclass.
Uppercasting / Upcasting: Treat a pointer to a subclass as a pointer to its superclass.
Polymorphism
A method to redefine the behaviour of a superclass without touching its implementation.
The one and same class may show many (“poly” – like in “polygamy”) forms (“morphs”) not defined by the class itself, but by its subclasses
The ability to realize class behaviour in multiple ways
“virtual”
a special type of function that, when called, resolves to the most-derived version of the function that exists between the base and derived class - learncpp
perhaps the biggest benefit of virtual functions is the ability to structure code in such a way that newly derived classes will automatically work with old code without modification!
Late binding or Dynamic linkage or Dynamic binding - function call is resolved during runtime, the compiler determines the type of object at runtime, and then binds the function call, similar concept to...
dynamic dispatch - the process of selecting which implementation of a polymorphic method to call at run time.
A pure virtual function or abstract function - exists only to be overridden, assigned 0
A class containing a pure virtual function cannot be used to declare the objects of its own, such classes are known as abstract base classes, they exist only to be derived.
Classes derived from abstract base classes are also abstract until they override the pure virtual function.
Can actually have a body, which could be called from derived class
An object of a derived type can be sent as an argument to a function expecting a parameter of the base type.
The dynamic_cast operator - If the conversion of the object to the type is possible, then the result is a new pointer which is fully usable.
Pet Dog example 1 using if
Pet Dog example 2 using l-value with try catch (more on this in the next lesson)
"const" - unalterable
with variables - must be initialized, can't be reassigned
with aggregates - read-only
with pointers - pointers can't change but the entities pointed to may be modified with no restrictions, int * const iptr
pointers to constants - pointers can change but the entities pointed to can't, const int *iptr
with pointers to constants - const int * const iptr
with fields - unalterable during the object's life, must be initialized in initialization list
with objects - mustn’t be modified during its life
with methods - promise that they won't modify state of object
"friend" review
Interface classes
no member variables and all pure virtual functions
Overriding <<
Week 11 11/3-8 Exceptions
Error handling
Learning Outcomes
Discussion / Mindfulness
OpenEDG
Part 2 - Module 3. Exceptions
Topics
3.1 Introduction to exceptions;
3.2 The throw statement in detail;
3.3 Exception categories;
3.4 Catching exceptions
Exam Topics
Exceptions - dealing with expected and unexpected problems
what is an exception,
catching and throwing exceptions,
different classes and hierarchy of exceptions,
defining your own exceptions.
Tutorial / Practice Activity / Project
Integrate exception handling
Readings
Resources
7.15 — Detecting and handling errors - happy path, sad path, defensive programming
C++ Exception Handling tutorialspoint - C++ Standard Exceptions and inheriting and overriding exception class
Exceptions cplusplus
Lesson
Discussion Review
OpenEDG and Reading Review
a throw statement is used to signal that an exception or error case has occurred (think of throwing a penalty flag)
Exceptions and inheritance - order of catch matters
std::exception is a small interface class
scope in try
Exception handling is best used when all of the following are true:
The error being handled is likely to occur only infrequently.
The error is serious and execution could not continue otherwise.
The error cannot be handled at the place where it occurs.
There isn’t a good alternative way to return an error code back to the caller.
Exception handling in C++ vs Java
In C++, all types (including primitive and pointer) can be thrown as exception. But in Java only throwable objects (Throwable objects are instances of any subclass of the Throwable class) can be thrown as exception.
C++ has "catch all" (...). In Java, we can catch class Exception to catch all kind of exceptions.
In Java, there is a block called finally that is always executed after the try-catch block. This block can be used to do cleanup work. There is no such block in C++.
In C++, all exceptions are unchecked. In Java, there are two types of exceptions – checked and unchecked.
In Java finding and handling the exception is easier than in C++.
Visual Studio try tab
Practice question #16, 17, 18, 19 class diagrams and state / memory diagram
Week 12 11/10-15 Generics / Templates
Learning Outcomes
LO7. Define and use iterators and other operations on aggregates, including operations that take functions as arguments. [Usage]
Discussion / Mindfulness
OpenEDG
Part 2 - Module 3. Exceptions
Topics
3.5 Exceptions in action
Assignments
Module 3 Quiz
Module 3 Test
Exam Topics
None
Tutorial / Practice Activity / Project
Add a template.
Define and use iterators and other operations on aggregates, including operations that take functions as arguments.
Readings
Resources
HackerRank Generics Tutorial (in Java)
Lesson
Discussion Review
OpenEDG and Reading Review
A template is essentially a stencil for creating functions or classes.
Templates can work with types that didn’t even exist when the template was written. This helps make template code both flexible and future proof!
template parameters
template argument deduction: the compiler deduces the type that should be used from the argument types
template types are sometimes called generic types
A good rule of thumb is to create normal functions at first, and then convert them into function templates if you find you need an overload for different parameter types.
C++20 introduces a new use of the auto keyword: When the auto keyword is used as a parameter type in a normal function, the compiler will automatically convert the function into a function template with each auto parameter becoming an independent template type parameter. This method for creating a function template is called an abbreviated function template.
Template classes are ideal for implementing container classes
you should understand what std::vector<int> means now
put all of your template class code in the header file or rename cpp inl
Passing a function as a parameter in C++ geeksforgeeks
5 Advantages of C++ Lambda Expressions and How They Make Your Code Better
https://stackoverflow.com/questions/890128/why-are-python-lambdas-useful
Week 13 11/17-22 Operators
Pointer Arithmetic
Learning Outcomes
Overload operators
Discussion / Mindfulness
OpenEDG
Part 2 - Module 4. Operators and enumerated types
4.1 Overloading operators
Exam Topics
Fundamentals of the object-oriented approach
defining and overloading operators
Tutorial / Practice Activity / Project
Readings
Resources
Lesson
Discussion Review
Passing a function as a parameter in C++ geeksforgeeks
OpenEDG and Reading Review
When you see the expression x + y, you can translate this in your head to the function call operator+(x, y) (where operator+ is the name of the function).
limitations on operator overloading
almost all but some exceptions
must be existing operators
at least one must be user defined
can't change number of operands
precedence and associativity remain the same
If the meaning of an overloaded operator is not clear and intuitive, use a named function instead.
Three different ways to overload operators:
the normal function way - Prefer overloading operators as normal functions instead of friends if it’s possible to do so without adding additional functions.
Overload Operators HackerRank
FeetInches class with overloading of +, -, and <<
Practice question #20-21 class diagrams and state / memory diagram
20 - change i to i.v, check in Visual Studio debugger
Week 14 11/29-12/1 Enumerated types
Learning Outcomes
Discussion / Mindfulness
OpenEDG
Part 2 - Module 4. Operators and enumerated types cont.
Topics
4.2 Enumerated types
4.3 Overloaded operators in detail - part 1
4.3 Overloaded operators in detail - part 2
Assignments
Module 4 Quiz
Module 4 Test
Course Final Test
Exam Topics
enums
Tutorial / Practice Activity / Project
Readings
Resources
Lesson
Discussion Review
OpenEDG and Reading Review
Reading
Start at 0
Enumerated types are incredibly useful for code documentation and readability purposes when you need to represent a specific, predefined set of states.
There’s little reason to use normal enumerated types instead of enum classes.
A struct is a class with only fields, no methods. They are also known as plain old data structs (or POD structs).
OpenEDG
From enum Symbols{ALPHA = -1, BETA = 1, GAMMA}; what would be the value of GAMMA?
From enum letters{A = 1, B = 0, C, D}; what would be the value of C?
Practice question #22 class diagrams and state / memory diagram
Project
Unit 3: Wrap Up
Week 15 12/6-8 Wrap up
Discussion / Mindfulness
Lesson
Portfolio
Viewing grades in Canvas
Work on final project
Professional advice
Prepare for Data Structures and Algorithms
Course retrospective
Educational options
Future programming requirements within the major and on the job
Majors: Integrated Studies
End of semester awards