{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

struct - Programming Structures 1 102 Prog Fundamentals...

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

View Full Document Right Arrow Icon
1 Programming Structures
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
2 P102 Prog. Fundamentals, Structures / Slide 2 Structures A Structure is a collection of related data items, possibly of different types. A structure type in C++ is called struct . A struct is heterogeneous in that it can be composed of data of different types. In contrast, array is homogeneous since it can contain only data of the same type.
Image of page 2
3 P102 Prog. Fundamentals, Structures / Slide 3 Structures Structures hold data that belong together . Examples: Student record: student id, name, major, gender, start year, … Bank account: account number, name, currency, balance, … Address book: name, address, telephone number, … In database applications, structures are called records.
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
4 P102 Prog. Fundamentals, Structures / Slide 4 Structures Individual components of a struct type are called members (or fields ). Members can be of different types (simple, array or struct). A struct is named as a whole while individual members are named using field identifiers. Complex data structures can be formed by defining arrays of structs .
Image of page 4
5 P102 Prog. Fundamentals, Structures / Slide 5 struct basics Definition of a structure: struct <struct-type>{ <type> <identifier_list>; <type> <identifier_list>; ... } ; Example: struct Date { int day; int month; int year; } ; The “Date” structure has 3 members, day, month & year. Each identifier defines a member of the structure.
Image of page 5

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

View Full Document Right Arrow Icon
6 P102 Prog. Fundamentals, Structures / Slide 6 struct examples Example: struct StudentInfo{ int Id; int age; char Gender; double CGA; }; Example: struct StudentGrade{ char Name[15]; char Course[9]; int Lab[5]; int Homework[3]; int Exam[2]; }; The “StudentGrade” structure has 5 members of different array types. The “StudentInfo” structure has 4 members of different types.
Image of page 6
7 P102 Prog. Fundamentals, Structures / Slide 7 struct examples Example: struct BankAccount{ char Name[15]; int AcountNo[10]; double balance; Date Birthday; }; Example: struct StudentRecord{ char Name[15]; int Id; char Dept[5]; char Gender; }; The “StudentRecord” structure has 4 members.
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
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