Skip to content

Commit

Permalink
Add Pascal.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhujer committed Sep 13, 2021
1 parent ddeff1a commit a1f72b8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The ExpenseReport example currently exists in the following languages:
- [Java](expensereport-java/)
- [JavaScript](expensereport-javascript/)
- [Kotlin](expensereport-kotlin/)
- [Pascal](expensereport-pascal/)
- [PHP](expensereport-php/)
- [Python](expensereport-python/)
- [Rust](expensereport-rust/)
Expand Down
2 changes: 2 additions & 0 deletions expensereport-pascal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
ExpenseReport
40 changes: 40 additions & 0 deletions expensereport-pascal/ExpenseReport.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
PROGRAM ExpenseReport;

USES sysutils;

TYPE
ExpenseType = (Dinner, Breakfast, CarRental);
Expense = RECORD
type_: ExpenseType;
amount: integer;
END;

PROCEDURE printReport(expenses: ARRAY OF Expense);
VAR total: integer = 0;
VAR mealExpenses: integer = 0;
VAR exp: Expense;
VAR expenseName: string;
VAR mealOverExpensesMarker: string;
BEGIN
writeln('Expenses: ', FormatDateTime('YYYY-MM-DD hh:mm:ss', Now));
FOR exp IN expenses DO
BEGIN
IF (exp.type_ = Dinner) OR (exp.type_ = Breakfast) THEN mealExpenses := mealExpenses + exp.amount;
CASE (exp.type_) of
Dinner: expenseName := 'Dinner';
Breakfast: expenseName := 'Breakfast';
CarRental: expenseName := 'Car Rental';
END;
IF (exp.type_ = Dinner) AND (exp.amount > 5000) OR (exp.type_ = Breakfast) AND (exp.amount > 1000) THEN mealOverExpensesMarker := 'X' ELSE mealOverExpensesMarker := ' ';
writeln(expenseName, #9, exp.amount, #9, mealOverExpensesMarker);
total := total + exp.amount;
END;
writeln('Meal expenses: ', mealExpenses);
writeln('Total expenses: ', total);
END;


VAR expenses: ARRAY OF Expense;
BEGIN
writeln('Hello, world!');
END.
10 changes: 10 additions & 0 deletions expensereport-pascal/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: all
all: ExpenseReport
./ExpenseReport

.PHONY: clean
clean::
$(RM) ExpenseReport *.[adios]

%: %.pas
fpc $^

0 comments on commit a1f72b8

Please sign in to comment.