Heterogeneous aggregate datatypes

Slides:



Advertisements
Similar presentations
Sub and Function Procedures
Advertisements

1 Structures. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc) and other.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Structure.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Chapter 11: Records (structs)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 11: Records (structs)
User-defined Structure Types Structures: collection of data of different types. We can define a structure type student_t : typedef struct { string name;
©2004 Brooks/Cole Chapter 10 More on Classes. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting.
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.
Chapter 11: Structured Data. Slide Introduction An array makes it possible to access a list or table of data of the same data type by using a single.
EGR 2261 Unit 10 Records (structs)
Overloading Operators. Operators  Operators are functions, but with a different kind of name – a symbol.  Functions.
Functions Pass by Reference Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Fall 2005.
Cosc237/structures1 Structures aggregate data types record - single variable name for the whole collection composed of several variables - fields,BUT,
C++ Lecture 4 Tuesday, 15 July Struct & Classes l Structure in C++ l Classes and data abstraction l Class scope l Constructors and destructors l.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
5/3/01 Sudeshna Sarkar, CSE, IIT Kharagpur1 Structures Lecture
1 Chapter 11 Structured Data. 2 Topics 10.1 Abstract Data Types 10.2 Combining Data into Structures 10.3 Accessing Structure Members 10.4 Initializing.
Copyright © 2012 Pearson Education, Inc. Chapter 11: Structured Data.
More C++ Features True object initialisation
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11: Structured Data.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Structured Data Chapter 11. Combining Data Into Structures Structure: C++ construct that allows multiple variables to be grouped together Format: struct.
Chapter 7 A Data Types – Structures Structures Structure: C++ construct that allows multiple variables to be grouped together Structure Declaration.
Structured Data Types struct class Structured Data Types array – homogeneous container collections of only one type struct – heterogeneous data type.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
Structures (aka records, structs) Textbook Chapter 11 sections:
Data Structures Using C++1 Chapter 3 Pointers Dr. Liu.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
Data Structures Using C++1 Chapter 3 Pointers and Array-Based Lists.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14: More About Classes.
Chapter 8: Advanced Method Concepts. Understanding Parameter Types Mandatory parameter – An argument for it is required in every method call Four types.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
Objects with Functions and Arrays. Objects can be Passed Class defines type – Can use as type of function or parameter.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7. 12: Structures Starting Out with C++ Early Objects Eighth.
Chapter Structured Data 11. Combining Data into Structures 11.2.
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
LECTURE 3 PASS BY REFERENCE. METHODS OF PASSING There are 3 primary methods of passing arguments to functions:  pass by value,  pass by reference, 
Chapter 7: Introduction to Classes and Objects
Chapter 11: Structured Data.
Memberwise Assignment / Initialization
Data Types – Structures
Using local variable without initialization is an error.
DATA HANDLING.
Dynamic Memory Allocation Reference Variables
Data Types – Structures
Const in Classes CSCE 121 J. Michael Moore.
Pass by Reference, const, readonly, struct
METHODS AND BEHAVIORS AKEEL AHMED.
Structs And Arrays.
Chapter 9: Records (structs)
Chapter 9: Records (structs)
Chapter 10: Records (structs)
Arrays And Functions.
Chapter 9: Records (structs)
Return by Reference CSCE 121 J. Michael Moore.
Anatomy of a Function Part 3
Objects with Functions and Arrays
CS148 Introduction to Programming II
Reference Parameters.
Copy Assignment CSCE 121 J. Michael Moore.
Chapter 11: Records (structs)
Lec17 Structs.
Structure (i.e. struct) An structure creates a user defined data type
Copy Assignment CSCE 121.
Chapter 9: Records (structs)
Functions Chapter No. 5.
SPL – PS3 C++ Classes.
Presentation transcript:

Heterogeneous aggregate datatypes Structs Heterogeneous aggregate datatypes

Struct is a Definition Struct defines a new data type Composed of other types

Members Members : component parts of struct Member access operator : . variableName.member Address Identifier Value 16 15 s1.Name "Bob Smith" 14 13 12 11 10 9 8 7 s1.quizAvg 84 6 5 4 3 s1.labAvg 92 2 1

Initialization Can use initialization list Order MUST match struct order

Copy Assignment does memberwise copy of struct:

No other Aggregate Operations Assignment is the ONLY aggregate operation No >, <, +, cout, cin, etc…

No other Aggregate Operations Do operations based on members:

Broken Function This does not work…

Broken Function Memory going into function In function

Correct Function To modify struct take reference parameter: Main: Function:

Const Ref Struct parameter options Pass by value : make copy Pass by reference : work with original Pass const reference : work with original, prevent changes

Struct Return Function can return struct Declare variable Set values Return var

Return More realistic function:

Structs in Structs Can define struct using existing struct:

Structs in Structs Values in memory:

Fields of Fields Use . multiple times to drill down: