Download presentation
Presentation is loading. Please wait.
Published bySusan Hopkins Modified over 9 years ago
1
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the structure, union, and enumerated types ❏ To use the type definition statement in programs ❏ To use enumerated types, including anonymous types. ❏ To create and use structures in programs ❏ To be able to use unions in programs ❏ To understand the software engineering concept of coupling and to be able to evaluate coupling between functions. Chapter 12 Chapter 12 Enumerated, Structure, Enumerated, Structure, and Union Types and Union Types
2
Computer Science: A Structured Programming Approach Using C2 FIGURE 12-1 Derived Types
3
Computer Science: A Structured Programming Approach Using C3 12-1 The Type Definition (typedef) Before discussing the derived types, let’s discuss a C declaration that applies to all of them—the type definition. A type definition, typedef, gives a name to a data type by creating a new type that can then be used anywhere a type is permitted.
4
Computer Science: A Structured Programming Approach Using C4 FIGURE 12-2 Type-definition Format
5
Computer Science: A Structured Programming Approach Using C5 12-2 Enumerated Types The enumerated type is a user-defined type based on the standard integer type. In an enumerated type, each integer value is given an identifier called an enumeration constant. Declaring an Enumerated Type Operations on Enumerated Types Enumeration Type Conversion Initializing Enumerated Constants Anonymous Enumeration: Constants Input/Output Operations Topics discussed in this section:
6
Computer Science: A Structured Programming Approach Using C6 PROGRAM 12-1Print Cable TV Stations
7
Computer Science: A Structured Programming Approach Using C7 PROGRAM 12-1Print Cable TV Stations
8
Computer Science: A Structured Programming Approach Using C8 Don’t be confused about strings and enumerated types. “Jan” is a string made of three characters; JAN as defined in the previous code example, is an enumerated type (identifier) which has the integer value 1. Note
9
Computer Science: A Structured Programming Approach Using C9 12-3 Structure A structure is a collection of related elements, possibly of different types, having a single name. Structure Type Declaration Initialization Accessing Structures Operations on Structures Complex Structures Structures and Functions Topics discussed in this section:
10
Computer Science: A Structured Programming Approach Using C10 FIGURE 12-3 Structure Examples
11
Computer Science: A Structured Programming Approach Using C11 Elements in a structure can be of the same or different types. However, all elements in the structure should be logically related. Note
12
Computer Science: A Structured Programming Approach Using C12 FIGURE 12-4 Tagged Structure Format
13
Computer Science: A Structured Programming Approach Using C13 FIGURE 12-5 Structure Declaration with typedef
14
Computer Science: A Structured Programming Approach Using C14 FIGURE 12-6 Structure Declaration Format and Example
15
Computer Science: A Structured Programming Approach Using C15 FIGURE 12-7 Initializing Structures
16
Computer Science: A Structured Programming Approach Using C16 FIGURE 12-8 Structure Direct Selection Operator
17
Computer Science: A Structured Programming Approach Using C17 PROGRAM 12-2Multiply Fractions
18
Computer Science: A Structured Programming Approach Using C18 PROGRAM 12-2Multiply Fractions
19
Computer Science: A Structured Programming Approach Using C19 FIGURE 12-9 Copying a Structure
20
Computer Science: A Structured Programming Approach Using C20 FIGURE 12-10 Pointers to Structures
21
Computer Science: A Structured Programming Approach Using C21 (*pointerName).fieldName pointerName - >fieldName. Note
22
Computer Science: A Structured Programming Approach Using C22 FIGURE 12-11 Interpretation of Invalid Pointer Use
23
Computer Science: A Structured Programming Approach Using C23 FIGURE 12-12 Indirect Selection Operator
24
Computer Science: A Structured Programming Approach Using C24 PROGRAM 12-3Clock Simulation with Pointers
25
Computer Science: A Structured Programming Approach Using C25 PROGRAM 12-3Clock Simulation with Pointers
26
Computer Science: A Structured Programming Approach Using C26 PROGRAM 12-3Clock Simulation with Pointers
27
Computer Science: A Structured Programming Approach Using C27 PROGRAM 12-3Clock Simulation with Pointers
28
Computer Science: A Structured Programming Approach Using C28 FIGURE 12-13 Nested Structure
29
Computer Science: A Structured Programming Approach Using C29 FIGURE 12-14 Arrays in Structures
30
Computer Science: A Structured Programming Approach Using C30 FIGURE 12-15 Pointers in Structures
31
Computer Science: A Structured Programming Approach Using C31 FIGURE 12-16 Array of Structures
32
Computer Science: A Structured Programming Approach Using C32 PROGRAM 12-4Sort Array of Student Structures
33
Computer Science: A Structured Programming Approach Using C33 PROGRAM 12-4Sort Array of Student Structures
34
Computer Science: A Structured Programming Approach Using C34 PROGRAM 12-4Sort Array of Student Structures
35
Computer Science: A Structured Programming Approach Using C35 PROGRAM 12-4Sort Array of Student Structures
36
Computer Science: A Structured Programming Approach Using C36 PROGRAM 12-4Sort Array of Student Structures
37
Computer Science: A Structured Programming Approach Using C37 PROGRAM 12-4Sort Array of Student Structures
38
Computer Science: A Structured Programming Approach Using C38 FIGURE 12-17 Passing Structure Members to Functions
39
Computer Science: A Structured Programming Approach Using C39 FIGURE 12-18 Passing and returning structures
40
Computer Science: A Structured Programming Approach Using C40 PROGRAM 12-5Passing and Returning Structures
41
Computer Science: A Structured Programming Approach Using C41 PROGRAM 12-5Passing and Returning Structures
42
Computer Science: A Structured Programming Approach Using C42 PROGRAM 12-5Passing and Returning Structures
43
Computer Science: A Structured Programming Approach Using C43 PROGRAM 12-5Passing and Returning Structures
44
Computer Science: A Structured Programming Approach Using C44 PROGRAM 12-5Passing and Returning Structures
45
Computer Science: A Structured Programming Approach Using C45 FIGURE 12-19 Passing Structures Through Pointers
46
Computer Science: A Structured Programming Approach Using C46 PROGRAM 12-6Passing Structures through Pointers
47
Computer Science: A Structured Programming Approach Using C47 PROGRAM 12-6Passing Structures through Pointers
48
Computer Science: A Structured Programming Approach Using C48 PROGRAM 12-6Passing Structures through Pointers
49
Computer Science: A Structured Programming Approach Using C49 PROGRAM 12-6Passing Structures through Pointers
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.