-
Notifications
You must be signed in to change notification settings - Fork 98
/
expensereport.adb
58 lines (47 loc) · 2.11 KB
/
expensereport.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
with Text_IO, Text_IO.Unbounded_IO, Ada.Command_Line, Ada.Strings.Unbounded, Ada.Strings.Fixed, Ada.Characters.Latin_1;
use Text_IO, Text_IO.Unbounded_IO, Ada.Command_Line, Ada.Strings.Unbounded;
procedure expensereport is
type ExpenseType is (Breakfast, Dinner, CarRental);
type Expense is tagged record
eType: ExpenseType;
amount: Integer;
end record;
type ExpenseList is array(Positive range <>) of Expense;
procedure printReport(expenses: in ExpenseList) is
total : Integer := 0;
mealExpenses : Integer := 0;
expenseName : Unbounded_String;
mealOverExpensesMarker : Character := ' ';
begin
Put_Line("Expenses:");
for i in expenses'Range loop
if (expenses(i).eType = Breakfast or expenses(i).eType = Dinner) then
mealExpenses := mealExpenses + expenses(i).amount;
end if;
expenseName := To_Unbounded_String("Foo" & "Foo");
case expenses(i).eType is
when Breakfast =>
expenseName := To_Unbounded_String("Breakfast");
when Dinner =>
expenseName := To_Unbounded_String("Dinner");
when CarRental =>
expenseName := To_Unbounded_String("Car Rental");
end case;
if ((expenses(i).eType = Breakfast and expenses(i).amount > 1000) or (expenses(i).eType = Dinner and expenses(i).amount > 5000)) then
mealOverExpensesMarker := 'X';
else
mealOverExpensesMarker := ' ';
end if;
Put_Line(expenseName & Ada.Characters.Latin_1.HT & Ada.Strings.Fixed.Trim(Integer'Image(expenses(i).amount), Ada.Strings.Left) & Ada.Characters.Latin_1.HT & mealOverExpensesMarker);
total := total + expenses(i).amount;
end loop;
Put_Line("Meal expenses:" & Integer'Image(mealExpenses));
Put_Line("Total expenses:" & Integer'Image(total));
end printReport;
expenses : ExpenseList := (
(Breakfast, 1),
(Breakfast, 1)
);
begin
printReport(expenses);
end expensereport;