Arrays, Casting & User Defined Variables

Slides:



Advertisements
Similar presentations
Exposure C++ Chapter XVI C++ Data Structures, the Record.
Advertisements

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.
EC-211 DATA STRUCTURES LECTURE 2. EXISTING DATA STRUCTURES IN C/C++ ARRAYS – A 1-D array is a finite, ordered set of homogeneous elements – E.g. int a[100]
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
Structure.
Chapter 7:: Data Types Programming Language Pragmatics
Objectives Learn about objects and reference variables Explore how to use predefined methods in a program.
CSC 142 J 1 CSC 142 Arrays [Reading: chapter 10].
1 Structures. Structure (struct) Definition A Structure is a container, it can hold a bunch of things. –These things can be of any type. Structures are.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Arrays Array – Group of contiguous memory locations Each memory location has same name Each memory location has same type.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
CISC105 – General Computer Science Class 9 – 07/03/2006.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
P OINTERS A pointer is an address All data is stored in memory in some location that is indexed with an address Can refer to variables by name or by memory.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Introduction toData structures and Algorithms
Lecture 5 array declaration and instantiation array reference
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Pascal Programming Arrays and String Type.
Java Arrays and ArrayLists COMP T1 #5
GC211 Data Structure Lecture 1 Sara Alhajjam.
Two-Dimensional Arrays
Arrays Low level collections.
Chapter 10-1: Structure.
Pointers, Enum, and Structures
Array, Strings and Vectors
Complex data types Complex data types: a data type made of a complex of smaller pieces. Pascal has four very commonly used complex data types: strings,
Chapter 7 Part 1 Edited by JJ Shepherd
A simple way to organize data
Enumerated DATA Types Enum Types Enumerated Data Types
Programming Languages and Paradigms
C++ Arrays.
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Complex Data Types One very important measure of the “goodness” of a PL is the capability of its data types to model the problem space variables Design.
Arrays An Array is an ordered collection of variables
Data Types and Expressions
Increment and Decrement
Chapter 10: Records (structs)
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Lecture 18 Arrays and Pointer Arithmetic
ArrayLists.
Introduction To Programming Information Technology , 1’st Semester
Why arrays are cool 4/25/2007.
Arrays .
Chapter 1: Introduction to Data Structures(8M)
Building Java Programs
Arrays ICS2O.
Enumerated DATA Types Enum Types Enumerated Data Types
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
ArrayLists 22-Feb-19.
CISC181 Introduction to Computer Science Dr
Building Java Programs
CSC 142 Arrays [Reading: chapter 12].
C Programming Lecture-8 Pointers and Memory Management
Structures In C Programming By Rajanikanth B.
Java Programming Language
C Programming Pointers
Chapter 6 Part 1.
Variables and Computer Memory
CS149D Elements of Computer Science
Java: Variables, Input and Arrays
Arrays and Pointers CSE 2031 Fall May 2019.
LINEAR DATA STRUCTURES
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

Arrays, Casting & User Defined Variables G6DICP - Lecture 10 Arrays, Casting & User Defined Variables

Data Structures Data is stored in variables Closely related data items may conveniently be stored in a “data structure” Data structures are complex variables that contain more than one item of data “Metavariables” - variables containing variables Arrays are a common form of data structure

Arrays Arrays are a data structure that contains a group of data items (elements) All elements must be of a single type Elements are indexed by an integer Arrays are of a pre-determined size For example: An array of 3 integers called data data[0]=3; data[1]=24; data[2]=12; An array of 3 Strings called day: day[0]=“Monday”; day[1]=“Tuesday”; day[2]=“Wednesday”

Java Arrays Arrays are a variables type, and so must be declared int[] data; or int data[]; Before they can be used, arrays must be initialized This determines their size The new reserved word allocates memory to a data structure, fixing the size and type of an array data = new int[3]; Once initialized elements of the array may be addressed by index (counting from 0) data[0] data[1] data[2]

Casting A simple form of data type conversion For example if you need to use the double 5.0 as an int then it must be converted to an int Syntax: double d=5; int I = (int) d; Many types can be cast into many other types Only if this makes sense! Information may be lost in the casting process

User defined data types Composite data structures A data type containing several different data types Analagous to a record of a flat field database Record in Pascal Struct in C Class in Java

A simple Class declaration class Person { String name; String email; String room; int phone; }

Using a user defined class Person tim; tim = new Person(); tim.name = “Tim Brailsford”; tim.email = “tjb@cs.nott.ac.uk”; tim.room = “C5”; tim.phone = 14231;