From a1f72b81cabe098d0fda4e47684ac900964b5a73 Mon Sep 17 00:00:00 2001 From: Christian Hujer Date: Mon, 13 Sep 2021 17:00:52 +0530 Subject: [PATCH] Add Pascal. --- README.md | 1 + expensereport-pascal/.gitignore | 2 ++ expensereport-pascal/ExpenseReport.pas | 40 ++++++++++++++++++++++++++ expensereport-pascal/Makefile | 10 +++++++ 4 files changed, 53 insertions(+) create mode 100644 expensereport-pascal/.gitignore create mode 100644 expensereport-pascal/ExpenseReport.pas create mode 100644 expensereport-pascal/Makefile diff --git a/README.md b/README.md index 53b955e0..7a8a046e 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/expensereport-pascal/.gitignore b/expensereport-pascal/.gitignore new file mode 100644 index 00000000..3c7b72eb --- /dev/null +++ b/expensereport-pascal/.gitignore @@ -0,0 +1,2 @@ +*.o +ExpenseReport diff --git a/expensereport-pascal/ExpenseReport.pas b/expensereport-pascal/ExpenseReport.pas new file mode 100644 index 00000000..05009120 --- /dev/null +++ b/expensereport-pascal/ExpenseReport.pas @@ -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. diff --git a/expensereport-pascal/Makefile b/expensereport-pascal/Makefile new file mode 100644 index 00000000..e2b5d3f9 --- /dev/null +++ b/expensereport-pascal/Makefile @@ -0,0 +1,10 @@ +.PHONY: all +all: ExpenseReport + ./ExpenseReport + +.PHONY: clean +clean:: + $(RM) ExpenseReport *.[adios] + +%: %.pas + fpc $^