| | |
Pseudo-Pascal Question: Need Help!!
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hi,
I',m not sure but I think I'm allowed to post questions here showing my own work. I have the following question (not homework or anything assessed - Im revising for my final exam and this is a past paper question that i dont have model answers to).
I'd appreciate any help. I think It's relatively simple but I am unfamiliar with pascal and unsure of my own answers.
Question
a) Each of these definitions of a type is expressed in a PASCAL-like notation. For each right hand side:
1) Express it in terms of set-operations.2) Indicate one representative member of the set that it defines.3) Give its size.
TYPE
Colour = (yellow, red, blue, green);
Charr = ['a'..'z'];
Integerr = [1..99];
String = ARRAY[0..10] OF Charr;
Info = RECORD
I : Integerr;
S : String;
C : Colour;
END (*RECORD*);
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;
|1 : C : Colour;
|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
hue = SET OF Colour;
My Answers
1) Express it in terms of set-operations.
(yellow, red, blue, green)
={ (x1, x2, x3, x4)| x1 Î yellow, x2 Î red, x3 Î blue, x4 Î green}} ???
['a'..'z']
={ a|aÎ {a,b,c, …, z}}
[1..99]
={ a|aÎ {1, 2, 3, 4, …, 99} }
ARRAY[0..10] OF Charr;={ [a0, a2, …, a10]| aiÎ Charr}
Info = RECORD
I : Integerr;
S : String;
C : Colour;
END (*RECORD*);={ I, S, C | IÎ Integerr, SÎString, CÎColour }
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;|1 : C : Colour;|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);=??????
???????
?=Check cardinality of ‘card’:
If 0 then assign I as integer
If 1 then assign C as Colour
If 2 then assign CC as Charr
hue = SET OF Colour;
={ x | x Î (yellow, red, blue, green)
2) Indicate one representative member of the set that it defines.
(yellow, red, blue, green)
=(yellow, red, blue, green) ???
['a'..'z']=‘a’
[1..99]=1
ARRAY[0..10] OF Charr;
=[a, b, c, d, e, f, g, h, I, j]
Info = RECORD
I : Integerr;
S : String;
C : Colour;
END (*RECORD*);
={I=1, S=[a, b, c, d, e, f, g, h, I, j], C=(yellow, red, blue, green)}
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;|1 : C : Colour;|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
=???????
??????
hue = SET OF Colour;
={ (x1, x2, x3, x4)| xi Î Colour}
OK. Phew!!
vrec = Im stuk with this. Although I have worked out that:
------------------------------
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;
|1 : C : Colour;
|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
------------------------------
Is probably equal to:
------------------------------|
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;|1 : C : Colour;|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
------------------------------
The '|' sign is the logical 'or'. I'm also guessing that first the CARDINALITY of 'card' is first taken and cardinality is the number of members of the set called 'card'. Therefore when the cardinality is worked out, if it's 0 then the variable I is assigned the datatype Integerr, when its 1 the variable C is assigned the datatype Colour, and when its 2 the variable CC is assigned the datatype Charr.
As you can see i can't really answer parts 2 and 3 if im not sure of part 1. :cry:
I'd appreciate any help you can provide.
Thank you.
I',m not sure but I think I'm allowed to post questions here showing my own work. I have the following question (not homework or anything assessed - Im revising for my final exam and this is a past paper question that i dont have model answers to).
I'd appreciate any help. I think It's relatively simple but I am unfamiliar with pascal and unsure of my own answers.
Question
a) Each of these definitions of a type is expressed in a PASCAL-like notation. For each right hand side:
1) Express it in terms of set-operations.2) Indicate one representative member of the set that it defines.3) Give its size.
TYPE
Colour = (yellow, red, blue, green);
Charr = ['a'..'z'];
Integerr = [1..99];
String = ARRAY[0..10] OF Charr;
Info = RECORD
I : Integerr;
S : String;
C : Colour;
END (*RECORD*);
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;
|1 : C : Colour;
|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
hue = SET OF Colour;
My Answers
1) Express it in terms of set-operations.
(yellow, red, blue, green)
={ (x1, x2, x3, x4)| x1 Î yellow, x2 Î red, x3 Î blue, x4 Î green}} ???
['a'..'z']
={ a|aÎ {a,b,c, …, z}}
[1..99]
={ a|aÎ {1, 2, 3, 4, …, 99} }
ARRAY[0..10] OF Charr;={ [a0, a2, …, a10]| aiÎ Charr}
Info = RECORD
I : Integerr;
S : String;
C : Colour;
END (*RECORD*);={ I, S, C | IÎ Integerr, SÎString, CÎColour }
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;|1 : C : Colour;|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);=??????
????????=Check cardinality of ‘card’:
If 0 then assign I as integer
If 1 then assign C as Colour
If 2 then assign CC as Charr
hue = SET OF Colour;
={ x | x Î (yellow, red, blue, green)
2) Indicate one representative member of the set that it defines.
(yellow, red, blue, green)
=(yellow, red, blue, green) ???
['a'..'z']=‘a’
[1..99]=1
ARRAY[0..10] OF Charr;
=[a, b, c, d, e, f, g, h, I, j]
Info = RECORD
I : Integerr;
S : String;
C : Colour;
END (*RECORD*);
={I=1, S=[a, b, c, d, e, f, g, h, I, j], C=(yellow, red, blue, green)}
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;|1 : C : Colour;|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
=???????
?????? hue = SET OF Colour;
={ (x1, x2, x3, x4)| xi Î Colour}
OK. Phew!!
vrec = Im stuk with this. Although I have worked out that:
------------------------------
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;
|1 : C : Colour;
|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
------------------------------
Is probably equal to:
------------------------------|
vrec = RECORD
CASE card : CARDINAL OF
0 : I : Integerr;|1 : C : Colour;|2 : CC : Charr;
END (*CASE*);
END (*RECORD*);
------------------------------
The '|' sign is the logical 'or'. I'm also guessing that first the CARDINALITY of 'card' is first taken and cardinality is the number of members of the set called 'card'. Therefore when the cardinality is worked out, if it's 0 then the variable I is assigned the datatype Integerr, when its 1 the variable C is assigned the datatype Colour, and when its 2 the variable CC is assigned the datatype Charr.
As you can see i can't really answer parts 2 and 3 if im not sure of part 1. :cry:
I'd appreciate any help you can provide.
Thank you.
When the moon of happiness rose over the horizon of my will, I set out for the sun of arrival
OK. Been doing research. Got some things to add. It seems that:
Colour = (yellow, red, blue, green);
Just means that yellow, red, blue, green are all variable names, and are of type Colour. I think I've found out something about pascal records....will post back oncei get to grips with it.
Colour = (yellow, red, blue, green);
Just means that yellow, red, blue, green are all variable names, and are of type Colour. I think I've found out something about pascal records....will post back oncei get to grips with it.
When the moon of happiness rose over the horizon of my will, I set out for the sun of arrival
Found this at a pascal site:
------------------
Enumeration
An enumeration provides a technique of setting a list of integers where each item of the list is ranked and has a specific name. For example, instead of numbers that represent players of a football (soccer) game such as 1, 2, 3, 4, 5, you can use names instead. This would produce GoalKeeper, RightDefender, LeftDefender, Stopper, Libero. The syntax of creating an enumeration is type Series_Name = (Item1, Item2, Item_n);
In our example, the list of players by their name or position would be type Players = ( GoalKeeper, RightDefender, LeftDefender, Stopper, Libero );Once the list has been created, the name you give to the list, such as Players, becomes a variable of its own.
------------------
So I'm thinking that Colour must become a variable on its own, and the enumeration probably preserves the order of the things being enumerated. Therefore the answer to 1 would be somthing like this:
{(yellow, red, blue, green)| yellow, red, blue, green al belong to Colour }
------------------
Enumeration
An enumeration provides a technique of setting a list of integers where each item of the list is ranked and has a specific name. For example, instead of numbers that represent players of a football (soccer) game such as 1, 2, 3, 4, 5, you can use names instead. This would produce GoalKeeper, RightDefender, LeftDefender, Stopper, Libero. The syntax of creating an enumeration is type Series_Name = (Item1, Item2, Item_n);
In our example, the list of players by their name or position would be type Players = ( GoalKeeper, RightDefender, LeftDefender, Stopper, Libero );Once the list has been created, the name you give to the list, such as Players, becomes a variable of its own.
------------------
So I'm thinking that Colour must become a variable on its own, and the enumeration probably preserves the order of the things being enumerated. Therefore the answer to 1 would be somthing like this:
{(yellow, red, blue, green)| yellow, red, blue, green al belong to Colour }
When the moon of happiness rose over the horizon of my will, I set out for the sun of arrival
![]() |
Similar Threads
- dev pascal question (Pascal and Delphi)
- Pascal Question (Pascal and Delphi)
- MATLAB Help (Legacy and Other Languages)
- 12 hrs later (Geeks' Lounge)
Other Threads in the Pascal and Delphi Forum
- Next Thread: translation of Pascal script into matlab
| Thread Tools | Search this Thread |





