-
Notifications
You must be signed in to change notification settings - Fork 0
/
Restaurant Bill Management.cpp
140 lines (117 loc) · 3.54 KB
/
Restaurant Bill Management.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include<bits/stdc++.h>
using namespace std;
class Restaurant
{
public:
int food_item_codes[12];
string food_item_names[12];
int food_item_prices[12];
protected:
int total_tax;
public:
Restaurant()
{
total_tax = 0;
}
string getName(int code)
{
for(int i=0; i<12; i++)
{
if(this->food_item_codes[i] == code)
return this->food_item_names[i];
}
}
int getPrice(int code)
{
for(int i=0; i<12; i++)
{
if(this->food_item_codes[i] == code)
return this->food_item_prices[i];
}
}
void setTax(double tax)
{
this->total_tax += tax;
}
bool checkCode(int code)
{
for(int i=0; i<12; i++)
{
if(this->food_item_codes[i] == code)
return true;
}
return false;
}
};
int main()
{
Restaurant *restaurant = new Restaurant();
int n;
cin >> n;
for(int i=0; i<n; i++)
{
cin >> restaurant->food_item_codes[i];
getchar();
getline(cin, restaurant->food_item_names[i]);
cin >> restaurant->food_item_prices[i];
}
while(true)
{
cout << endl;
cout << "\t\t Make Bill" << endl;
cout << "\t\t-----------------" << endl;
cout << endl;
cout << " Item Code\t Item Name\t\t\t Item Price" << endl;
for(int i=0; i<n; i++)
{
cout << " " << restaurant->food_item_codes[i] << "\t\t";
cout << " " << restaurant->food_item_names[i] << "\t\t";
cout << " " << restaurant->food_item_prices[i] << endl;
}
cout << endl << endl;
int tableNumber, items;
cout << " Enter Table No: ";
cin >> tableNumber;
cout << " Number of Items: ";
cin >> items;
int code[items], quantity[items];
for(int i=1; i<=items; i++)
{
cout << " Enter Item " << i << " Code: ";
Again:
cin >> code[i];
if(!restaurant->checkCode(code[i]))
{
cout << " Invalid Code! Enter again...\n ";
goto Again;
}
cout << " Enter Item " << i << " Quantity: ";
cin >> quantity[i];
}
cout << endl << endl;
cout << "\t\t\t\t\t\t Bill SUMMARY" << endl;
cout << "\t\t\t\t\t\t--------------------" << endl;
double total = 0;
cout << " Table No.: " << tableNumber << endl;
cout << " Item Code\t Item Name\t\t\t Item Price\t\t Item Quantity\t\t Total Price" << endl;
for(int i=1; i<=items; i++)
{
cout << " " << code[i] << "\t\t";
cout << " " << restaurant->getName(code[i]) << "\t\t";
cout << " " << restaurant->getPrice(code[i]) << "\t\t\t";
cout << " " << quantity[i] << "\t\t\t";
cout << " " << restaurant->getPrice(code[i])*quantity[i] << endl;
total += restaurant->getPrice(code[i])*quantity[i];
}
/// Calculate tax
double tax = total*(5.0/100.0);
cout << " TAX\t\t\t\t\t\t\t\t\t\t\t\t " << tax << endl;
cout << "---------------------------------------------------------------------------------------------------------------" << endl;
total += tax;
cout << " Net Total\t\t\t\t\t\t\t\t\t\t\t = " << total << " Taka" << endl;
cout << endl << endl;
/// Add tax to total_tax
restaurant->setTax(tax);
}
return 0;
}