Ex.
No: 10 MINI PROJECT
Date: Grocery Delivery Management
AIM:
To develop a grocery delivery management system that handles orders with priority and normal
delivery options. The system allows adding orders, managing delivery routes, and processing orders
based on their priority status.
ALGORITHM:
1. Initialize delivery routes and order containers (vector for orders, priority queue for priority
orders).
2. Display menu and get user choice repeatedly until exit.
3. Add new order:
o Get customer name.
o Show delivery routes and get selected address.
o Ask if the order is priority or normal.
o Generate order ID based on priority status and add the order to system.
4. Process orders:
o If priority orders exist, process and deliver them first.
o Otherwise, process and deliver normal orders.
5. Display orders and routes as per user’s choice until user exits.
PROGRAM:
#include <bits/stdc++.h>
using namespace std;
enum class OrderStatus { Pending, Dispatched, Delivered };
class Order {
public:
int id;
string customerName;
string address;
bool isPriority;
OrderStatus status;
Order(int i, string name, string addr, bool priority)
: id(i), customerName(name), address(addr), isPriority(priority), status(OrderStatus::Pending) {}
void display() const {
cout << "Order ID: " << id
<< ", Name: " << customerName
U23CS452 – Object Oriented Programming using C++ Laboratory 202 | P a g e
<< ", Address: " << address
<< ", Status: " << getStatusString()
<< (isPriority ? " [Priority]" : "") << endl;
}
string getStatusString() const {
switch (status) {
case OrderStatus::Pending: return "Pending";
case OrderStatus::Dispatched: return "Dispatched";
case OrderStatus::Delivered: return "Delivered";
default: return "Unknown";
}
}
};
struct OrderCompare {
bool operator()(const Order& a, const Order& b) {
if ([Link] != [Link])
return ![Link];
return [Link] > [Link];
}
};
class GroceryDeliveryService {
private:
vector<Order> orders;
list<string> deliveryRoutes;
priority_queue<Order, vector<Order>, OrderCompare> priorityOrders;
int nextNormalOrderId = 100;
int nextPriorityOrderId = 1000;
public:
void addRoute(const string& location) {
deliveryRoutes.push_back(location);
}
void displayRoutes() const {
cout << "\nAvailable Delivery Routes:\n";
int idx = 1;
for (const auto& loc : deliveryRoutes) {
cout << idx++ << ". " << loc << endl;
}
}
const list<string>& getDeliveryRoutes() const {
return deliveryRoutes;
}
int generateOrderId(bool isPriority) {
if (isPriority) {
return nextPriorityOrderId++;
} else {
return nextNormalOrderId++;
U23CS452 – Object Oriented Programming using C++ Laboratory 203 | P a g e
}
}
void addOrder(const Order& order) {
orders.push_back(order);
if ([Link]) {
[Link](order);
}
cout << "Order added successfully with ID: " << [Link] << endl;
}
void displayOrders() const {
cout << "\nAll Orders:\n";
if ([Link]()) {
cout << "No orders available.\n";
return;
}
for (const auto& o : orders)
[Link]();
}
bool hasPriorityOrders() {
return any_of([Link](), [Link](), [](const Order& o) {
return [Link] && [Link] == OrderStatus::Pending;
});
}
void processPriorityOrders() {
if ([Link]()) {
cout << "\nNo priority orders to process.\n";
return;
}
cout << "\nProcessing Priority Orders:\n";
while (![Link]()) {
Order top = [Link]();
[Link]();
[Link] = OrderStatus::Delivered;
cout << "Delivered Priority -> ";
[Link]();
auto it = remove_if([Link](), [Link](), [&](const Order& o) {
return [Link] == [Link];
});
[Link](it, [Link]());
}
}
void processNormalOrders() {
if (hasPriorityOrders()) {
cout << "\nPriority orders are pending. Please process them first.\n";
return;
}
U23CS452 – Object Oriented Programming using C++ Laboratory 204 | P a g e
if ([Link]()) {
cout << "\nNo normal orders to process.\n";
return;
}
cout << "\nProcessing Normal Orders:\n";
auto it = [Link]();
while (it != [Link]()) {
if (!it->isPriority) {
it->status = OrderStatus::Delivered;
cout << "Delivered -> ";
it->display();
it = [Link](it);
} else {
++it;
}
}
}
};
void showMenu() {
cout << "\n===== Grocery Delivery Service Menu =====\n";
cout << "1. Add New Order\n";
cout << "2. Display All Orders\n";
cout << "3. Process Priority Orders\n";
cout << "4. Process Normal Orders\n";
cout << "5. Show Delivery Routes\n";
cout << "6. Exit\n";
cout << "Select an option: ";
}
int main() {
GroceryDeliveryService service;
[Link]("Sector 21");
[Link]("Downtown");
[Link]("City Center");
int choice;
do {
showMenu();
cin >> choice;
[Link]();
if (choice == 1) {
string name;
cout << "Enter customer name: ";
getline(cin, name);
[Link]();
cout << "Select address by number: ";
int addrChoice;
U23CS452 – Object Oriented Programming using C++ Laboratory 205 | P a g e
cin >> addrChoice;
[Link]();
const auto& routes = [Link]();
if (addrChoice < 1 || addrChoice > (int)[Link]()) {
cout << "Invalid address choice.\n";
continue;
}
auto it = [Link]();
advance(it, addrChoice - 1);
string address = *it;
cout << "Is this a priority order? (1 for yes / 0 for no): ";
int p;
cin >> p;
[Link]();
bool priority = (p == 1);
int orderId = [Link](priority);
Order newOrder(orderId, name, address, priority);
[Link](newOrder);
} else if (choice == 2) {
[Link]();
} else if (choice == 3) {
[Link]();
} else if (choice == 4) {
[Link]();
} else if (choice == 5) {
[Link]();
} else if (choice == 6) {
cout << "Exiting...\n";
} else {
cout << "Invalid choice! Please try again.\n";
}
} while (choice != 6);
return 0;
}
U23CS452 – Object Oriented Programming using C++ Laboratory 206 | P a g e
OUTPUT:
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 1
Enter customer name: black
Available Delivery Routes:
1. Sector 21
2. Downtown
3. City Center
Select address by number: 1
Is this a priority order? (1 for yes / 0 for no): 1
Order added successfully with ID: 1000
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 1
Enter customer name: sirius
Available Delivery Routes:
1. Sector 21
2. Downtown
3. City Center
Select address by number: 2
Is this a priority order? (1 for yes / 0 for no): 0
Order added successfully with ID: 100
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 1
Enter customer name: naruto
Available Delivery Routes:
1. Sector 21
2. Downtown
3. City Center
Select address by number: 3
U23CS452 – Object Oriented Programming using C++ Laboratory 207 | P a g e
Is this a priority order? (1 for yes / 0 for no): 1
Order added successfully with ID: 1001
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 2
All Orders:
Order ID: 1000, Name: black, Address: Sector 21, Status: Pending [Priority]
Order ID: 100, Name: sirius, Address: Downtown, Status: Pending
Order ID: 1001, Name: naruto, Address: City Center, Status: Pending [Priority]
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 4
Priority orders are pending. Please process them first.
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 3
Processing Priority Orders:
Delivered Priority -> Order ID: 1000, Name: black, Address: Sector 21, Status: Delivered [Priority]
Delivered Priority -> Order ID: 1001, Name: naruto, Address: City Center, Status: Delivered [Priority]
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 2
All Orders:
Order ID: 100, Name: sirius, Address: Downtown, Status: Pending
U23CS452 – Object Oriented Programming using C++ Laboratory 208 | P a g e
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 4
Processing Normal Orders:
Delivered -> Order ID: 100, Name: sirius, Address: Downtown, Status: Delivered
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 2
All Orders:
No orders available.
===== Grocery Delivery Service Menu =====
1. Add New Order
2. Display All Orders
3. Process Priority Orders
4. Process Normal Orders
5. Show Delivery Routes
6. Exit
Select an option: 6
Exiting…
RESULT:
The grocery delivery service program has been successfully implemented and runs without
errors. It allows users to add orders, manage delivery routes, and process priority and normal
deliveries through a menu-driven interface.
U23CS452 – Object Oriented Programming using C++ Laboratory 209 | P a g e