-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
142 lines (128 loc) · 4.59 KB
/
Copy pathmain.cpp
File metadata and controls
142 lines (128 loc) · 4.59 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
#include <iostream>
using namespace std;
// simple menu item
struct Food { int id; string name; string type; int price; };
// order record
struct Order { int id; string customer; int total; string status; };
// menu items
Food menu[13] = {
{1,"Pizza","Main Dish",320},
{2,"ingera","Main Dish",100},
{3,"burger","Main Dish",200},
{4,"Chicken","Main Dish",120},
{5,"egg","Main Dish",90},
{6,"juice","Side",50},
{7,"firfr","Side",60},
{8,"bread","Side",50},
{9,"Salad","Side",80},
{10,"Fanta","Drink",60},
{11,"Orange","Drink",50},
{12,"Chocolate","additional",70},
{13,"Water","Drink",40}
};
Order orders[20]; // store orders here
int orderCount = 0,
nextId = 1001; // starting order id
// show the menu to the user
void showMenu() {
cout << "\n======== MENU ========\n";
for(int i = 0; i < 13; i++)
cout << menu[i].id << ". " << menu[i].name
<< " (" << menu[i].type << ") - " << menu[i].price << " ETB\n";
}
// take a new order from a customer
void takeOrder() {
string name;
cout << "\nCustomer Name: ";
cin.ignore(); // clear leftover newline
getline(cin, name); // read full name (spaces allowed)
Order o; o.id = nextId++; o.customer = name; o.total = 0; o.status = "Pending";
char more = 'y';
while(more == 'y') {
showMenu();
int choice, qty;
cout << "Item (1-13, 0=stop): "; cin >> choice;
if(choice == 0) break;
if(choice < 1 || choice > 13) { cout << "Invalid!\n"; continue; }
cout << "Quantity: "; cin >> qty;
o.total += menu[choice - 1].price * qty;
cout << "Added " << qty << "x " << menu[choice - 1].name << "\n";
cout << "Add more? (y/n): "; cin >> more;
}
if(o.total > 0) {
orders[orderCount] = o; orderCount++;
cout << "\nOrder #" << o.id << " created! Total: " << o.total << " ETB\n";
} else {
cout << "Order cancelled!\n";
nextId--; // rollback id when no items were ordered
}
}
// list all orders
void showOrders() {
if(orderCount == 0) { cout << "\nNo orders!\n"; return; }
cout << "\n===== ORDERS =====\n";
for(int i = 0; i < orderCount; i++)
cout << "#" << orders[i].id << " - " << orders[i].customer
<< " - " << orders[i].total << " ETB - " << orders[i].status << "\n";
}
// update an order's status
void updateStatus() {
if(orderCount == 0) { cout << "\nNo orders!\n"; return; }
showOrders();
int id; cout << "\nOrder ID: "; cin >> id;
for(int i = 0; i < orderCount; i++) {
if(orders[i].id == id) {
cout << "1.Preparing 2.Ready 3.Completed: ";
int c; cin >> c;
if(c == 1) orders[i].status = "Preparing";
else if(c == 2) orders[i].status = "Ready";
else if(c == 3) orders[i].status = "Completed";
else { cout << "Invalid!\n"; return; }
cout << "Status updated!\n";
return;
}
}
cout << "Order not found!\n";
}
// print bill for a ready/completed order
void generateBill() {
if(orderCount == 0) { cout << "\nNo orders!\n"; return; }
showOrders();
int id; cout << "\nOrder ID: "; cin >> id;
for(int i = 0; i < orderCount; i++) {
if(orders[i].id == id) {
if(orders[i].status == "Ready" || orders[i].status == "Completed") {
cout << "\n===== BILL =====\nOrder #" << orders[i].id
<< "\nCustomer: " << orders[i].customer
<< "\nTotal: " << orders[i].total << " ETB"
<< "\nStatus: " << orders[i].status
<< "\n================\nThank you!\n";
} else {
cout << "Order not ready! Status: " << orders[i].status << "\n";
}
return;
}
}
cout << "Order not found!\n";
}
int main() {
while(1) {
cout << "\n===== RESTAURANT SYSTEM =====\n"
<< "1. View Menu\n2. Take Order\n3. View Orders\n"
<< "4. Update Status\n5. Generate Bill\n6. Exit\n"
<< "Choice (1-6): ";
int c; cin >> c;
if(c == 1) showMenu();
else if(c == 2) takeOrder();
else if(c == 3) showOrders();
else if(c == 4) updateStatus();
else if(c == 5) generateBill();
else if(c == 6) { cout << "Goodbye!\n"; break; }
else cout << "Invalid choice!\n";
cout << "\nPress Enter...";
cin.ignore(); // wait for user to press Enter
cin.get();
system("cls||clear"); // clear screen (Windows/Linux)
}
return 0;
}