Professional Documents
Culture Documents
Object Oriented
Programming in C++
Professor Fowler
Last Time
2
Agenda
Ch 7 - Object Oriented Programming
7.1 Abstract Data Types 7.8 Private member Functions
3
Theme for Today
4
“Initializing Classes”
5
Chapter 7
Object Oriented
Programming
6
Agenda
Ch 7 - Object Oriented Programming
7.1 Abstract Data Types 7.8 Private member Functions
7
Agenda
Ch 7 - Object Oriented Programming
7.1 Abstract Data Types 7.8 Private member Functions
8
Accountability Groups
9
Purpose
10
First Meeting
11
Activities
1. Quick Check - 1/2 words on how you’re doing.
12
Debrief
Programming Exercise
Coding Exercise
14
7.6 Constructors
18
Constructors
19
• Does this mean classes which we have not created
a constructor, do not have constructors?
20
Constructor Use Case
Initialize data.
Serve as an interface.
21
Constructors as an interface
22
Overloading Constructors
• Computer always makes a default constructor - unless you write
ANY other constructor.
24
Bottom Line
25
Constructors, functions
and methods, Oh my!
27
• Distinguishing between various constructors and
methods can be confusing.
28
Class ABC {
};
int main() {
ABC x; // Default - works fine
ABC x(); // Error - thinks it’s a method
ABC x(10) // Fine - overloaded default
Exercise
C++ Debugging
Exercise Goals
• Debugging Practice
31
Debug Exercise
32
7.7 Destructors
34
• Constructors!
• Destructors!
37
• Our objects use regular variables all the time (ints,
floats, etc).
38
Nothing we haven’t
seen before.
Now, we go ahead an access it …
Now, we go ahead an access it …
Now, we go ahead an access it …
48
10.12 Selecting
Members of Objects
50
What do we do when we need to access pointers
inside objects?
Programming Exercise
Activity
Coding Exercise
Create a Date class with private member ints day,
month, and year. Add a print public member function
to display the date. Use constructors to initialize to
specified values or default values if nothing is
specified. Set to error date of 99/99/9999 if any
invalid date values are used (don’t make this an
exhaustive test).
54
What’s this section
about?
55
Theme for Today
“Method.”
56
Agenda
Ch 7 - Object Oriented Programming
7.1 Abstract Data Types 7.8 Private member Functions
57
What’s Next?
58
Agenda
Ch 7 - Object Oriented Programming
7.1 Abstract Data Types 7.8 Private member Functions
59
Agenda
Ch 7 - Object Oriented Programming
7.1 Abstract Data Types 7.8 Private member Functions
60
Chapter 12 quiz SUNDAY
61
10.13 Smart Pointers
62
Use Case
63
Modify This
65
Exercise
Programming Exercise
Exercise Goals
• Construct Knowledge
68
Programming Exercise
• Get 10-2demo.cpp working
• Explain
• Debugging Practice
71
Debug Exercise
72
Programming Exercise
Activity
Exercise Goals
• Construct Knowledge
75
Programming Exercise
• With 10-2demo.cpp
76
Coding Exercise
77