Pascal 显示特定类型的所有变量
我想在Pascal 显示特定类型的所有变量,pascal,freepascal,Pascal,Freepascal,我想在WriteFoodMenu中创建一个菜单,允许用户显示所有可用选项(这是WriteLn当前在WriteFoodMenu中所做的操作),或者只显示所选场馆所在的选项 例如,如果用户选择“Bakery” WriteLn(mfood.foodtype, ' - ', mfood.chef, ' - ', mfood.venue); 将仅显示场地为面包店的选项 编辑:如果我需要包括任何其他内容,请告诉我 type Venues =(cafe, resteraunt, bakery, milkb
WriteFoodMenu
中创建一个菜单,允许用户显示所有可用选项(这是WriteLn
当前在WriteFoodMenu
中所做的操作),或者只显示所选场馆所在的选项
例如,如果用户选择“Bakery”
WriteLn(mfood.foodtype, ' - ', mfood.chef, ' - ', mfood.venue);
将仅显示场地为面包店的选项
编辑:如果我需要包括任何其他内容,请告诉我
type
Venues =(cafe, resteraunt, bakery, milkbar, fastfood);
Mfood = record
foodtype, chef: string
venue: Venues;
end;
function FoodType(prompt: String): Venues;
var
selection: Integer;
begin
WriteLn('Venues:');
WriteLn(' 1. Cafe');
WriteLn(' 2. Restaurant');
WriteLn(' 3. Bakery');
WriteLn(' 4. Milkbar');
WriteLn(' 5. FastFood');
selection := ReadIntegerRange('Select a venue (1 - 5): ', 1, 5);
result := Venues(selection - 1);
end;
procedure WriteFoodMenu(MFood: MFood);
begin
WriteLn(mfood.foodtype, ' - ', mfood.chef, ' - ', mfood.venue);
end;
您必须在
场馆
上选择:
procedure WriteFoodMenu(Venue: Venues; MFood: MFood);
begin
if MFood.venue = Venue then
WriteLn(mfood.foodtype, ' - ', mfood.chef, ' - ', mfood.venue);
end;
只有当您将所需的地点传递给程序时,这才有效。现在您可以拥有一份MFoods列表:
const
Foods: array[0..numOfFoods - 1] of MFood =
(
(FoodType: 'Spaghetti'; Chef: 'Luigi'; Venue: resteraunt),
( etc...),
// etc...
( etc...)
);
...
Venue := FoodType('Select a venue');
for I := Low(Foods) to High(Foods) do
WriteFoodMenu(Venue, Foods[I]);
请注意,在显示菜单之前显示传递给FoodType
的提示是有意义的。您当前根本没有使用提示。FWIW,单词是restaurant,而不是resteraint。