Alvin Sylvain

Alvin Sylvain

Functions, Part 2

Slide Duration:

Table of Contents

Section 1: Introduction to C++
Introduction

26m 51s

Intro
0:00
Overview
0:11
What You'll Learn
0:51
Evaluate & Write Some Real C++ Code
3:22
Learn Some 'Best Practices'
3:43
C++ in the Wild
4:01
Examples
7:11
Declare an Integer
7:20
Call Functions
7:41
Examples
10:20
Factorial
10:36
Loop
12:20
Examples
13:20
If Greater Than 0
14:06
If Each 0 Equal 1
14:23
Modular Example - Function
14:34
Trig - Examples
16:44
A Brief History
19:02
Combines Features From Simula 67 and C
19:20
1998 - First International Standard Known as C++98
20:14
2011- New C++11
20:24
C=++ Advantages
20:36
Combines Functional Programming with Object-Oriented Programming
21:29
Compiled Code Works Closely with the Hardware
22:18
Language Elements
22:51
C++ Disadvantages
23:09
Little Run-Time Checking
23:39
Library of Tools are Not as Extensive as Other Languages
24:40
Ready to Get Started!
26:35
Getting Started

44m 24s

Intro
0:00
Overview
0:15
Acquiring a C++ Compiler - Windows
1:06
Setting up MinGW
2:44
Acquiring a C++ Compiler - Others
3:24
Redhat (Fedora) Linux
3:40
Ubuntu (Debian) Linux
4:19
Apple Macintosh
4:43
Acquiring a C++ Compiler - IDE
5:05
Eclipse CDT
5:12
Eclipse Older Version
6:30
Acquiring an Editor
6:46
Acquiring an Editor
8:36
Linux
8:40
Macintosh
8:51
'Hello World' Everybody's First Program
9:35
Source Code
13:31
Basic Program Structure
17:50
Example
20:14
Basic Program Structure
21:02
Main Function Definition
21:29
Compiling, Linking, Running
22:14
Examples: Compile
22:47
Link
24:55
Build Tools
26:11
Build a 'Makefile'
26:26
Integrated Development Environment (IDE)
27:25
Quick Note on Variable Declaration
28:03
Example: Integers
28:26
Example: Floating Point Numbers
29:05
Your Second Program - User Input Basic 'How Old Are You?'
30:49
Workspace / Source Code
32:21
New Workspace
33:29
Quick Note on Character Arrays
34:44
Example
35:34
Your Third Program - User Text Input 'What’s Your Name?'
37:13
Example
37:46
Workspace
39:50
Do Your Homework!
42:56
Data Storage

10m 8s

Intro
0:00
Overview
0:12
Variables, Identifiers, Names
1:34
Identifiers Defined
1:51
Example of Valid Identifiers
2:16
Styles: Multi-Word Identifiers
3:59
Compiler Doesn't Care
4:51
Styles: Identify Identifiers
5:38
Simple Data Types
8:08
Variable Type Declaration
10:35
Commentary
11:42
More Than One Variable Declared
13:22
Compiler Allocates Storage
14:23
Example
15:30
Variable Initialization
16:47
C Style
17:39
Example
18:23
C++ 'Class' Style
18:35
Numeric Literals
19:41
'Long' Types
21:15
Beware: Do Not Use
23:40
Character Literals
24:27
Examples
24:49
Quoted Special Characters
27:43
String Literals
29:55
String Object
32:28
Homework
33:20
Operators & Expression

32m 24s

Intro
0:00
Overview
0:11
Parameters for Operators
0:47
Left Side vs. Right Side
1:56
Example
3:12
Operators - Assignment
3:40
Assignment - Don't Confuse Readers
5:17
Operators - Arithmetic
7:53
Operators - Compound Assignment
9:38
Operators: Increment / Decrement
10:24
Examples
10:50
Pre- vs. Post-Operator
11:20
Operators - Comparators
12:19
Operators - Logical
13:38
Examples
14:35
Operators - Boolean Truth Tables
15:45
Examples
16:55
Operators - Input and Output
18:42
I/O Stream
18:56
Operators - Type Casting, Sizeof
20:42
'Sizeof'
21:46
Type-Casting Cautions
22:27
Classic Example
22:38
Type Promotion
25:46
Operator Precedence
26:58
Firth Things: Unary Operators
27:27
Expressions
28:32
Examples
28:58
Cautions
30:17
Classic Example
30:31
Hey! Wrong Kind of Operator!
32:13
Branching

26m 15s

Intro
0:00
Overview
0:03
Code Blocks, Scope
1:32
'Scope' of the Block of Code
2:27
Scope Example
2:56
'If' Statement
5:20
'Else' Clause
6:43
Example
7:01
Nested 'If'
7:52
Example
8:08
More Nested 'If'
8:41
'If' Without Blocks
9:53
'Chained If'
10:35
Example
10:51
'If' Statement's Expression
11:36
'If' Statement Stylistic Notes
12:55
'Else' Clause Stylistic Notes
14:24
'Switch' Multiple Choice
15:15
'Switch' Like 'Chained-If'
16:35
'Switch Tricks'
17:56
Leave Break Out
18:10
'Conditional' Statement Cautions
19:54
'Conditional' Statement Example
21:56
Another Example
23:05
'Goto' and 'Label'
23:40
Do's and Don'ts
1:54
Looping

28m 19s

Intro
0:00
Overview
0:08
Important Kind of Branch
1:17
Branch That Loops
1:43
In The Beginning
3:51
'While' Loop - Pre-Test
4:45
'Do-While' Loop - Post-Test
6:47
'Do-While' Run It Again
7:31
'For' Loop-Counting Loops
9:38
'For' Loop-Most Typical Use
11:46
Useful Feature
12:47
'For' Loop - Similar to 'While'
13:47
Example
13:57
Equivalent 'While' Loop
14:34
'Break' Out of Loop
15:50
'Break' Examples
17:07
'Continue' Back to Beginning
18:49
'For' Loop
19:04
'Continue' Caution
20:05
Infinite Loop
20:58
Loop Inside of Loops
21:44
Typical Bug
22:50
More Looped Loops
24:08
What a Loop!
27:46
Functions, Part 1

14m 44s

Intro
0:00
Overview
0:09
Value of Functions
0:46
Example Without Function
2:04
Example With Function
3:30
Function Prototype
4:11
Return Type
4:33
Name
4:40
Parameters
4:52
Nomenclature
5:27
Prototype Example
5:45
Function Definition
6:28
Definition Example
8:11
Function Parameter Types
8:52
Definition
9:47
Using the Function
11:09
Functions Return Single Value
13:15
Break Problem into Pieces
14:12
Functions, Part 2

16m 56s

Intro
0:00
Overview
0:09
Parameters by Value
0:47
Example
1:26
Parameters by Reference
2:55
Example
3:53
Parameters by Reference Example
4:20
Default Parameters
6:36
Acceptable Example
7:13
Unacceptable Example
7:27
Default Parameters Example
7:42
Return Value
8:41
Special Type: Void
10:31
Overloading
11:07
Name Accordingly & Carefully
11:17
Example
11:59
Overloading Example
12:31
Modularization
13:41
Smaller Modules
14:14
Isolated Modules
15:17
Cut Into More Pieces
16:31
Arrays & Pointers

40m 44s

Intro
0:00
Overview
0:10
Use a 'Chunk' of Memory
3:22
Declaring an Array
6:27
Example
6:55
Select an Element From Array
8:44
Example
10:15
Multi-Dimensional Array
12:15
Examples
13:09
Compile-Time Initialization
14:18
Example
15:04
Multi-Initialization
16:27
Character String Initialization
18:27
Examples
18:43
Pointers
20:11
Example
21:02
Pointer Declaration
22:20
Reference Operator
22:52
Referencing and Dereferencing
24:30
Example
24:49
Pointer Arithmetic
27:10
Function Call-By Reference
31:06
Function Array/ Pointer Example
32:21
Null Terminated Character Arrays
34:22
Example
35:13
'New' and 'Delete'
36:31
Example
37:44
Array of Pointers
40:19
Structures

24m 37s

Intro
0:00
Overview
0:10
Keep Data Organized
1:25
Multiple Arrays
2:01
Structure Declaration
3:19
Example
4:00
Structure Declaration
4:24
Example
4:53
Structure Usage
6:03
Example Structure
6:09
Accessing Members
8:27
Structure Member Structures
9:38
Example
9:50
Initializing Member Structures
11:35
Example
11:44
Access Data Within Data
12:46
Arrays of Structures
13:11
Multi-Dimensional? Of Course!
15:18
Pointers to Structures
17:55
Pointed-to Structure Members
21:22
Structure Pointer Operator
22:41
Example
22:53
Structure for Pointers
24:16
Input/ Output (IO)

43m 36s

Intro
0:00
Overview
0:15
Character Input Streams
3:02
'Getline' Method
5:12
Input Stream Object Methods
7:47
Input Examples
11:56
Character Output Streams
15:19
'Cout' = Standard Output
15:34
'Cerr' = Error Output
16:32
Insertion Operator
17:45
Format
18:12
Output Stream Object Methods
18:23
Output Examples
21:23
Formatting: I/O Manipulators
23:38
Set the Width
24:04
More I/O Manipulators
28:20
Scientific
28:44
Set Precision
29:15
Examples
31:04
File Input/Output
32:13
Output Streams
33:52
Insertion Operator
35:15
Example
35:22
Input Streams
36:50
Example
37:35
Error Messages
38:18
'errno'
39:10
Example
39:49
File Example
41:06
Got Files?
42:58
Review Using Real Code

48m 26s

Intro
0:00
Overview
0:19
Checkbook Program
1:15
Source Code
1:26
3 Structures
1:47
Checkbook Program
6:36
Create Functions
7:15
Source Code: Constant Set up / Version
7:45
Delimiter
9:25
Load Transactions
13:00
Dump Transactions
13:17
Utility Functions
14:56
Structures
16:14
Bank Structure
16:35
Transactions
16:44
Global Constants
17:00
Source Code: Global Variables
18:29
Function Prototypes
18:52
Source Code
19:36
Find the Bug in the Code
22:04
Function Prototypes
24:32
'Main', the Director
25:16
Source Code
25:44
Read Initial Data
26:13
Source Code
26:45
Function to Create 'Init' File
30:34
Transactions File Functions
35:12
User Action Functions
36:58
First User Action
37:10
Source Code
38:32
Utility Functions
44:34
'Stringstream'
45:23
Write Your Own Cheque
47:26
C++ Standard Library

27m 53s

Intro
0:00
Overview
0:22
System Time
1:42
Example
2:48
Back to the Future!
3:31
Human-Readable Time
5:27
Example
5:47
Static Memory
6:36
Local and GMT Time
7:45
localtime
8:28
gmtime
8:42
Example
8:50
Time Structure
9:23
Formatting Time
10:16
Example
11:02
Math Library
11:58
Other Math Functions
13:11
Functions from cstdlib (Standard Library)
13:47
More from cstdlib
15:31
Functions from ctype
19:29
More From ctype
21:27
Example
21:55
Functions from cstrings
23:00
More from cstrings
25:16
Additional Length Limited Versions
25:46
See the Library!
27:30
Handling Strings

33m 1s

Intro
0:00
Overview
0:09
Two Kinds of Strings
2:21
Object String from C++
2:25
Classic Strings from C
3:30
C++ String Object
4:24
Useful Member Functions
4:34
String Object Examples
7:35
Initialization
7:39
Operations
7:49
String Object Member Functions
10:27
Member Function
10:40
Example
11:02
More Member Functions
13:34
Arrays of String Objects
16:18
Examples
16:34
Classic C Character String Array
19:00
Defined As
19:24
Useful Functions for C-String Operations
20:20
Array of Classic C String
22:00
Examples
22:10
Some Reasons Against Classic
24:36
Examples
24:59
Need to Use String Functions
25:33
Cautions with Classic C Strings
26:11
Examples
26:23
Especially with Copying and Concatenation
27:16
But You Can't be Rid of It
29:35
Examples
30:00
Don't Tangle Your Strings!
32:30
Object Oriented Programming

22m 45s

Intro
0:00
Overview
0:15
Concepts
1:53
Object Oriented Programming (OOP)
2:42
Some Terminology
3:34
Object Defined
3:39
Class Defined
4:07
Instance Defined
4:20
Example
4:35
Abstraction
5:21
Emphasis on Essential
5:36
Emphasis on Characteristics
6:17
Encapsulation
7:29
Private Data
8:16
Public Methods
8:40
Protected Data
9:14
Inheritance
10:08
Example
10:39
Polymorphism
11:39
Example: Operator Overloading
12:24
'Is-a' vs. 'Has-a'
14:00
Multiple Inheritance
15:07
Example
15:28
Diamond Problem
17:59
Constructors / Destructors
18:27
My Kind of Inheritance
22:25
Source Files & OO Samples

35m 58s

Intro
0:00
Overview
0:19
Source File Separation
2:31
Compilation Units
4:24
Example
4:34
Header File (Interface)
7:23
Include Header File
9:25
Example
10:12
Protect from Multi-Include
11:42
Example
12:33
Source File (Implementation)
14:05
Algorithms
14:23
Commands
15:49
Class Syntax
17:25
Private Member
18:00
Protected Member
18:23
Public Member
18:52
Class Prototype for Header
21:13
Class Implementation
23:21
Controlled Access
24:49
Inheritance
25:44
Implementation
27:44
Virtual Method
29:04
Pointer
31:37
Virtual Example
32:02
Base Class
32:12
Derived Classes
32:25
Polymorphic Example
33:14
Finished
35:23
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 Introduction to 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.
Since this lesson is not free, only the preview will appear on your website.
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Services

Lecture Comments (11)

2 answers

Last reply by: Alvin Sylvain
Thu Jun 25, 2015 6:55 PM

Post by Alex Moon on June 24, 2015

Hello, I don't understand what is being asked here.

2. Write a function that takes a float parameter, and uses it as the divisor into two, then subtracts two. That is, do the following arithmetic: (2.0 / parameter + 2.0)

Return the result in the parameter, but have a Boolean return value of “false” if the arithmetic can not be performed because the parameter is too small (we want to avoid getting overflow errors or divide-by-zero errors), or “true” otherwise. You will have to test the parameter before performing the operation.

Thus, if the function returns “true”, the parameter has been changed to its new value, and the caller may use it. Otherwise, it remains unchanged, and the return value tells the caller the parameter can not be used.


In "Return the result in the parameter, but have a Boolean return value of “false” if the arithmetic can not be performed ... or “true” otherwise"
is it telling me to create a function that can either return a boolean AND a float result?
Should the program print the value passed by reference in parameter? Thank you

2 answers

Last reply by: Timothy White
Fri Oct 31, 2014 7:42 AM

Post by Timothy White on October 30, 2014

Not necessarily related to this lecture, but is it possible to use C++ in a webpage? This is the first language I have learned that is not geared toward web development, so I wanted to know if there is a way to do so.

1 answer

Last reply by: Alvin Sylvain
Thu Jan 10, 2013 2:56 PM

Post by Karpis Sanosyan on January 10, 2013

Hello I have love the lessons and they really help, but i have a quick question. Its not as much as related to the lessons but to educator.com it's self. Could you please possible make an android and iPhone app for this site. Because I find that I don't always have my computer when I'm on the go and want to watch the lectures.

1 answer

Last reply by: Alvin Sylvain
Sun Oct 28, 2012 7:44 PM

Post by David McNeill on September 30, 2012

Alvin I hope you could help me move on to the next section in my course.
when doing homework for this section "functions part 2" i got rather confused on question 2. After struggling to understand the problem i came up with a solution but i don't know if it is the correct solution. Please help me move on so i know i understand what i have learned up until this point. here is my solution please let me know if I have understood your question:

//============================================================================
// Name : Function_Return_Boolean.cpp
// Author : David K McNeill
// Version : 1.0
// Copyright : Your copyright notice
// Description : checks a parameter is not to small before calculating and assigning the result to a variable.
//============================================================================

#include <iostream>
using namespace std;

// Function that checks if a parameter is not to small to divide.
// If parameter is not to small this function will perform the following arithmetic:
// 2.0 / parameter -2; it will then pass out the result to a parameter and return the
// value true to the caller.
// if the parameter is to small then it will return false to the caller.
bool divide_Add (float para, float & result, bool & a) {
//result = (2.0 / para -2);
if (para == 0) {
a = false;
}
else {
result = (2.0 / para -2);
a = true;
}
return a;
}

//global variables.
float para = 10; // parameter to be checked if its to small.
bool test = true; // variable that is assigned the function boolean return value.
bool a = false; // variable that determines what value the function returns.
float actual = 0; // variable we want to assign the function arithmetic to if all is Ok.
float result = 0; // variable that we assign the value of function arithmetic.

// main function
int main() {


test = divide_Add (para, result, a); // this is the call to the function
if (test == true) { // if function returns true we will assign the function arithmetic to are variable.
actual = result; // and print out "yippe it worked" as well as the value of 'actual', 'result' and 'para'.
cout << "Yippe it worked."<<endl;
cout << actual <<endl;
cout << result <<endl;
cout << para <<endl;
}
else {
cout << "number to small to use." <<endl; // if function returns false the this warning will be printed
} // and no value assigned to are variable.
return 0;
}

0 answers

Post by Alex Abraham on August 19, 2012

In the first example, the code is more broken than you think :p

The first time, it takes 7, adds 7, and gets 14.

The second time, it takes 14, adds 14, and gets 28.

The third time, it takes 28, adds 28, and gets 56.

One way to fix this error is to say something like: number = second; before the for statement and change the command in the for statement to number += second;

Also at the end it should say return number;

Functions, Part 2

  • A function may have “call by value” parameters, where the caller provides input arguments for the function to work on. The function is free to change the values of these parameters without affecting the caller. Where possible, this is the preferred method to increase isolation and maintainability.
  • A function may have “call by reference” parameters, where the caller expects the function to return new values for the input arguments.
  • A function may have “call by address” parameters, where the caller passes pointers as parameters.
  • A function may have default parameters that provide a default value for any argument not provided by the caller.
  • Each function usually has exactly one return value, or the caller’s “answer”, that will be used by the caller.
  • Functions may be overloaded which allows the same function name to be used with different prototypes.
  • Functions are crucial to creating modular code, avoiding code duplication, allowing more readable and reusable code. Readable code is easier to maintain. Reusable code saves time and effort. Modules should be insulated from their containing systems to decrease external dependencies, and increase reusability
  • Here are links to more information about C++ functions: http://www.cplusplus.com/doc/tutorial/functions/http://www.cplusplus.com/doc/tutorial/functions2/

Functions, Part 2

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
  • Overview 0:09
  • Parameters by Value 0:47
    • Example
  • Parameters by Reference 2:55
    • Example
  • Parameters by Reference Example 4:20
  • Default Parameters 6:36
    • Acceptable Example
    • Unacceptable Example
  • Default Parameters Example 7:42
  • Return Value 8:41
    • Special Type: Void
  • Overloading 11:07
    • Name Accordingly & Carefully
    • Example
  • Overloading Example 12:31
  • Modularization 13:41
    • Smaller Modules
    • Isolated Modules
  • Cut Into More Pieces 16:31
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.