{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CP1_10_Struct_1112

CP1_10_Struct_1112 - Structures Structures Compound...

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

View Full Document Right Arrow Icon
Structures: Compound Data
Image of page 1

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

View Full Document Right 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 example, are various properties of the same real-world 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, date 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 i bl variable: string h2011123456_name; int h2011123456_year_of_study; char h2011123456_gender; t i h2011123456 i l 2 CSIS1117B Computer Programming 1 2011-2012 string h2011123456_curriculum;
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. However, sometimes what we need is an aggregate or collection of data items of different types and the ability to handle the entire aggregate as a single item. This 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
Image of page 3

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

View Full Document Right 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. To define a struct , we define the names and types of the b th t t d b th t t members that are aggregated by the struct .
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern