Chapter 2.6 Modula 2 Structured Types. Types in Modula 2 Simple Types: values can’t be decomposed –Ordinal Types: bijection with natural numbers –Reals:

Slides:



Advertisements
Similar presentations
Sorting algorithms Sieve of Eratosthenes
Advertisements

Pointers.
Introduction to Programming Lecture 15. In Today’s Lecture Pointers and Arrays Manipulations Pointers and Arrays Manipulations Pointers Expression Pointers.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Chapter 2.5 Modula 2 Control Instructions. Modula 2 Control Statements Selection statements –BOOLEAN Selector : IF statement –Ordinal Selector : CASE.
An Introduction to Hashing. By: Sara Kennedy Presented: November 1, 2002.
Chapter 7:: Data Types Programming Language Pragmatics
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
CS 331, Principles of Programming Languages Chapter 4 Types: Data Representation.
COMS W3156: Software Engineering, Fall 2001 Lecture #20: C, continued Janak J Parekh
Lecture 3 1. Structures 2. Abstract Data Types. STRUCTURES WHY ARE STRUCTURES NEEDED? If the predefined types are not adequate to model the object, create.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
13.5 Representing Data Elements Fields, Records, Blocks Variable-length Data Modifying Records.
1) Enumerated types 2) Records and structures 3) Accessing fields in records/structures 4) Operations on records/structures 5) Variant records 6) Dynamic.
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Pascal By: Liane Tom. Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
1.7 Arrays academy.zariba.com 1. Lecture Content 1.Basic Operations with Arrays 2.Console Input & Output of Arrays 3.Iterating Over Arrays 4.List 5.Cloning.
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.
Chapter 2.1 Program Design and Documentation. Summary System/Program specifications System/Program design –Top-down & Bottom-up design –Object Oriented.
Chapter 2.3 Modula 2 An Introduction. Summary First example Terminal symbols Comments Data –Constants –Variables Actions –Assignment statement –Control.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Pascal Course Spring Introduction Designed: 1968/9 by Niklaus Wirth Published: 1970 Imperative, structural, procedural Static and strong.
Structures, Unions, and Enumerations Chapter Data Structure ( 資料結構 ) Content of data –Attributes of an object Person:name, age, sex, … A poker card:suit.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
Structured Data Types array array union union struct struct class class.
Pointers & Dynamic Arrays Shinta P.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
CGS 3460 More On File IO. CGS 3460 What is a File n A file is a package of information with a name attached to it. n Files are used for various purposes:
1 Chapter Structured Types, Data Abstraction and Classes Dale/Weems.
1 Intro to Data Structures and ADTs Chapter 2. 2 Goal of Data Structures Organize data Facilitate efficient … –storage –retrieval –manipulation Select.
Lecture Set 12 Sequential Files and Structures Part D - Structures.
C++ Lecture 3 Monday, 14 July Arrays, Pointers, and Strings l Use of array in C++, multi- dimensional array, array argument passing l Pointers l.
Pascal CourseWinter 2010/111. Introduction Imperative and procedural programming language Designed: 1968/9 Published: 1970 Static and strong typing.
Pascal Course Spring Introduction Designed: 1968/9 by Niklaus Wirth Published: 1970 Imperative, structural, procedural Static and strong.
Structured Data Types struct class Structured Data Types array – homogeneous container collections of only one type struct – heterogeneous data type.
Chapter 11 Data Structures. Understand arrays and their usefulness. Understand records and the difference between an array and a record. Understand the.
Structures and Unions in C Alan L. Cox
Chapter 2.4 Modula 2 Simple Types. Constants and Variables Constants –Name –Value The value of a constant belongs to a type. Variables –Name –Type Type.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
ISBN Chapter 6 Structured Data Types Array Types Associative Arrays Record Types Union Types.
1 CSC241: Object Oriented Programming Lecture No 05.
Arrays Dr. Jose Annunziato. Arrays Up to this point we have been working with individual primitive data types Arrays allow working with multiple instances.
1 Info 3.2. Chapter 3.2 Recursive Data Structures Part 1 : Linear Lists.
1 Assertions. 2 A boolean expression or predicate that evaluates to true or false in every state In a program they express constraints on the state that.
Department of Computer Science and Engineering, HKUST 1 HKUST Summer Programming Course 2008 Using Member Functions and Data Members.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the relationship between arrays and pointers ❏ To understand the.
Subprograms - implementation. Calling a subprogram  transferring control to a subprogram: save conditions in calling program pass parameters allocate.
CGS 3460 Thus Far n Whenever we declare a variable, we specified its data type. n The data type helped us identify the type of information that a variable.
CCSA 221 Programming in C CHAPTER 11 POINTERS ALHANOUF ALAMR 1.
Data Structures in C++ Pointers & Dynamic Arrays Shinta P.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Advanced Programming Constants, Declarations, and Definitions Derived Data Types.
1 CSC 533: Programming Languages Spring 2014 Subprogram implementation  subprograms (procedures/functions/subroutines)  subprogram linkage  parameter.
Data Types Chapter 6: Data Types Lectures # 12. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
Imperative Programming C. Imperative Programming Heart of program is assignment statements Aware that memory contains instructions and data values Commands:
CHAPTER 4 VARIABLES & BINDING SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Brendan Murphy CS 377 Discussion 1 Brendan Murphy
Data Types In Text: Chapter 6.
CS 326 Programming Languages, Concepts and Implementation
Records Design Issues: 1. What is the form of references?
Structures and Unions in C
Pascal Winter 2010/ Course.
2. Understanding VB Variables
البرمجة بلغة الفيجول بيسك ستوديو
البرمجة بلغة فيجول بيسك ستوديو
kbkjlj/m/lkiubljj'pl;
Course Overview PART I: overview material PART II: inside a compiler
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

Chapter 2.6 Modula 2 Structured Types

Types in Modula 2 Simple Types: values can’t be decomposed –Ordinal Types: bijection with natural numbers –Reals: approx. representation for real values –Pointers: addresses in data memory Structured Types: Values have # components –Arrays: all components have same type –Records: components can have # types –Sets: small sets of ordinal values –Procedures: entire subprograms

Types in Modula 2 Simple Types: values can’t be decomposed –Ordinal Types: bijection with natural numbers –Reals: approx. representation for real values –Pointers: addresses in data memory Structured Types: Values have # components –Arrays: all components have same type –Records: components can have # types –Sets: small sets of ordinal values –Procedures: entire subprograms

ARRAY type index typecomponent type ARRAY type

ARRAY element array variable designatorindex expression array element

ARRAY applications MonSunSatFriThuWedTue info. teleN st.pr. teleEst.pr. teleEst.pr. info. st.pr.info. st.pr.info.

ARRAY applications TYPE Day = (Mon,Tue,Wed,Thu,Fri,Sat,Sun); Hour = [8..19]; Course = ARRAY[0..10] OF CHAR; Schedule = ARRAY Day, Hour OF Course; VAR RoomK1 : Schedule; BEGIN... RoomK1[Wed,8] := "info.";... END

Sieve of Eratosthenes Print all primes <= Max Make a set of cardinals 2 <= x <= MAX FOR all cardinals present in set Print the first cardinal x remaining in the set Remove all multiples of x from the set

Sieve of Eratosthenes Make a set of cardinals 2 <= x <= MAX CONST Max = 1000; VAR Sieve : ARRAY[2..Max] OF BOOLEAN; i : [2..Max];... FOR i:= 2 TO MAX DO Sieve[i] := TRUE END; (* FOR *) FALSE TRUE

Sieve of Eratosthenes FOR all cardinals present in the set Print the first cardinal in the set Remove all multiples of it VAR p : CARDINAL;... FOR i := 2 TO Max DO IF Sieve[i] THEN p := i; WriteCard(p,5); WriteLn; WHILE p <= Max DO Sieve[p] := FALSE; p := p + i END (* WHILE *) END (* IF *) END (* FOR *)

Types in Modula 2 Simple Types: values can’t be decomposed –Ordinal Types: bijection with natural numbers –Reals: approx. representation for real values –Pointers: addresses in data memory Structured Types: Values have # components –Arrays: all components have same type –Records: components can have # types –Sets: small sets of ordinal values –Procedures: entire subprograms

Repairing a flat tire Refinement of “tools” Tools : –Jack : device to lift a car –Wrench : device to loose or fasten bolts

RECORD example TYPE Date = RECORD Day : [1.. 31]; Month : [1.. 12]; Year : [ ] END; VAR Today : Date;

RECORD type END field listfields fixed fields field type

RECORD element record variable designator field identifier Today.Day := 20; Today.Month := 10; Today.Year := 1998; WITH Today DO Day := 20; Month := 10; Year := 1998; END

Nested RECORDs example (1) TYPE Date = RECORD Day : [1.. 31]; Month : [1.. 12]; Year : [ ] END; String = ARRAY [0..29] OF Char; Identity = RECORD Name, FirstName : String; BirthPlace : String; BirthDate : Date; IssueDate : Date; END; VAR Myself : Identity; Today : Date;

Nested RECORDs example (2) Today.Day := 20; Today.Month := 10; Today.Year := 1998 Myself.Name := "Tiberghien"; Myself.FirstName := "Jacques"; Myself.BirthPlace := "Berchem"; Myself.BirthDate.Day := 1; Myself.BirthDate.Month := 4; Myself.BirthDate.Year := 1946; Myself.IssueDate := Today;

Nested RECORDs example (2) WITH Today DO Day := 20; Month := 10; Year := 1998 END; WITH Myself DO Name := "Tiberghien"; FirstName := "Jacques"; BirthPlace := "Berchem"; WITH BirthDate DO Day := 1; Month := 4; Year := 1946; END; IssueDate := Today; END

Variant RECORDs variant variant list variant fields

Variant RECORD with explicit tag field Car =RECORD Weight : CARDINAL; NumberDoors : CARDINAL; FrameId,EngineId : ARRAY[0..19] OF CHAR; Fuel :(Gasoline,FuelOil,LPG,Electricity); CASE Engine :(Explosion,Electricity) OF Explosion : NbrCylinders : CARDINAL; VolCylinders : CARDINAL | Electricity : Supply : (AC,DC); Voltage : CARDINAL; END;

Variant RECORD with implicit tag field Car =RECORD Weight : CARDINAL; NumberDoors : CARDINAL; FrameId,EngineId : ARRAY[0..19] OF CHAR; Fuel :(Gasoline,FuelOil,LPG,Electricity); CASE (Explosion,Electricity) OF Explosion : NbrCylinders : CARDINAL; VolCylinders : CARDINAL | Electricity : Supply : (AC,DC); Voltage : CARDINAL; END;

Types in Modula 2 Simple Types: values can’t be decomposed –Ordinal Types: bijection with natural numbers –Reals: approx. representation for real values –Pointers: addresses in data memory Structured Types: Values have # components –Arrays: all components have same type –Records: components can have # types –Sets: small sets of ordinal values –Procedures: entire subprograms