CP1_10_Struct_1112

CP1_10_Struct_1112 - Structures: Structures: Compound...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
tructures: Structures: ompound Data Compound Data
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Multiple data items When we call our functions, we can pass built-in types (int, double, etc.) or type provided by the libraries (e.g string). We can also pass arrays of a single type. But what if we have multiple pieces of data which, for xample, are various properties of the same real- orld example, are various properties of the same real world entity? How can we keep them together and pass them around the application? For example, in a student registration application, we might maintain many pieces of information about a student: name, ate of birth gender curriculum contact details etc date of birth, gender, curriculum, contact details, etc. It would be inconvenient to have each of these in a single variable: string h2011123456_name; int h2011123456_year_of_study; char h2011123456_gender; 2 CSIS1117B Computer Programming 1 2011-2012 string h2011123456_curriculum;
Background image of page 2
Compound data The built-in types such as int, char, double, bool allow us to declare variables that hold a single item of data. If we want to create an aggregate a collection of data items of the same type we can use an array. yp y However, sometimes what we need is an aggregate or ollection of data items of ifferent types nd the ability to collection of data items of different types and the ability to handle the entire aggregate as a single item. his would allow us to collect together and manipulate data This would allow us to collect together and manipulate data related to a single concept . It is also useful to do this even if the related data are all of the same type. For example: Representing 2D points with real-valued x and y coordinates. 3 CSIS1117B Computer Programming 1 2011-2012
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
User-defined types Effectively, we want to define our own data types. For example, a Student type . C++ provides this facility with a data structure called struct for storing compound data.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

CP1_10_Struct_1112 - Structures: Structures: Compound...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online