Chapter 10: Records (structs)

Slides:



Advertisements
Similar presentations
Structure.
Advertisements

Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 7: User-Defined Functions II.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 10: Records ( structs )
Chapter 11: Records (structs)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 11: Records (structs)
Chapter 9: Arrays and Strings
Chapter 9: Arrays and Strings
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
More Storage Structures A Data Type Defined by You Characteristics of a variable of a specific ‘data type’ has specific values or range of values that.
EGR 2261 Unit 10 Records (structs)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Chapter 10: Records (structs)
Chapter 8 Arrays and Strings
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 11: Records ( struct s)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 10: Records ( struct s)
Chapter 10: Records (structs)
Edited from Powerpoint Slides provided by Thomson Learning
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Pointer and Array Lists Chapter 3, Summary CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
Structures (aka records, structs) Textbook Chapter 11 sections:
Data Structures Using C++1 Chapter 3 Pointers Dr. Liu.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Structures. Outline Introduction Structure Definitions and declarations Initializing Structures Operations on Structures members Structures as Functions.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 11: Records ( struct s)
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Chapter 9 Arrays. Chapter Objectives Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of “array index.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
Lecture 10: Structures. Outline Introduction Structure Definitions and declarations Initializing Structures Operations on Structures members Structures.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
EGR 2261 Unit 13 Classes Read Malik, Chapter 10.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 10-1: Structure.
Computer Programming BCT 1113
Chapter 7: Introduction to Classes and Objects
About the Presentations
MIS 120 Structures.
Records C++ Structs Chapter 10.1.
Chapter 15: Overloading and Templates
C++ Structs.
Records C++ Structs Chapter 12.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Lecture 9 Structure 1. Concepts of structure Pointers of structures
Heterogeneous aggregate datatypes
Structs And Arrays.
Chapter 9: Records (structs)
Chapter 9: Records (structs)
Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 9: Records (structs)
Review for Final Exam.
EGR 2261 Unit 12 structs Read Malik, Chapter 9.
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
Chapter 7: User-Defined Functions II
Review for Final Exam.
Structure.
Chapter 11: Records (structs)
C Programming Lecture-13 Structures
Chapter 9: Pointers and String
Chapter 12: Classes and Data Abstraction
Structure (i.e. struct) An structure creates a user defined data type
Chapter 10 C Structures and Unions
Chapter 9: Records (structs)
Chapter 11 Structure and Union Types.
Presentation transcript:

Chapter 10: Records (structs) C++ Programming: Program Design Including Data Structures, Second Edition Chapter 10: Records (structs)

Objectives In this chapter you will: Learn about records (structs) Examine various operations on a struct Explore ways to manipulate data using a struct Learn about the relationship between a struct and functions Discover how arrays are used in a struct Learn how to create an array of struct items C++ Programming: Program Design Including Data Structures, Second Edition

Records (structs) Struct: collection of a fixed number of components, accessed by name Components may be of different types Components of a struct are called the members of the struct struct is a reserved word C++ Programming: Program Design Including Data Structures, Second Edition

Records (structs) (continued) The general syntax of a struct is: struct structName { dataType1 identifier1; dataType2 identifier2; . dataTypen identifiern; }; C++ Programming: Program Design Including Data Structures, Second Edition

Accessing struct Members The syntax for accessing a struct member is: structVariableName.memberName The dot (.) is an operator, called the member access operator C++ Programming: Program Design Including Data Structures, Second Edition

Assignment Value of one struct variable can be assigned to another struct variable of the same type using an assignment statement The statement: student = newStudent; copies the contents of newStudent into student C++ Programming: Program Design Including Data Structures, Second Edition

Comparison (Relational Operators) Compare struct variables member-wise To compare the values of student and newStudent: if(student.firstName == newStudent.firstName && student.lastName == newStudent.lastName) . C++ Programming: Program Design Including Data Structures, Second Edition

Input/Output No aggregate input/output operations on a struct variable Data in a struct variable must be read one member at a time The contents of a struct variable must be written one member at a time C++ Programming: Program Design Including Data Structures, Second Edition

struct Variables and Functions A struct variable can be passed as a parameter by value or by reference A function can return a value of type struct C++ Programming: Program Design Including Data Structures, Second Edition

Arrays in structs Two key items are associated with a list: Values (elements) Length of the list Define a struct containing both items: const arraySize = 1000; struct listType { int listElem[arraySize]; //array containing the list int listLength; //length of the list }; C++ Programming: Program Design Including Data Structures, Second Edition

Summary Struct: collection of a fixed number of components Components can be of different types struct is a reserved word No memory is allocated for a struct; memory is allocated for struct variables when declared Components of a struct are called members C++ Programming: Program Design Including Data Structures, Second Edition

Summary struct components are accessed by name Dot (.) operator is called the member access operator Members of a struct are accessed using the dot (.) operator The only built-in operations on a struct are the assignment and member access C++ Programming: Program Design Including Data Structures, Second Edition

Summary Neither arithmetic nor relational operations are allowed on structs struct can be passed by value or reference A function can return a value of type struct A struct can be a member of another struct C++ Programming: Program Design Including Data Structures, Second Edition