-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBilling System.cpp
More file actions
203 lines (173 loc) · 6.25 KB
/
Copy pathBilling System.cpp
File metadata and controls
203 lines (173 loc) · 6.25 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int MENU_SIZE = 8;
const int MAX_ORDER_SIZE = 15;
struct MenuItem {
int itemNo{};
string itemName;
double price{};
};
// LOAD MENU LIST TO ARRAY
void getData(MenuItem menuList[])
{
menuList[0] = { 111, "Plain Egg ", 1.45 };
menuList[1] = { 112, "Bacon and Egg", 2.45 };
menuList[2] = { 113, "Muffin ", 0.99 };
menuList[3] = { 114, "French Toast ", 1.99 };
menuList[4] = { 115, "Fruit Basket ", 2.49 };
menuList[5] = { 116, "Cereal ", 0.69 };
menuList[6] = { 117, "Coffee ", 0.50 };
menuList[7] = { 118, "Tea ", 0.75 };
}
// DISPLAY MENU FOR CUSTOMER
void showMenu(const MenuItem menuList[])
{
cout.setf(ios::fixed);
cout.precision(2);
cout << "------- Welcome to Meal Hut --------" << endl;
cout << "----- Breakfast Billing System -----\n";
cout << " \n";
cout << "Item No Menu Item Price\n";
for (int i = 0; i < MENU_SIZE; ++i) {
cout << menuList[i].itemNo << " " << menuList[i].itemName << " $" << menuList[i].price << endl;
}
cout << "\nNote: A 5% tax will be added to the full bill.\n";
cout << "\nInstructions: \n";
cout << " * Enter No 2 (Order Items) for start add items to your order.\n";
cout << " * Enter one item number at a time.\n";
cout << " * After adding items please enter No 3 (Calculate Bill) for generate the bill.\n";
cout << " * You can order only 15 items per bill.\n";
}
// ADD ITEMS TO THE ORDER
int orderPlace(const MenuItem menuList[], int orderedItemsCount[])
{
int orderAmount = 0;
const int MAX_ORDER_SIZE = 15;
cout << "Enter item numbers to order, one at a time (type 0 to finish): ";
int input;
while (cin >> input && input != 0) {
if (orderAmount >= MAX_ORDER_SIZE) {
cout << "You have reached the maximum order limit of " << MAX_ORDER_SIZE << " items.\n";
break;
}
bool found = false;
for (int i = 0; i < MENU_SIZE; ++i) {
if (menuList[i].itemNo == input) {
orderedItemsCount[orderAmount++] = i;
found = true;
break;
}
}
if (!found) {
cout << "Invalid item number. Please try again.\n";
}
else if (orderAmount <= MAX_ORDER_SIZE) {
cout << "ITEM ADDED!\n";
cout << "\nEnter next item number or 0 to finish: ";
}
}
if (orderAmount > 0) {
cout << "\nItems successfully added to your order.\n";
}
else {
cout << "\nNo items were added.\n";
}
return orderAmount;
}
// CALCULATE AND PRINT BILL AND SAVE BILLS TO A FILE
void printCheck(const string& filename, const MenuItem menuList[], const int orderedItemsCount[], int orderAmount)
{
static int orderNo = 1;
double subTotal = 0;
double taxRate = 0.05;
// ROUNDING FOR TWO DECIMAL POINTS
cout.setf(ios::fixed);
cout.precision(2);
cout << " ------------ Meal Hut ------------\n";
cout << " ---- No.101 ---- \n";
cout << " -- York -- \n";
cout << " ---- LONDON ---- \n";
cout << " ------------ INVOICE -------------\n";
cout << " Order No: " << orderNo << endl;
cout << endl;
for (int j = 0; j < orderAmount; ++j) {
int itemIndex = orderedItemsCount[j];
cout << menuList[itemIndex].itemNo << " " << menuList[itemIndex].itemName << " $" << menuList[itemIndex].price << endl;
subTotal = subTotal + menuList[itemIndex].price;
}
double tax = subTotal * taxRate;
double total = subTotal + tax;
cout << endl;
cout << "Subtotal: $" << subTotal << endl;
cout << "Tax Amount (5%): $" << tax << endl;
cout << "Amount Due: $" << total << endl;
cout << endl;
cout << "Thank you for visiting Meal Hut.HAVE A NICE DAY!!\n";
ofstream outFile(filename, ios::app);
outFile << "Order No: " << orderNo << endl;
outFile << endl;
for (int j = 0; j < orderAmount; ++j) {
int itemIndex = orderedItemsCount[j];
outFile << menuList[itemIndex].itemNo << " " << menuList[itemIndex].itemName << " $" << menuList[itemIndex].price << endl;
}
outFile.setf(ios::fixed);
outFile.precision(2);
outFile << endl;
outFile << "Subtotal: $" << subTotal << endl;
outFile << "Tax Amount (5%): $" << tax << endl;
outFile << "Amount Due: $" << total << endl;
outFile << endl;
outFile << "-----------------------------------------\n";
outFile << endl;
outFile.close();
orderNo++;
}
int main()
{
string filename = "E:/bill.txt";
MenuItem menuList[MENU_SIZE];
int orderAmount = 0;
int orderedItemsCount[MAX_ORDER_SIZE];
getData(menuList);
// NAVIGATION MENU SYSTEM
int choice;
do {
cout << "\nWelcome to Meal Hut! Enjoy the best breakfast in town.\n";
cout << endl;
cout << "1. Breakfast Menu\n";
cout << "2. Order Items\n";
cout << "3. Calculate Bill\n";
cout << "4. Exit\n";
cout << endl;
cout << "Enter your choice: ";
cin >> choice;
cout << endl;
switch (choice)
{
case 1:
showMenu(menuList);
break;
case 2:
orderAmount = orderPlace(menuList, orderedItemsCount);
break;
case 3:
if (orderAmount > 0) {
printCheck(filename, menuList, orderedItemsCount, orderAmount);
}
else {
cout << "No items ordered yet.\n";
}
break;
case 4:
cout << "Thank you for visiting Meal Hut.HAVE A NICE DAY!!\n";
break;
default:
cout << "Invalid choice. Please try again.\n";
cout << endl;
break;
}
} while (choice != 4);
return 0;
}