Professional Documents
Culture Documents
L 13 (May - 15 - 2016)
L 13 (May - 15 - 2016)
Lecture #13
Spring 2016
Structure
• Single structures
• Arrays of structures
• Structures as function arguments
• Linked lists
Object Oriented Programming I
• Classes
• Basic class functions
• Adding class functions
Case Study: Constructing Date Object
• Reading Assignments
• Chapter 11 of the text book
• Chapter 13 of the text book
• Dynamic Structure Allocation
• Complex Numbers
2
Single Structures ASTU
4
Example 2: Global Declaration ASTU
5
Arrays of Structures ASTU
ID Name Groups
7
Example 3: Array of Structures ASTU
8
Structures as Function Arguments ASTU
9
Structures as Function Arguments ASTU
10
Example 4: Passing by Value ASTU
11
Example 4: Passing by Value ASTU
12
Example 5: Passing by Reference ASTU
• Change line 10
13
Passing a Pointer ASTU
14
Example 6: Passing Pointer ASTU
• Change line 10
• Change line 15
15
Passing a Pointer ASTU
16
Passing a Pointer ASTU
17
Changing Pointer Address ASTU
18
Returning Structures ASTU
19
Example 7: Returning Structures ASTU
20
Linked Lists ASTU
22
Linked Lists ASTU
23
Linked Lists ASTU
24
Linked Lists ASTU
25
Linked Lists ASTU
26
Example 8: Linked List ASTU
27
The Relationship between Structures ASTU
28
Example 10: Cycling through the List ASTU
29
Example 10: Cycling through the List ASTU
30
Classes ASTU
32
Abstract Data Types ASTU
33
Abstract Data Types ASTU
35
Class Construction ASTU
37
Class Construction ASTU
39
Class Construction ASTU
40
Example 1: Complete Program ASTU
• Modify Example 1
– Insert the following
41
Class Construction ASTU
42
Class Construction ASTU
43
Terminology ASTU
45
Constructor Functions ASTU
47
Calling Constructors ASTU
48
Example 2: Constructors ASTU
49
Accessor Functions ASTU
50
Mutator Function ASTU
51
Example 3: Accessors and Mutators ASTU
52
Example 3: Accessors and Mutators ASTU
53
Adding Class Functions ASTU
55
Example 4: Member Functions ASTU
56
Example 4: Member Functions ASTU
57
Friend Functions ASTU
58
Friend Functions ASTU
59
Friend Functions ASTU
60
Example 5: Friend Functions ASTU
61
Example 5: Friend Functions ASTU
62
Case Study: Constructing Date Object ASTU
63
Case Study: Constructing Date Object ASTU
• Data Structure
– In this application, you have one type of
object, a date, which is specified by a
month, day, and year.
64
Case Study: Constructing Date Object ASTU
• Required Operations
– A complete description of a Date class must
include how a date is to be represented and
the operations the class must provide.
65
Case Study: Constructing Date Object ASTU
• Data Members
66
Code the Solution ASTU
67
Code the Solution ASTU
71