Alvin Sylvain

Alvin Sylvain

Containers, Vector

Slide Duration:

Table of Contents

Section 1: Intermediate C++
Overview of Intermediate C++

39m 28s

Intro
0:00
Overview
0:22
Review
3:10
Language Features You're Expected to Already be Familiar With
3:41
Introduce New Features and Cover Some Familiar Territory More In-Depth
4:17
Containers; Vector
4:45
Features: Templates and Containers
4:56
Vector is the First Container Learned
5:15
Example
5:44
Containers; List
7:18
Linked List is One of the Most Basic Data Structures in Computer Science
7:24
This Class Shows How to Use the Standard Library 'List' Container
7:52
Example
8:15
Containers; Set, Map
9:15
Binary Tree
9:23
'Set' and 'Map' are Not Sequential
10:23
Set Retrieves Unique Keys
10:41
Map Retrieves a Unique Key, Then the Related Value
10:55
Example
11:11
Templates
12:00
Allow for Code Re-Use and Modularity
12:14
Example
12:46
Object Oriented Programming
15:19
OOP is the Main Motivating Factor to the Original Development
15:29
Only Grafted on Non-OOP Features
15:39
Discuss How Classes and Objects Are Created and Instantiated in C++
16:20
Operator Overloading
18:29
Writing Polymorphic Functions
18:39
Operator Overloading is a Standard Feature in Most Programming Language
18:52
Example
19:00
Exception
21:05
Practical Programming Means Handling Unexpected Conditions in an Expected Way
21:08
Programmers Have Used Different Techniques to Pass Along Info That's 'Less Than Good'
22:27
Exception Handling in C++
23:51
C++ Exceptions Can be Any Type
24:31
Example
24:38
Namespaces
25:30
Name Collision
25:40
C++ Solution is for Each Company to Use Their Own Unique Namespace
26:06
Example
26:29
Input/Output
27:43
Class Hierarchy for C++ Input/Output
28:16
Turn on Exception Handling and Check Input/Output Status Bits
28:21
How to Use 'Stringstream' Object
28:32
More Details for Functions
29:19
Parameters on the Main Function
29:34
Inline Functions
29:52
Recursive Functions
30:34
Pass Pointers to Functions as Function Parameters
30:42
More Kinds of Types
32:23
Union to Force Memory Overlap
32:30
Enum Type
33:01
Typedef Keyword
33:37
Keeping Things the Same 'Const'
34:00
Pre-Compiler Macros
34:09
'#include'
34:22
'#define'
34:45
Conditional Compilation with '#ifdef'
35:19
Compiling the Code
35:57
Dash D Testing
36:26
Common Flags
37:18
Flag That Allows a Run-Time Debugger to Hook Into the Application
38:11
Tally Ho!
39:07
Review

56m 23s

Intro
0:00
Overview
0:21
Acquire a Compiler
1:24
Windows
1:51
Macintosh
2:02
Acquire a Compiler for Linux
2:18
Redhat
2:28
Ubuntu
2:38
Software Manager
2:51
Acquire an Editor
3:14
Popular Editors
3:48
Compile and Run a Program
5:00
Traditional First Program
5:28
Comments in Code
8:12
Standard C 'block' Type Comment
8:34
C++ 'to end of line' Comment
8:59
Simple Data Types
10:00
Integer
10:07
Floating Point
11:11
Character
11:50
Two Types of 'Strings' in C++
12:31
Examples
12:48
Operators
15:56
Unary
16:01
Binary
17:24
Ternary
18:16
Function-like
18:43
Member Reference
19:41
Expressions
20:51
Modifying
21:01
Arithmetic
21:24
Comparison
21:46
Logical
22:24
Comma
22:48
Left-Hand Expressions
24:04
'Right hand'
24:07
'Left hand'
24:30
Examples
25:12
'If' Branching
26:33
'Switch' Branching
29:15
Looping
30:59
'While' Loop
31:04
'Do While' Loop
32:17
'For' Loop
32:59
'Break'
34:15
'Continue'
34:36
Functions
34:49
Prototypes
36:06
Function Parameters
36:36
Return Value
38:23
Overloading
38:41
Arrays
39:10
Multi-Dimensional Arrays
41:05
Pointers
43:37
Definition
43:43
'Dereference' Operator
43:51
'Reference' Operator
44:40
Structures
47:20
Example: Without Structure
48:12
Example: With Structure
49:13
Object Oriented Programming
51:00
Access Can Be Defined As
53:24
Input / Output
54:07
Insertion Operator
54:29
Extraction Operator
55:04
File Stream Objects
55:33
Two Thumbs Up!
55:58
Containers, Vector

40m 14s

Intro
0:00
Lesson Overview
0:11
Containers
1:50
Vector
1:58
List
2:24
Set, Map
2:56
Data Access
3:44
Iterators
4:10
Container Information
4:37
Vector
4:53
Memory Re-Allocation
6:07
Declare Vector of 'Type'
7:37
Size & Capacity
8:01
Vector<type> Variable
8:20
Vector<type> Variable (Initial Size, Initial Value)
9:27
Vector<type> Variable (Initial Size)
10:11
Access Vector Data
10:27
Example: Typical Array Access
10:46
Method Call Access
11:07
Other Data Access
12:26
Front
12:30
Back
12:38
Use Empty Function to Test
13:37
Vector Information
14:36
Resize
15:53
Reserve
17:55
Vector Iterators
19:11
Example: Data Elements May be Accessed Like Standard Array
19:30
Data Elements May be Accessed Using Iterators
20:38
Vector Iterator Begin/ End
23:30
Begin
23:34
Eng
23:50
Reverse Begin
24:07
Reverse Iterator
24:16
'Short?' Cuts
25:21
Declaring Loop Index Inside the 'for' Loop
25:34
With Iterators
26:05
Modifying Vector Data
26:54
Push Back
27:44
Pop Back
28:57
Insertions
29:32
Example: Insert New Value at Beginning
29:51
Example: Insert Value in Middle
30:40
More Vector Operations
32:12
Empty
32:15
Erase
32:22
Clear
33:01
Assign
33:20
Compile-Time Initialization
34:34
Example 1
35:22
Example 2
36:07
Example 3
37:25
Caution-Invalidating Iterators
37:59
Contained!
39:56
Containers, List

33m 40s

Intro
0:00
Lesson Overview
0:13
Linked List Overview
1:34
Arrays and Vectors
1:39
Linked List
3:16
List Information
5:53
Empty Method
6:04
Max Size
6:14
Resize
6:51
List Access
7:48
Front and Back
8:04
Iterators
8:16
Example
8:49
List Iterators vs. Vector Iterators
9:24
The Next Element May be Physically in Memory Before the Current Element
9:50
Vector Iterators Allow Integer Add
10:34
List Iterators Do Not Allow Integer Add
12:24
Simple List Modification
14:24
Constructors
14:32
Difference Between Assign and Insert
15:16
Assign
15:37
Insert
16:01
Push
16:31
Pop
16:38
Erase
16:53
Complex List Modification
18:34
Merging and Splicing
18:38
Merge
19:35
Splice
20:24
Reordering
21:46
Removing
22:28
Modification Examples
23:22
Functions as Parameters
24:49
A Function for 'remove_it()'
25:04
A Function for Merge and Sort - Evens Before Odds
25:46
Deque
27:28
Insertion or Removal in Middle May be More Efficient than with Vectors
27:51
Not Guaranteed to be Contiguous Memory
28:42
Same Method as Vector, Plus More
29:00
Stack
29:11
Empty, Size, Top, Push, Pop
31:05
Queue
31:56
Definition
32:19
Not That Kind of List
33:19
Containers, Set, Map

35m 35s

Intro
0:00
Lesson Overview
0:11
Tree Structures for Sets/Maps
2:01
What's the Value?
3:00
Pair Template Class
4:45
Allows a Function to Return 'Two' Values Instead of the Normal One
5:15
Example for an Integer Set
5:46
Example for Map with a String Key, Double Value
7:09
Set, Multiset
8:03
What's a Set
8:32
Elements are the Key
9:30
Custom Class for Ordering
9:52
Get Data In to Set
10:28
Constructors
10:33
Insert (Value)
11:26
Insert (Position, Value)
12:30
Insert (First, Last)
13:18
Get Data Out of Set
13:28
Erase
13:33
Find
13:57
Lower_Bound
15:20
Upper_Bound
15:43
Iterators Positioned Such That a For-Loop Can 'Start at Zero'
15:59
Set Examples
16:32
Map, Multimap
19:15
Get Data In to Map
20:45
Constructors
20:48
Insert a Key Value Pair
21:25
Insert Position
22:05
Insert (First, Last)
22:21
Get Data Out of Map
22:37
Operator
23:43
Erase
25:16
Find, Lower & Upper Bound
25:28
Map Examples
25:37
Comparison Class
29:34
Example
30:37
What About Duplicates?
33:29
Define a Pair to Receive a Container Iterator and a Boolean
33:40
Example
34:07
Useful Maps
35:10
Templates

41m 8s

Intro
0:00
Lesson Overview
0:08
Function Template
5:48
Define
5:52
Use
6:46
Example
7:03
Constraints on Types
10:34
Example
10:45
Multiple Types
13:58
Example
14:03
Default Types
17:11
Example
17:24
Class Template
20:27
Example
20:33
Template Specialization
24:31
Example
25:00
Non-Type Parameters
27:32
Example
27:46
Templates in Templates
32:20
Example
32:34
Cautions
35:04
Don't Use a Template with a Type That Doesn't Support All the Template's Operations
35:10
Templates Can Not be Split into Header Files and Compiled Units
36:51
Issues with Debugging
39:47
Templates Gone Wild!
40:33
Object Oriented Programming, Part 1

1h 4m 48s

Intro
0:00
Lesson Overview
0:14
Concepts
4:39
Historically Distinct Ways of Programming and Design
4:41
OOP Emphasizes Important Concepts
6:28
Some Terminology
9:53
Object
9:56
Class
11:47
Instance
12:56
Example
14:04
Abstraction
20:00
Abstraction Defines the Essential Characteristics of an Object
20:08
Emphasis on Essential
20:34
Classes are Defined with Characteristics That Distinguish One Class of Objects From Another
21:18
Encapsulation
22:23
Private Data
23:25
Public Methods
23:40
Protected Data
24:47
Inheritance
25:52
What Is Inheritance?
25:58
Example
27:57
Polymorphism
29:18
Example of Operator Overloading
29:30
Example of Parameter Signature
30:22
Methods Inherited From another Object Can be Overwritten and Customized to the New Object
31:13
Object Relationships
33:37
Consider Two Objects, Car and Vehicle
33:42
Consider Two Other Objects, Car and Tire
34:01
Object Motorcycle
34:22
Inheritance Example
35:27
Multiple Inheritance
39:24
Example
39:51
Be Careful for Diamond Problem
43:46
Multiple Inheritance Example
45:28
Constructors
46:55
Default Constructor
47:33
Copy Constructor
49:10
Default Constructor
50:33
Example
50:55
Shallow Copy
52:41
Example
53:10
Deep Copy
56:35
Example
56:42
Copy Constructor
1:01:34
Good Design? Or…
1:04:28
Object Oriented Programming, Part 2

44m 16s

Intro
0:00
Lesson Overview
0:10
Overloading Constructors
3:10
Provide Other Constructors
3:26
Example
3:43
Initialization Lists
5:40
Syntax Example
5:43
Equivalent to Initializing in Statements in the Method Body
6:50
Destructors
7:09
Destructor is Automatically Called when Instance is Deleted
7:26
Declare the Declare as Virtual in the Event the Class is Designed to be Derived by Sub-Class
9:15
What's in a Name?
11:15
Example: How to Tell Field from Parameter
11:56
Friendship Functions
16:32
Avoids Strict Object Oriented Principles and Declare the Function or Class Using 'friend' Keyword
16:47
Example
17:12
Friendship Classes
18:48
Example
18:57
Designing for Derivation
20:54
Add 'Virtual' Keyword to Public Methods
21:50
Add 'Virtual' Keyword to Destructors
24:17
Abstract Class
25:41
Designed Only for Derivation
25:47
Example
26:13
Compilation Units
28:22
Classes Are Typically Divided into the Interface Portion and Implementation Portion
28:53
Namespaces Are Used to Associate a Class Method with the Class Definition
29:31
Example Compilation Units
30:53
Definition for 'Vehicle' Class for an Include File
30:54
Implementation for 'Vehicle' Class in Program File
33:01
Why You Add 'Include Guards'
36:33
Suppose You Derive 'Automobile' From 'Vehicle'
36:38
Caller File Includes Both
37:21
Object Oriented? Or Not?
38:46
When Is It Appropriate?
39:31
When Is It Not Appropriate?
41:04
The Object Oriented Purist
43:53
Operator Overloading

1h 12m 54s

Intro
0:00
Overview
0:13
When Not to Overload Operators
4:32
Arithmetic Operators Should Only Apply to 'Numeric' Kinds of Classes
4:53
Complex Number
6:04
'add' Operation vs. 'add()' Method
6:38
When It Can Be a Good Idea
7:42
Your Class is Inherently Numeric In Nature
7:49
Some Operators Still Make Sense to be Overloaded
8:26
Kinds of Operators to Overload
11:03
Binary Operator
11:19
Unary Operator
12:06
Non-Member Functions
14:27
Example: Named Vector
15:03
Named Vector is a Directional Vector with a Name
15:10
Directional Vectors
15:15
Overloading Demonstration
18:58
Assignment Operator=
20:26
Deep Copy
20:37
Copy Constructor
20:55
Overloading Operator=
22:21
Example Member Function
22:28
Overloading Binary Operator==
27:10
Example 'Equal' Member Method
27:30
Other Comparison Methods Can Call This One
31:09
Overloading Binary Operator<
32:30
Example: 'Less Than' Member Method
32:43
Overloading Arithmetic Operators
35:04
'@=' Operator
35:23
Operations Work Symmetrically
36:22
Overloading Binary Object-to-Object
38:19
'@=' Is Member Function with Full Access
38:27
'@' is Non-Member Function
40:24
Multiple a Vector by a Number to Make it Larger
43:19
Need Two Symmetrical Non-Member Functions
44:46
Overloading Unary Operator
47:16
No Parameter for the Operator@ Function
47:40
Overloading Prefix/Postfix Operator
49:12
Unary Operators with Different Semantics for Prefix and Postfix
49:38
'++' and '--'
50:43
Overloading Prefix Operator++
51:21
Add 1.0 to X/Y Components Before Accessing Value for Caller
51:38
Also Include the Operator-- to Subtract 1.0
51:55
Overloading Postfix Operator++
52:02
Give It a Dummy Operator
52:07
Overloading, Object-to-Other Object
54:18
Make Non-Member Function a 'Friend' to Access Private Members of Your Class
54:36
Parameters Must Include Other Objects When Overloading
54:50
Useful for Saving an Object to a File
55:52
Overloading Operator<<
56:45
Include Non-Member 'Friend' Function in Class
56:50
Implement Function in the Compilation Unit
57:58
Allows Output of Your Objects with Other Data
59:39
Array Operator[]
1:00:55
Example: The Standard Library Vector
1:02:00
Named Vector
1:02:49
Overload Array Operator []
1:03:19
Implement Operator[] As a Member Function
1:03:23
Write the Code
1:04:15
It Lets You Define a Non-Int for the 'Array Index'
1:05:22
Function Operator()
1:06:39
Examples
1:07:07
Define (idx)
1:08:38
Overloading Function Operator()
1:09:45
Implement Operator() As a Member Function
1:09:48
Calling Example
1:11:27
Bad Overloading!
1:12:27
Exception Handling

57m 51s

Intro
0:00
Overview
0:11
Something Went Wrong! Now What?
6:05
Data Must Always be Validated
6:11
Many Operations Will Validate Input to Make Sure No Mistakes Were Made
8:13
Many Check the External Environment
10:26
Many Don’t Check But App Can Still Crash
10:56
Different Error Checking Methods
11:38
Traditional Method
11:42
Exception Handlin
14:09
Lazy Way
15:30
Traditional Error Checking
16:08
Example: Return Code, Simply 'if'
16:12
Example: Output Parameter
18:15
Exception Handling
20:01
'Try' Block
20:05
'Catch All' Block
20:49
No 'Finally' Block
21:31
'System Errors'
22:34
Basic Syntax
23:12
Code to Throw an Exception
23:16
Code to Handle an Exception
23:49
Example Exception
26:51
Run This Program Fragment, It Will Crash
26:54
Run This One, The Error is Controlled
28:00
Throw Exception
30:51
Can 'Throw' An Exception If Error Conditions Found
30:56
Basic Example' 'int' Exceptions
31:03
Character String Exceptions
36:16
Exception Can Be Any Type, But a Character String Can be Informative in Simple Cases
36:19
Not Good for More Than Simple Situations
38:19
Derive From 'Exception' Class
38:34
When You Don’t Care Exactly Which Sub-Class of 'Exception' Can Be Thrown
39:02
When Each Sub-Class Handled Differently
39:17
Exception Derivation Example
41:28
Adding 'Throw()' Keyword to Prototype
45:32
Promises to Compiler What Kind of Exceptions the Function or Method Might Throw
45:42
Leave the Keyword Off
46:39
Leave the Parameter List Empty
46:51
Exception Can Not Be Caught With a Type-Specific Handler
47:28
Exceptions Not Derived From 'Exception'
49:11
Don’t Rely on System Exceptions!
54:06
Certain System Operations Don't Throw an Exception in a Platform-Independent Manner
54:10
Examples
54:25
Your Own Code Should Test for the Conditions That Might Lead to Uncatchable Exceptions
56:03
Exceptional!
57:30
Namespaces

29m 51s

Intro
0:00
Overview
0:15
Namespaces
5:27
Uses the 'Scope Operator'
5:30
Two Kinds: Standard Library and Classname
5:47
Helps Avoid Third Party Name Collision
6:42
'Namespace' for Class Association
7:46
Scope
7:53
Example
8:01
Implementation in Separate File, Same Scope
8:46
Define a Namespace
10:05
Use 'namespace' Keyword, Valid Identifier, and Block to Add to a Namespace
10:07
Example
10:40
Units Can Share Namespace
12:26
'std' Namespace
12:40
Include Namespace Declaration Block in Each Compilation Unit
13:13
Use Namespaces for Types, Classes
14:04
Compilation Unit: alpha.cpp
14:11
Compilation Unit: beta.cpp
14:27
Calling Unit
14:49
Don't Use Namespaces for Instances
15:21
Namespace Cannot Be Used to Duplicate Names of Object Instances in Different Compilation Units
15:25
Example
15:40
Error When Compilation Units Are Linked Together
16:22
Using Explicit Namespace
16:51
Header File for Class
16:56
Use of Namespace in Compilation Unit
17:03
'Using' Keyword
17:36
Specify a Default Namespace
17:40
More Than One 'Using' Can Be Specified
18:49
Avoiding 'Using'
20:48
Third-Party Packages Often Avoid 'Using'
20:49
Example
21:03
Using for Particular Names
22:54
The 'Using' Keyword Can Set Up Just Certain Names for a Default Use
22:56
Naming Strategy
24:30
Unique Name, World-Wide
24:48
Avoid Confusion with Another Similar Name
25:23
Typical Advice: Use Company Website Name
25:30
Namespace Aliases
28:35
User Uses Certain Namespace with a Different Name
28:27
Example
28:38
Avoiding Duplicates
29:33
Input/ Output

42m 46s

Intro
0:00
Overview
0:11
Streams
4:37
Byte Streams
4:51
Operator '<<' Overloaded for Output
5:14
Operator '>>' Overloaded for Input
5:47
I/O Class Hierarchy
6:46
ios_base
6:57
Input Stream
7:04
Output Stream
8:27
Multiply Inherits From istream, ostream
9:04
Buffer Class Hierarchy
9:27
Buffering Allows I/O to Work More Efficiently
9:38
'Flushed'
9:54
Streambuf - Buffer for Data
9:58
Base Class Attributes
10:25
Formatting Information
10:36
State Information
14:43
Sub-Class Members
15:46
IOS Adds Additional Members and Methods
15:49
Error State Flags
18:23
Input Classes
20:31
istream - Input Character Stream
20:33
ifstream - Input File Character Stream
22:50
istringstream - Input String Character Stream
23:23
Output Classes
24:10
ostream - Output Character Stream
24:13
ofstream - Output File Character Stream
25:28
ostringstream - String Character Stream
25:42
Multiple Inheritance and Includes
25:59
iostream - Multiply Inherits From istream, ostream
26:04
Classic Example of Multiple Inheritance
26:22
fstream - Inherits From iostream
26:47
stringstream - Inherits From iostream
27:08
Detect Failures Using Status Bits
27:32
Test the Status Bits
27:43
Use Exceptions
29:12
Failure Bit Cautions
30:20
failbit Is Set on Formatted Input if the Input Stream Cannot be Parsed
30:27
Example
30:37
String I/O with Stringstream
32:21
Used for Input and Output
32:26
Example
33:45
Flushing Data buffer
35:39
Sometimes Buffering Is Not Desired
35:43
Input Flush Example
37:10
Output Flush Example
38:17
Internationalization
39:06
Complex Problem with Different Cultures
39:20
'Imbue' I/O with Installed Locale Info
40:12
Set Size of a 'Character' for I/O
41:45
Confused Yet?
42:47
More With Functions

42m 52s

Intro
0:00
Overview
0:18
Parameters for 'Main'
2:18
First Function
2:19
The Way Seen Most Often
5:13
Some Typical Parameters
6:05
Help
6:11
Version
6:22
User
6:51
Password / Port
6:59
File To Be Operated On
7:25
Code Example
8:25
Some Things of Note
12:17
First Item in 'argv' is the Program File
12:20
How Each Argument is Given to the Program is OS Dependent
13:42
A Return of '0' Usually Means Success
14:48
More Things of Note
15:11
It's Customary to Have Both Stand-Alone Arguments (Options) and Arguments with Additional Parameters
15:28
Examples
15:37
Inline Functions
17:37
'inline' Tells the Compiler to Insert the Function Body Explicitly Into the Code
17:43
Function Modularity Without Function Overhead
17:53
Example
19:05
Recursive Functions
20:22
Definition of Recursive: A Function or Algorithm That Uses Itself to Solve a Problem
20:34
Common Mistakes
20:56
Classic Example: Factorial
21:27
Recursive Factorial Code
23:16
Compare Iterative Version
23:48
Pointers to Functions
25:55
Technique Used Often in GUI Programming
26:05
The Package Calls the Caller's Function by Dereferencing the Pointer
26:45
Example
27:04
Pointers to Functions as Parameters
27:45
Syntax
28:01
Calling Parameter Function Within Function
29:42
Example
30:15
Multi-Dimensional Array Parameters
31:07
Function Receives a Pointer to Array But Can Not Know Size Ingo
31:40
Example
31:48
Ways to Handle; 1-Dim Array
33:53
Good use for an Inline Function
34:06
Ways to Handle: Internal Data
35:38
Example 1
35:48
Example 2
36:25
Ways to Handle: Objects
39:38
Example
39:47
Usage Examples
41:18
No Help Here!
42:28
More Types

39m 10s

Intro
0:00
Overview
0:12
More Kinds of C++ Types
1:32
It Has Strong Type Conventions That Can Be Used to Enforce Program Integrity
1:50
Recommended: Avoid the Short Cuts!
2:02
If a Short Cut is Necessary…
2:57
Unions
3:24
Union = Short-Cut
3:25
Example: Inspect Each Byte of a 32 bit Integer
3:56
This May Not Run the Same on Different Platforms
5:11
Union of Struct
8:12
Typical Use for a Union is Sharing Memory Between Structures
8:13
Example
8:21
Union Rules
9:56
There's No Platform Independent Way to Store Member Data
9:57
Cannot Store Classes That Have Constructors
11:37
Enumerators
12:39
Useful for Defining Enumerated Constants
12:40
Use it Like Any Other Type
13:02
Example: Can Be Started and Restarted at Any Value
13:38
Can Be Used Like Any Integer
14:48
Less Error-Prone
15:10
Be Careful Changing the Sequence
15:25
Example: Sometimes Useful to Associate String Constants
16:24
Use of 'typedef'
17:46
In C, 'types' Created with 'typedef' Keyword
17:47
In C++, the Keyword is Largely Unnecessary
17:52
Examples: Use of'typedef' in C and C++
18:06
Custom Type Substitution
19:57
'typedef' Keyword is Often used in Place of Somet Other underlying Type for Purposes of Clarity
19:58
Examples: Custom Type Substitution
20:25
Pointer Hiding
23:10
Pointer to a Type Look
23:11
Example: Pointer Hiding
23:39
Cautions Using Underlying Types
26:02
Example: Using Underlying Types
26:03
The Underlying on Most Systems Today
26:42
Example: Only Works Because It Is an 'int'
27:20
Cautions Using time_t Typedef
28:05
32-Bit Integer 'Runs Out' In The Year 2038
28:06
Only Use the Provided Classes and Functions Designed to Handle a Particular Type
29:27
When Working with typedef, Treat It Like A Class Object
29:45
'const' Ness
30:45
It’s More Than Just Declaring a Variable or Parameter That Cannot Be Changed
30:46
Also Used on Methods
31:25
Example: 'const' ness
31:37
'const' on Object Attributes
33:01
Can Be Used on Object Attributes
33:01
Example: 'const' on Object Attributes
33:06
Row That Is Permanently Identified by 17
33:34
Allow Certain Change, 'mutable'
34:29
'mutable' Allows Change
34:30
Used on Specific Object Members When the Method Is Supposed to be 'const'
34:49
Why Would Some Members Need to Change?
35:23
Examples
36:00
'mutable' Examples
36:49
Union Troubles
38:53
Macros & Compilation

51m 23s

Intro
0:00
Overview
0:14
Pre-Processor Macros
2:57
Define with the 'Pound' Character
2:58
Macros Are Pre-Processed on a Textual Basis
3:48
Including Other Files
5:25
Use the 'Include' Macro When You Use a Pre-Compiled Library
5:26
Triangle Brackets
6:20
Quotes Indicate That the Include File May Be Found in the Same Directory as the File Being Compiled
6:32
Any Text File Can Be Included
7:00
Basic Constant Definition
8:54
'Define' Macro Keyboard
8:55
'MAX_ROWS replaced by '300'
10:16
Compiler Never Sees MAX_ROW
10:48
Literally Anything Can Be Defined
12:03
Typical Use
12:19
Application Constants
12:30
C++ Improvements
12:48
Using Macros in Macros
13:32
Macro Substitution Can Occur in Macro Substitution
13:33
Example
14:17
Text Replacement
14:30
Conditional Compilation, Includes
16:20
ifdef, ifndef, if, else, elif, and endif
16:21
Include Guards & Example
18:10
Conditional Compilation
20:21
Don't Print Out Debugging Info in the Production Code
20:22
Compiler Will Never See the Testing Code
21:48
Macros Can Be 'undef'ed
22:36
Good for Temporary Removal
23:27
'Comment Out' Sections
23:37
Can't Use the // or /**/ Comment
23:54
Use 'ifdef'
24:57
Macro Functions
26:29
Macros Have a Facility for Creating Small In-Text Functions
26:30
Define a Macro Function
27:16
If You Need More Than One Line
27:32
Macro Function Examples
28:34
Return Area of a Circle
28:35
Return Volume of a Cylinder
29:00
What Can Happen Without Parentheses?
29:45
Avoid Those Problems
31:14
In C++, Use Inline Functions
31:15
Inline Functions Avoid All Other Problems That Historically Have Occurred With Macros
32:11
Mixing C with C++
34:08
C Code Can Not Be Linked Directly with C++ Code
34:09
In C Header File Add
35:38
Pre-Defined Macros
37:18
Macros That Should Be Pre-Defined for Every Standards-Compliant Compiler
37:19
Occasional Misuse
38:39
Abusing the Facility
38:40
Example: Trying to 'look' Like Pascal
39:03
Allows Code to be Written Like This
39:20
Compiling
40:14
Typical Compilation Command Line
40:15
Compilation of One Unit at a Time
41:02
Compiler Flags to Find Libraries
42:34
Finding Other Include Files & Other Libraries to Link Into Your Application
42:35
Example: Create an Application that Uses the MySQL Database
43:02
Other Useful Flags
47:07
Small Set of Command Line is Most Common
47:08
'-c' Create an Object File From the Source
47:12
'-g' Add Internal Code That Allows a Run-Time Debugger to Hook into the Program
47:22
'-Dmacro' Set a Macro to be Defined
47:58
'-E' Stop After Pre-Processing
48:55
'-S' Stop After Compilation
49:26
Setting Flags for IDE
49:51
If You're Using Eclipse
49:52
Example
50:25
Uh, Almost
51:03
A Look at Some Code

57m 58s

Intro
0:00
Real Code Example
0:29
Global Constants
1:10
Account.cpp
2:14
Account.h
3:03
Call Back Function
3:24
Vector & Transactions
4:10
Constructor
5:54
User.h
8:54
User.cpp
12:01
Exceptions
23:56
Class Exception, Minor Exception, and Regular Exception
24:57
StringField.h
29:38
StringField.cpp
35:40
NumberField.h
38:56
NumberField.cpp
44:56
IntegerField.cpp
47:53
Date.h
49:17
Date.cpp
51:10
BankAccountMain.cpp
52:20
Lesson Summary
56:46
Loading...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Intermediate C++
Bookmark & Share Embed

Share this knowledge with your friends!

Copy & Paste this embed code into your website’s HTML

Please ensure that your website editor is in text mode when you paste the code.
(In Wordpress, the mode button is on the top right corner.)
  ×
  • - Allow users to view the embedded video in full-size.
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Services

Lecture Comments (4)

1 answer

Last reply by: Ram Manohar Oruganti
Tue Nov 4, 2014 6:27 PM

Post by Ram Manohar Oruganti on November 4, 2014

Hi,
I thought that begin and end give the value of at the start and end. So, how come the iterator could know the address when given a value?

1 answer

Last reply by: Alvin Sylvain
Tue Nov 20, 2012 7:20 PM

Post by Edwin Clement on November 17, 2012

How can I write a function maximum that computes the largest element in a list<int>

Containers, Vector

  • Create a program that declares a vector for 25 integers. Use the vector constructor to initialize it so that each element equals 0. Use a “for” loop to print out each element to confirm that it was properly set.
  • Create a program that declares a vector for doubles, but do not initialize it. I.e., it will start off empty. Use a “for” loop for 50 times, and each loop, use “push_back()” to add a new value to the vector. The value should be computed based on the index.
    • E.g., something like, 5.0*index or (including <cmath>), sin((double)index / 57.2958) etc. Whatever you think would be an interesting computation.
    • In a separate loop, “cout” the values to confirm that they are set as you expected.
  • Modify the program above so that the “cout” is in the same loop as the “push_back()” method. In that same section, “cout” the new size and new capacity of the vector.
  • Modify the program above to add a “while” loop after the vector data has been set. The loop contents will include a “pop_back()” method call, plus “cout” the new size and new capacity. The “while” loop should terminate when the vector is empty.
  • Create a compilation unit with the following. You’ll need it for the next assignments.
    • class named T
    • has two private fields, int “aInt” and double “aDouble”
    • has public methods to set and get each field
    • has default constructor that sets both fields to 0
    • has constructor that sets “aInt” to parameter, and “aDouble” to 0
    • has constructor that sets “aDouble” to parameter, and “aInt” to 0
    • has constructor that set both fields to parameters
    • has constructor that copies the fields from a reference to T parameter
      (e.g., T(T &t) {aInt = t.aInt; aDouble = t.aDouble;})
      (also known as a copy constructor)
    • has destructor that prints out, “Destroying, aInt (value), aDouble (value)”, where “value” is set to the current field values
  • Modify the first assignment to make a vector for type T. Initialize the int field to -1. “cout” both fields in the for loop.
  • Modify the program above to initialize the double field to -1.5.
  • Modify the program above to initialize each element to (-1, -1.5). Hint: to set both fields, you can instantiate a variable of type T, initialized to those values, and use that variable in the vector constructor.
  • Modify the program above use an iterator instead of an index to loop through each element. Also in this loop, change each element according to some calculation, so that each value is different. “cout” the before and after value.
  • Modify the program above to erase the middle 5 elements from the vector. I.e., remove elements 10 through 14 and leave the rest. “cout” the new vector contents, size and capacity.

Containers, Vector

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Lesson Overview 0:11
  • Containers 1:50
    • Vector
    • List
    • Set, Map
    • Data Access
    • Iterators
    • Container Information
  • Vector 4:53
    • Memory Re-Allocation
  • Declare Vector of 'Type' 7:37
    • Size & Capacity
    • Vector<type> Variable
    • Vector<type> Variable (Initial Size, Initial Value)
    • Vector<type> Variable (Initial Size)
  • Access Vector Data 10:27
    • Example: Typical Array Access
    • Method Call Access
  • Other Data Access 12:26
    • Front
    • Back
    • Use Empty Function to Test
  • Vector Information 14:36
    • Resize
    • Reserve
  • Vector Iterators 19:11
    • Example: Data Elements May be Accessed Like Standard Array
    • Data Elements May be Accessed Using Iterators
  • Vector Iterator Begin/ End 23:30
    • Begin
    • Eng
    • Reverse Begin
    • Reverse Iterator
  • 'Short?' Cuts 25:21
    • Declaring Loop Index Inside the 'for' Loop
    • With Iterators
  • Modifying Vector Data 26:54
    • Push Back
    • Pop Back
  • Insertions 29:32
    • Example: Insert New Value at Beginning
    • Example: Insert Value in Middle
  • More Vector Operations 32:12
    • Empty
    • Erase
    • Clear
    • Assign
  • Compile-Time Initialization 34:34
    • Example 1
    • Example 2
    • Example 3
  • Caution-Invalidating Iterators 37:59
  • Contained! 39:56
Educator®

Please sign in to participate in this lecture discussion.

Resetting Your Password?
OR

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Membership Overview

  • Available 24/7. Unlimited Access to Our Entire Library.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lecture slides for taking notes.
  • Track your course viewing progress.
  • Accessible anytime, anywhere with our Android and iOS apps.