Write an Pascal Program for Pascal – Sets - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Saturday, September 23, 2017

Write an Pascal Program for Pascal – Sets

Pascal – Sets

Program:
program setColors;
type
color = (red, blue, yellow, green, white, black, orange);
colors = set of color;

procedure displayColors(c : colors);
const
names : array [color] of String[7]
= ('red', 'blue', 'yellow', 'green', 'white', 'black', 'orange');
var
cl : color;
s : String;

begin
s:= ' ';
for cl:=red to orange do
if cl in c then
begin
if (s<>' ') then s :=s +' , ';
s:=s+names[cl];
end;
writeln('[',s,']');
end;

var
c : colors;

begin
c:= [red, blue, yellow, green, white, black, orange];
displayColors(c);

c:=[red, blue]+[yellow, green];
displayColors(c);

c:=[red, blue, yellow, green, white, black, orange] - [green, white];
displayColors(c);

c:= [red, blue, yellow, green, white, black, orange]*[green, white];
displayColors(c);

c:= [red, blue, yellow, green]><[yellow, green, white, black];
displayColors(c);
end.

Output:
[ red , blue , yellow , green , white , black , orange]
[ red , blue , yellow , green]
[ red , blue , yellow , black , orange]
[ green , white]

[ red , blue , white , black]

No comments:

Post a Comment