Compound Data CSCE 121 J. Michael Moore.

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

C Language.
Introduction to arrays
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
Arrays. Arrays  When a value is to be used in a program, a variable is declared to hold that value  What about storing the results of exams for a large.
CHAPTER 07 Arrays and Vectors (part I). OBJECTIVES 2 In this part you will learn:  To use the array data structure to represent a set of related data.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
1. 1. Introduction to Array 2. Arrays of Data 3. Array Declaration 4. Array Initialization 5. Operations on Array 6. Multidimensional Arrays 7. Index.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
OpenGL Shading Language
CSCE Introduction to Program Design and Concepts J. Michael Moore Spring 2015 Set 6: Miscellaneous 1 Based on slides created by Bjarne Stroustrup.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Parameter Passing: Arrays 1.Create new variables (boxes) for each of the formal parameters allocated on a fresh stack created for this function call. int.
Sections 10.1 – 10.4 Introduction to Arrays
Chapter 6: Using Arrays.
(Numerical Arrays of Multiple Dimensions)
Motivation and Overview
Computer Programming BCT 1113
Hassan Khosravi / Geoffrey Tien
EKT120 : Computer Programming
COSC 220 Computer Science II
STL Common tools for C++.
Lecture 7 – Arrays (1) PGT 106 : C PROGRAMMING.
Student Book An Introduction
Dynamic Memory CSCE 121 J. Michael Moore.
C++ Data Types Simple Structured Address Integral Floating
Operator Overloading CSCE 121 J. Michael Moore
C-Programming, continued
Classes & Objects CSCE 121 J. Michael Moore.
C Passing arrays to a Function
Pointers and Arrays S.Bhuvaneshwari Assistant Professor/CSE
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Visual Basic .NET BASICS
Multiple Dimension Arrays
Introduction to the Standard Template Library
7 Arrays.
Linked List Intro CSCE 121 J. Michael Moore.
Array & Pointers CSCE 121 J. Michael Moore.
EKT150 : Computer Programming
Return by Reference CSCE 121 J. Michael Moore.
Lecture 18 Arrays and Pointer Arithmetic
CSCI N207 Data Analysis Using Spreadsheet
COMP26120: Algorithms and Imperative programming
EKT120: Computer Programming
Arrays ICS2O.
Array Creation ENGR 1181 MATLAB 02.
STL: Traversing a Vector
Vectors.
Bingo Example: Design (Print Card Algorithm)
Multidimensional array
CMSC202 Computer Science II for Majors Lecture 03 – Arrays and Functions Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
Arrays ICS2O.
7 Arrays.
Vectors CSCE 121 J. Michael Moore.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Java SE 7 One and Multi Dimensional Arrays Module 6
Python: Sorting – Selection Sort
COP 3330 Object-oriented Programming in C++
Managing 2D Arrays Simple Dynamic Allocation
EECE.2160 ECE Application Programming
point when a program element is bound to a characteristic or property
Linked List Intro CSCE 121.
CSCE 206 Lab Structured Programming in C
Working with Arrays in MATLAB
Vectors CSCE 121.
Operator Overloading CSCE 121 Based on Slides created by Carlos Soto.
Reasoning with Types.
Presentation transcript:

Compound Data CSCE 121 J. Michael Moore

Large Sets of Data What to do?

Datatypes Simple Compound int, double, bool, etc. Homogeneous Heterogeneous Array Vector ?

Group of homogeneous elements accessed by an index. Array/Vector Group of homogeneous elements accessed by an index. Vector access with ary.at(index) Bounds checking Array and Vector access with ary[index] No bounds checking

Array Really a pointer Variable name is a pointer to the first element For ary[2] Conceptually: address of ary + 2*sizeof(array datatype) Actually: ary + 2 (math is done automatically) Pointer arithmetic Must know size of array at compile time Allows access to elements outside of array bounds Security problem

Vector Preferred over arrays Bounds checking We’ll use vectors instead of arrays for now. Bounds checking Prevents access outside array bounds Resizable #include <vector>

Vector Must say what type it is e.g. vector<int> Define size at beginning vector<int> vec = vector<int>(SIZE); vector<int> vec = vector<int>(SIZE,INIT_VAL); Let vector grow as needed vector<int> vec; vec.push_back(7); Increases size by one

Vector vector<int> vec; vec.push_back(7); vec.erase(vec.begin()+index); vec.at(index); // range checking & harder to read vec[index]; // no range checking & easier to read

Parallel Vectors Book calls them multiple vectors. Conceptually a set of items with multiple types of information People Name Age Weight Separate vectors for name, age and weight. Each index maps to the same person. Better way is to use a heterogeneous datatype (e.g. classes)

Multi-dimensional Vectors Matrix calculations Multi-dimensional data A vector of vectors vector< vector<int> > ary2d; Access ary2d.at(i).at(j) // safer ary2d[i][j] More later