12-4 unions
DESCRIPTION
12-4 Unions. The union is a construct that allows memory to be shared by different types of data. This redefinition can be as simple as redeclaring an integer as four characters or as complex as redeclaring an entire structure. Topics discussed in this section:. Referencing Unions - PowerPoint PPT PresentationTRANSCRIPT
Computer Science: A Structured Programming Approach Using C 1
12-4 Unions
The union is a construct that allows memory to be The union is a construct that allows memory to be shared by different types of data. This redefinition can shared by different types of data. This redefinition can be as simple as redeclaring an integer as four be as simple as redeclaring an integer as four characters or as complex as redeclaring an entire characters or as complex as redeclaring an entire structure.structure.
Referencing UnionsInitializersUnions and StructuresInternet Addresses
Topics discussed in this section:Topics discussed in this section:
Computer Science: A Structured Programming Approach Using C 2
FIGURE 12-20 Unions
Computer Science: A Structured Programming Approach Using C 3
PROGRAM 12-7 Demonstrate Effect of Union
Computer Science: A Structured Programming Approach Using C 4
PROGRAM 12-7 Demonstrate Effect of Union
Computer Science: A Structured Programming Approach Using C 5
FIGURE 12-21 A Name Union
Computer Science: A Structured Programming Approach Using C 6
PROGRAM 12-8 Demonstrate Unions in Structures
Computer Science: A Structured Programming Approach Using C 7
PROGRAM 12-8 Demonstrate Unions in Structures
Computer Science: A Structured Programming Approach Using C 8
PROGRAM 12-8 Demonstrate Unions in Structures
Computer Science: A Structured Programming Approach Using C 9
PROGRAM 12-9 Convert IP Address to long
Computer Science: A Structured Programming Approach Using C 10
PROGRAM 12-9 Convert IP Address to long
Computer Science: A Structured Programming Approach Using C 11
PROGRAM 12-9 Convert IP Address to long
Computer Science: A Structured Programming Approach Using C 12
12-5 Programming Application
In this section, we develop a program that simulates In this section, we develop a program that simulates the operation of an elevator. The elevator serves floors the operation of an elevator. The elevator serves floors from zero (the basement) to the top floor. The elevator from zero (the basement) to the top floor. The elevator is very old and is not fully automatic. When people is very old and is not fully automatic. When people enter the elevator, they enter their desired floor enter the elevator, they enter their desired floor number. number.
Computer Science: A Structured Programming Approach Using C 13
FIGURE 12-22 Elevator Structure
Computer Science: A Structured Programming Approach Using C 14
FIGURE 12-23 Elevator Structure Chart
Computer Science: A Structured Programming Approach Using C 15
FIGURE 12-24 Elevator State Diagram
Computer Science: A Structured Programming Approach Using C 16
PROGRAM 12-10 Elevator: main
Computer Science: A Structured Programming Approach Using C 17
PROGRAM 12-10 Elevator: main
Computer Science: A Structured Programming Approach Using C 18
PROGRAM 12-11 Elevator: Initialize
Computer Science: A Structured Programming Approach Using C 19
PROGRAM 12-12 Elevator: Run Elevator
Computer Science: A Structured Programming Approach Using C 20
PROGRAM 12-12 Elevator: Run Elevator
Computer Science: A Structured Programming Approach Using C 21
PROGRAM 12-12 Elevator: Run Elevator
Computer Science: A Structured Programming Approach Using C 22
PROGRAM 12-13 Elevator: Move
Computer Science: A Structured Programming Approach Using C 23
PROGRAM 12-13 Elevator: Move
Computer Science: A Structured Programming Approach Using C 24
PROGRAM 12-13 Elevator: Move
Computer Science: A Structured Programming Approach Using C 25
PROGRAM 12-14 Elevator: Move Up and Move Down
Computer Science: A Structured Programming Approach Using C 26
PROGRAM 12-14 Elevator: Move Up and Move Down
Computer Science: A Structured Programming Approach Using C 27
PROGRAM 12-14 Elevator: Move Up and Move Down
Computer Science: A Structured Programming Approach Using C 28
PROGRAM 12-14 Elevator: Move Up and Move Down
Computer Science: A Structured Programming Approach Using C 29
PROGRAM 12-15 Elevator: Any Up and Any Down Request
Computer Science: A Structured Programming Approach Using C 30
PROGRAM 12-15 Elevator: Any Up and Any Down Request
Computer Science: A Structured Programming Approach Using C 31
PROGRAM 12-16 Elevator: Time Pass
Computer Science: A Structured Programming Approach Using C 32
PROGRAM 12-17 Elevator: Terminate
Computer Science: A Structured Programming Approach Using C 33
12-6 Software Engineering
In this section we discuss two important aspects of In this section we discuss two important aspects of program design: function coupling and data hiding.program design: function coupling and data hiding.
CouplingData Hiding
Topics discussed in this section:Topics discussed in this section:
Computer Science: A Structured Programming Approach Using C 34
Well-structured functions are highly cohesive and loosely coupled.
NoteNote
Computer Science: A Structured Programming Approach Using C 35
Stamp coupling should pass only the data needed.
NoteNote
Computer Science: A Structured Programming Approach Using C 36
Don’t bundle unrelated data to reduce the number of parameters.
NoteNote
Computer Science: A Structured Programming Approach Using C 37
Control coupling should be used only to pass status.
NoteNote
Computer Science: A Structured Programming Approach Using C 38
Avoid global coupling within a program.
NoteNote
Computer Science: A Structured Programming Approach Using C 39
Never use content coupling.
NoteNote
Computer Science: A Structured Programming Approach Using C 40
Programming Standard:Do not place any variables in the global area of a program.
NoteNote