显示特定类型的所有变量
display all variables for a specific type
我想在 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;
您必须 select 在 Venues
:
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
的提示是有意义的。您目前根本没有使用提示。
我想在 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;
您必须 select 在 Venues
:
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
的提示是有意义的。您目前根本没有使用提示。