program Project1;
uses
crt;
type
ordertype = record
item: string;
price: integer;
cat: string[20];
end;
label
return;
var
menufile: Text;
numrec: array [1..100] of integer;
orderrec, foodrec: array [1..100] of ordertype;
i, j, c, y, total, Count, max, maxorder: integer;
sure1, sure2, sure3: char;
procedure Menu;
begin
Assign(menufile, 'menu1.txt');
reset(menufile);
while not EOF do
begin
max := max + 1;
with foodrec[max] do
begin
readln(menufile, item);
readln(menufile, price);
readln(menufile, cat);
end;
end;
Close(menufile);
end;
procedure FoodCategory;
begin
writeln('Please choose the category.');
writeln('[1]: Pizza');
writeln('[2]: Pasta');
writeln('[3]: Salad');
writeln('[4]: Soup');
writeln('[5]: Dessert');
writeln;
end;
procedure DisplayChoice(x: integer);
var
i: integer;
begin
y := 0;
case x of
1:
begin
for i := 1 to 100 do
begin
with foodrec[i] do
if cat = 'pizza' then
begin
y := y + 1;
writeln('[', y, ']: ', item, ' $', price: 1);
numrec[y] := i;
end;
end;
end;
2:
begin
for i := 1 to 100 do
begin
with foodrec[i] do
if cat = 'pasta' then
begin
y := y + 1;
writeln('[', y, ']: ', item, ' $', price: 1);
numrec[y] := i;
end;
end;
end;
3:
begin
for i := 1 to 100 do
begin
with foodrec[i] do
if cat = 'salad' then
begin
y := y + 1;
writeln('[', y, ']: ', item, ' $', price: 1);
numrec[y] := i;
end;
end;
end;
4:
begin
for i := 1 to 100 do
begin
with foodrec[i] do
if cat = 'soup' then
begin
y := y + 1;
writeln('[', y, ']: ', item, ' $', price: 1);
numrec[y] := i;
end;
end;
end;
5:
begin
for i := 1 to 100 do
begin
with foodrec[i] do
if cat = 'dessert' then
begin
y := y + 1;
writeln('[', y, ']: ', item, ' $', price: 1);
numrec[y] := i;
end;
end;
end;
end;
end;
procedure Calculate;
var
cost: integer;
begin
cost := 0;
with foodrec[numrec[Count]] do
cost := price;
total := total + cost;
end;
procedure PlaceOrder;
var
a: integer;
begin
clrscr;
FoodCategory;
repeat
readln(a);
until (a >= 1) and (a <= 5);
clrscr;
DisplayChoice(a);
writeln('Please enter your choice:');
repeat
readln(Count);
until (Count >= 1) and (Count <= y);
maxorder := maxorder + 1;
orderrec[maxorder] := foodrec[numrec[Count]];
Calculate;
clrscr;
end;
procedure Delete;
var
delrec: integer;
begin
for i := 1 to maxorder do
begin
with orderrec[i] do
writeln('[', i, ']: ', item, ' $', price: 1);
end;
writeln('Please enter the order you want to delete(input number):');
repeat
readln(delrec);
until (delrec >= 1) and (delrec <= maxorder);
Write('Are you sure?(Y/N): ');
repeat
readln(sure1);
until sure1 in ['y', 'Y', 'n', 'N'];
if (sure1 = 'y') or (sure1 = 'Y') then
begin
with orderrec[delrec] do
total := total - price;
for j := delrec to maxorder do
orderrec[j] := orderrec[j + 1];
maxorder := maxorder - 1;
end;
writeln('The order has been deleted.');
end;
begin
maxorder := 0;
Menu;
writeln('Welcome to the ordering system.');
writeln('Press enter to place order now.');
readln;
clrscr;
PlaceOrder;
return:
clrscr;
writeln('Please enter your choice.');
writeln('[1]: Add order');
writeln('[2]: Delete order');
writeln('[3]: Display order');
writeln('[4]: Print out bill');
writeln;
repeat
readln(c)
until (c >= 1) and (c <= 4);
case c of
1:
begin
clrscr;
PlaceOrder;
goto return;
end;
2:
begin
clrscr;
Delete;
goto return;
end;
3:
begin
clrscr;
writeln('This is your order:');
for i := 1 to maxorder do
begin
with orderrec[i] do
writeln('[', i, ']: ', item, ' $', price: 1);
end;
writeln('Total : $', total: 1);
writeln('Press enter to continue.');
readln;
goto return;
end;
else
begin
Write('Are you sure?(Y/N): ');
repeat
readln(sure2);
until (sure2 = 'y') or (sure2 = 'Y') or (sure2 = 'n') or (sure2 = 'N');
if (sure2 = 'y') or (sure2 = 'Y') then
begin
if total = 0 then
writeln('You do not have any order.')
else
begin
writeln('The order has been printed out.');
writeln('Press enter to continue.');
readln;
clrscr;
end;
end;
if (sure2 = 'n') or (sure2 = 'N') then
goto return;
writeln('Thank you');
i := 0;
j := 0;
y := 0;
Count := 0;
max := 0;
total := 0;
writeln('Do you have an new order?(Y/N)');
repeat
readln(sure3);
until (sure3 = 'Y') or (sure3 = 'y') or (sure3 = 'N') or (sure3 = 'n');
clrscr;
end;
end;
end.