Chapter 9 Programming I
Chapter 9 Programming I
Chapter 9 Programming I
Records (structs)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain
1
product or service or otherwise on a password-protected website for classroom
Objectives (1 of 2)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 2
product or service or otherwise on a password-protected website for classroom use.
Objectives (2 of 2)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 3
product or service or otherwise on a password-protected website for classroom use.
Records (structs) (1 of 3)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 4
product or service or otherwise on a password-protected website for classroom use.
Records (structs) (2 of 3)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 5
product or service or otherwise on a password-protected website for classroom use.
Records (structs) (3 of 3)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 6
product or service or otherwise on a password-protected website for classroom use.
Accessing struct Members (1 of 2)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 7
product or service or otherwise on a password-protected website for classroom use.
Accessing struct Members (2 of 2)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 8
product or service or otherwise on a password-protected website for classroom use.
Assignment (1 of 2)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 9
product or service or otherwise on a password-protected website for classroom use.
Assignment (2 of 2)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 10
product or service or otherwise on a password-protected website for classroom use.
Comparison (Relational Operators)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 11
product or service or otherwise on a password-protected website for classroom use.
Input/Output
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 12
product or service or otherwise on a password-protected website for classroom use.
struct Variables and Functions
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 13
product or service or otherwise on a password-protected website for classroom use.
Arrays versus structs
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 14
product or service or otherwise on a password-protected website for classroom use.
Arrays in structs (1 of 3)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 15
product or service or otherwise on a password-protected website for classroom use.
Arrays in structs (2 of 3)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 16
product or service or otherwise on a password-protected website for classroom use.
Arrays in structs (3 of 3)
• Consider these statements and refer to the figure below showing the results
following execution of the statements:
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 17
product or service or otherwise on a password-protected website for classroom use.
structs in Arrays (1 of 2)
• Example
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 18
product or service or otherwise on a password-protected website for classroom use.
structs in Arrays (2 of 2)
employeeType employees[50]
• Declares the array employees of 50 components of type employeeType
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 19
product or service or otherwise on a password-protected website for classroom use.
structs within a struct
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 20
product or service or otherwise on a password-protected website for classroom use.
Quick Review (1 of 2)
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 21
product or service or otherwise on a password-protected website for classroom use.
Quick Review (2 of 2)
• In C++, the dot (.) operator is called the member access operator
• Used to access members of a struct
• The only built-in operations on a struct are the assignment and member
access operations
• Neither arithmetic nor relational operations are allowed on structs
• A struct can be passed by value or reference
• A function can return a value of type struct
• A struct can be a member of another struct
© 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain 22
product or service or otherwise on a password-protected website for classroom use.