Lecture9_10 - Lecture 9 - Structured Data ECE 3090 Software...

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

View Full Document Right Arrow Icon
ECE 3090 Software for Engineering Systems Dr. Ayanna Howard School of Electrical and Computer Engineering Georgia Institute of Technology Lecture 9 - Structured 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
2 Adapted from “Brief Version of Starting Out with C++” Abstract Data Types A data type that specifies values that can be stored operations that can be done on the values User of an abstract data type does not need to know the implementation of the data type, e.g. , how the data is stored ADTs are created by programmers Abstraction : a definition that captures general characteristics without details Ex: An abstract triangle is a 3-sided polygon. A specific triangle may be scalene, isosceles, or equilateral Data Type defines the values that can be stored in a variable and the operations that can be performed on it
Background image of page 2
3 Adapted from “Brief Version of Starting Out with C++” Combining Data into Structures Structure : C++ construct that allows multiple variables to be grouped together General Format: struct < structName > { type 1 field 1 ; type 2 field 2 ; . . . };
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Adapted from “Brief Version of Starting Out with C++” struct Declaration Notes Must have ; after closing } struct names commonly begin with uppercase letter Multiple fields of same type can be in comma- separated list: string name, address;
Background image of page 4
5 Adapted from “Brief Version of Starting Out with C++” Defining Variables struct declaration does not allocate memory or create variables To define variables, use structure tag as type name: Student bill; studentID name yearInSchool gpa bill
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Adapted from “Brief Version of Starting Out with C++” Accessing Structure Members Use the dot (.) operator to refer to members of struct variables: cin >> stu1.studentID; getline(cin, stu1.name); stu1.gpa = 3.75; Member variables can be used in any manner appropriate for their data type
Background image of page 6
7 Adapted from “Brief Version of Starting Out with C++” Program 10-1
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Adapted from “Brief Version of Starting Out with C++” Program 10-1 Continued
Background image of page 8
9 Adapted from “Brief Version of Starting Out with C++” Displaying a struct Variable To display the contents of a struct variable, must display each field separately, using the dot operator: cout << bill; // won’t work cout << bill.studentID << endl; cout << bill.name << endl; cout << bill.yearInSchool; cout << " " << bill.gpa;
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Adapted from “Brief Version of Starting Out with C++” Comparing struct Variables Cannot compare struct variables directly: if (bill == william) // won’t work Instead, must compare on a field basis: if (bill.studentID == william.studentID) . ..
Background image of page 10
11 Adapted from “Brief Version of Starting Out with C++” Initializing a Structure struct variable can be initialized when defined: Student s = {11465, "Joan", 2, 3.75}; Can also be initialized member-by-member after definition: s.name = "Joan"; s.gpa = 3.75;
Background image of page 11

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

View Full DocumentRight Arrow Icon
12 Adapted from “Brief Version of Starting Out with C++” More on Initializing a Structure
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 53

Lecture9_10 - Lecture 9 - Structured Data ECE 3090 Software...

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

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