Upload
omar-al-sabek
View
254
Download
1
Embed Size (px)
Citation preview
Pascal Programming Language
Omar ElSabek & Fayez GhazzawiIT Engineering3th year – UNKNOWN Department
programming II
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
Color = (red, blue, yellow, green, white);
Days = (Mon, tue, wed, thu, fri, sat, sun);
Letters = set of char;
Alphabets = set of 'A' .. 'Z';
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.
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;