![Page 1: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/1.jpg)
Structure and Union TypesChapter 10
1
![Page 2: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/2.jpg)
Chapter Objectives
• To learn how to declare a struct data type which consists of several data fields, each with its own name and data type
• To understand how to use a struct to store data for a structured object or record
• To learn how to use dot notation to process individual fields of a structured object
• To learn how to use structs as function parameters and to return function results
2
![Page 3: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/3.jpg)
Chapter Objectives
• To see how to create a struct data type for representing complex numbers and how to write functions that perform arithmetic operations on complex numbers
• To understand the relationship between parallel arrays and arrays of structured objects
• To learn about union data types and how they differ form structs
3
![Page 4: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/4.jpg)
User-Defined Structure Types
• record– a collection of information about one data object
• structure type– a data type for a record composed of multiple
components
• hierarchical structure– a structure containing components that are
structures
4
![Page 5: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/5.jpg)
User-Defined Structure TypesName: JupiterDiameter: 142,800 kmMoons: 16Orbit time: 11.9 yearsRotation time: 9.925 hours
5
![Page 6: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/6.jpg)
Individual Components of aStructured Data Object
• direct component selection operator– a period placed between a structure type variable
and a component name to create a reference to the component
6
![Page 7: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/7.jpg)
7
![Page 8: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/8.jpg)
8
![Page 9: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/9.jpg)
Structure Data Type as Input and Output Parameters
• When a structured variable is passed as an input argument to a function, all of its component values are copied into the components of the function’s corresponding formal parameter.
9
![Page 10: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/10.jpg)
Structure Data Type as Input and Output Parameters
• When such a variable is used as an output argument, the address-of operator must be applied in the same way that we would pass output arguments of the standard types char, int, and double.
10
![Page 11: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/11.jpg)
11
![Page 12: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/12.jpg)
12
![Page 13: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/13.jpg)
Structure Data Type as Input and Output Parameters
• indirect component selection operator– the character sequence -> placed between a
pointer variable and a component name creates a reference that follows the pointer to a structure and selects the component
13
![Page 14: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/14.jpg)
14
![Page 15: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/15.jpg)
15
![Page 16: Structure and Union Types - Temple Universitytuf80213/courses/temple/cis1057/slides/... · User-Defined Structure Types • record – a collection of information about one data object](https://reader031.vdocument.in/reader031/viewer/2022022013/5b3519877f8b9aa0238eb3b6/html5/thumbnails/16.jpg)
16