sets c1

28
Pascal Programming Language Omar ElSabek & Fayez G hazzawi IT Engineering 3 th year UNKNOWN Department programming II

Upload: omar-al-sabek

Post on 13-Apr-2017

254 views

Category:

Education


1 download

TRANSCRIPT

Pascal Programming Language

Omar ElSabek & Fayez GhazzawiIT Engineering3th year – UNKNOWN Department

programming II

Welcome!

Hope you are doing fine!

Sets

Record

Files (Text & Binary)

Pointers

Linked Lists

Unit

Course Index :

What Do we need !

• Let’s Begin learning the SETS

Sets

A set is a collection of elements of same type.

Pascal allows defining the set data type.

The elements in a set are called members. In Pascal, sets are represented by enclosing the members within square brackets [ ]

The Proprieties

• items can not be repeated • ordinal• discrete• finite (in Pascal the maximum size of set is

256 item)

1. We CAN’T repeat values in a single Set

2. We should define the Set as a Type

3. In the arrays we can get the value of an element inside byarray[Num].But here ……. We just can’t

4. The max number of elements in the Set is 255 element

5. All the elements inside have the same Type (integer ,char ,boolean ,enumerated)

Type

set-identifier = set of base type ;

Var

s1, s2, ... : set-identifier;

Type

Color = (red, blue, yellow, green, white);

Var

s1, s2 : Color ;

Type

Color = (red, blue, yellow, green, white);

Days = (Mon, tue, wed, thu, fri, sat, sun);

Letters = set of char;

Alphabets = set of 'A' .. 'Z';

Examples:

Re-initialization

initialization

S1 = set of integer;

S2 = Set of 1..300

S3 = Set of char;

Program Lesson1_Program1 (input,output);

Type

Days = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);

Var

D : days

Begin

writeln (days(2)); { output Tue}readln;

End.

Program Lesson1_Program1 (input,output);

Type

Days = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);

Var

D : days

Begin

writeln (ord(Mon)); { output 1}

readln;

End.

Can We Define a Set in “Var” ????

Var

S : set of 1..70 ;

Remembering the ‘:’

17

S1 := [40, 55, 99, 40, 41, 44..55, 300];

40 41 55..99

Won’t add

S1

• The operations on Sets :

⋂ ⇔ * ⋃ ⇔ + / ⇔ - ⊆ ⇔ <= ⊇ ⇔ >= ∈ ⇔ in

19

20

Procedure ReadsetI (var S:SI; L:integer) ;var

i, x : integer;Begin

For i:=1 to L dobegin

Read(x);S := S + [x];

end;End;

Enumerated Type

Car= (kia,BMW,Toyota,ZTR,Mazda)