© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design in C Sixth Edition By Jeri R. Hanly & Elliot B. Koffman
1-2 © 2010 Pearson Addison-Wesley. All rights reserved. 1-2 Structures and Union Types A database is a collection of information stored in a computers memory or in a disk file. A database is subdivided into records, which normally contains information regarding specific data objects. The structure of the record is determined by the structure of the objects data type.
1-3 © 2010 Pearson Addison-Wesley. All rights reserved. 1-3 Structures and Union Types Define a structure type before it can be created or saved. #define STRSZ 10 typedef struct { char name[STRSZ]; double diameter; int moons; double orbit_time, rotation_time; } planet_t planet_t current_planet, previous_planet, blank_planet = {, 0, 0, 0, 0};
1-4 © 2010 Pearson Addison-Wesley. All rights reserved. 1-4 Figure 11.1 Assigning Values to Components of Variable current_planet p569
1-5 © 2010 Pearson Addison-Wesley. All rights reserved. 1-5 Figure 11.2 Function with a Structured Input Parameter
1-6 © 2010 Pearson Addison-Wesley. All rights reserved. 1-6 Figure 11.3 Function Comparing Two Structured Values for Equality
1-7 © 2010 Pearson Addison-Wesley. All rights reserved. 1-7 Figure 11.3 Function Comparing Two Structured Values for Equality (contd)
1-8 © 2010 Pearson Addison-Wesley. All rights reserved. 1-8 Figure 11.4 Function with a Structured Output Argument
1-9 © 2010 Pearson Addison-Wesley. All rights reserved. 1-9 Figure 11.5 Data Areas of main and scan_planet during Execution of status = scan_planet (¤t_planet);
1-10 © 2010 Pearson Addison-Wesley. All rights reserved Figure 11.6 Function get_planet Returning a Structured Result Type
1-11 © 2010 Pearson Addison-Wesley. All rights reserved Figure 11.7 Function to Compute an Updated Time Value
1-12 © 2010 Pearson Addison-Wesley. All rights reserved Figure 11.8 Structured Values as a Function Input Argument and as a Function Result
1-13 © 2010 Pearson Addison-Wesley. All rights reserved Figure 11.9 Data Type planet_t and Basic Operations
1-14 © 2010 Pearson Addison-Wesley. All rights reserved Figure Partial Implementation of Type and Operators for Complex Numbers
1-15 © 2010 Pearson Addison-Wesley. All rights reserved Figure Partial Implementation of Type and Operators for Complex Numbers (contd)
1-16 © 2010 Pearson Addison-Wesley. All rights reserved Figure Partial Implementatio n of Type and Operators for Complex Numbers (contd)
1-17 © 2010 Pearson Addison-Wesley. All rights reserved Figure Partial Implementation of Type and Operators for Complex Numbers (contd)
1-18 © 2010 Pearson Addison-Wesley. All rights reserved Figure Partial Implementation of Type and Operators for Complex Numbers (contd)
1-19 © 2010 Pearson Addison-Wesley. All rights reserved Figure An Array of Structures
1-20 © 2010 Pearson Addison-Wesley. All rights reserved Figure Universal Measurement Conversion Program Using an Array of Structures
1-21 © 2010 Pearson Addison-Wesley. All rights reserved Figure Universal Measurement Conversion Program Using an Array of Structures (contd)
1-22 © 2010 Pearson Addison-Wesley. All rights reserved Figure Universal Measurement Conversion Program Using an Array of Structures (contd)
1-23 © 2010 Pearson Addison-Wesley. All rights reserved Figure Universal Measurement Conversion Program Using an Array of Structures (contd)
1-24 © 2010 Pearson Addison-Wesley. All rights reserved Figure Universal Measurement Conversion Program Using an Array of Structures (contd)
1-25 © 2010 Pearson Addison-Wesley. All rights reserved Figure Data File and Sample Run of Measurement Conversion Program
1-26 © 2010 Pearson Addison-Wesley. All rights reserved Figure Function That Displays a Structure with a Union Type Component
1-27 © 2010 Pearson Addison-Wesley. All rights reserved Figure Two Interpretations of Parameter hair
1-28 © 2010 Pearson Addison-Wesley. All rights reserved Figure Program to Compute Area and Perimeter of Geometric Figures
1-29 © 2010 Pearson Addison-Wesley. All rights reserved Figure Program to Compute Area and Perimeter of Geometric Figures (contd)
1-30 © 2010 Pearson Addison-Wesley. All rights reserved Figure Program to Compute Area and Perimeter of Geometric Figures (contd)
1-31 © 2010 Pearson Addison-Wesley. All rights reserved Figure Program to Compute Area and Perimeter of Geometric Figures (contd)