EGR 2261 Unit 10 Records (structs)

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Structure.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Structures Spring 2013Programming and Data Structure1.
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 10: Records ( structs )
Chapter 14: Overloading and Templates C++ Programming: Program Design Including Data Structures, Fifth Edition.
Chapter 14: Overloading and Templates
Chapter 11: Records (structs)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 11: Records (structs)
Chapter 9: Arrays and Strings
Chapter 13: Overloading.
Chapter 8 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.
Chapter 15: Operator Overloading
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 14: Overloading and Templates.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 15: Overloading and Templates.
Pointer Data Type and Pointer Variables
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
Chapter 6: User-Defined Functions
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)
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
Chapter 10: Records (structs)
Edited from Powerpoint Slides provided by Thomson Learning
EGR 2261 Unit 9 Strings and C-Strings  Read Malik, pages in Chapter 7, and pages in Chapter 8.  Homework #9 and Lab #9 due next week.
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
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.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
Structures (aka records, structs) Textbook Chapter 11 sections:
Data Structures Using C++1 Chapter 3 Pointers Dr. Liu.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Chapter 13: Overloading and Templates. Objectives In this chapter, you will – Learn about overloading – Become familiar with the restrictions on operator.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 11: Records ( struct s)
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
EGR 2261 Unit 13 Classes Read Malik, Chapter 10.
REVISION CSC 138 – Structured Programming One Dimensional Array
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
About the Presentations
MIS 120 Structures.
Records C++ Structs Chapter 10.1.
C++ Structs.
Records C++ Structs Chapter 12.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Heterogeneous aggregate datatypes
Structs And Arrays.
Chapter 9: Records (structs)
Chapter 9: Records (structs)
Chapter 10: Records (structs)
Chapter 9: Records (structs)
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
Chapter 11: Records (structs)
Chapter 9: Records (structs)
Presentation transcript:

EGR 2261 Unit 10 Records (structs) Read Malik, Chapter 9. Homework #10 and Lab #10 due next week. Quiz next week.

Chapter 9: Records (structs)

Objectives In this chapter, you will: Learn about records (structs) Examine various operations on a struct Manipulate data using a struct Learn about the relationship between a struct and functions Examine the difference between arrays and structs C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Objectives (cont’d.) Discover how arrays are used in a struct Learn how to create an array of struct items Learn how to create structs within structs C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Records (structs) struct: collection of a fixed number of components (members), accessed by name Members may be of different types Syntax: C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Records (structs) (cont’d.) A struct is a definition, not a declaration Must declare a variable of that type to use it C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Records (structs) (cont’d.) C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Accessing struct Members Syntax to access a struct member: The dot (.) is called the member access operator C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Accessing struct Members (cont’d.) To initialize the members of newStudent: newStudent.GPA = 0.0; newStudent.firstName = "John"; newStudent.lastName = "Brown"; C++ Programming: From Problem Analysis to Program Design, Seventh 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: From Problem Analysis to Program Design, Seventh Edition

Assignment (cont’d.) The assignment statement: student = newStudent; is equivalent to the following statements: student.firstName = newStudent.firstName; student.lastName = newStudent.lastName; student.courseGrade = newStudent.courseGrade; student.testScore = newStudent.testScore; student.programmingScore = newStudent.programmingScore; student.GPA = newStudent.GPA; C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Comparison (Relational Operators) Compare struct variables member-wise No aggregate relational operations allowed To compare the values of student and newStudent: C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Input/Output No aggregate input/output operations on a struct variable Data in a struct variable must be read or written one member at a time Example: output newStudent contents C++ Programming: From Problem Analysis to Program Design, Seventh 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: From Problem Analysis to Program Design, Seventh Edition

Arrays versus structs C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Arrays in structs Two items are associated with a list: Values (elements) Length of the list Define a struct containing both items: C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Arrays in structs (cont’d.) C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Arrays in structs (cont’d.) C++ Programming: From Problem Analysis to Program Design, Seventh Edition

structs in Arrays Example: C++ Programming: From Problem Analysis to Program Design, Seventh Edition

structs in Arrays (cont’d.) C++ Programming: From Problem Analysis to Program Design, Seventh Edition

structs within a struct C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Summary struct: collection of a fixed number of components Components can be of different types Called members Accessed by name struct is a reserved word No memory is allocated for a struct Memory when variables are declared C++ Programming: From Problem Analysis to Program Design, Seventh Edition

Summary (cont’d.) Dot (.) operator: member access operator Used to access members of a struct The only built-in operations on a struct are the assignment and member access Neither arithmetic nor relational operations are allowed on structs A struct can be passed by value or reference A function can return a value of type struct structs can be members of other structs C++ Programming: From Problem Analysis to Program Design, Seventh Edition