OOPS - Mini Project
OOPS - Mini Project
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;
class Order {
public:
int id;
string customerName;
string address;
bool isPriority;
OrderStatus status;
struct OrderCompare {
bool operator()(const Order& a, const Order& b) {
if (a.isPriority != b.isPriority)
return !a.isPriority;
return a.id > b.id;
}
};
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);
}
bool hasPriorityOrders() {
return any_of(orders.begin(), orders.end(), [](const Order& o) {
return o.isPriority && o.status == OrderStatus::Pending;
});
}
void processPriorityOrders() {
if (priorityOrders.empty()) {
cout << "\nNo priority orders to process.\n";
return;
}
cout << "\nProcessing Priority Orders:\n";
while (!priorityOrders.empty()) {
Order top = priorityOrders.top();
priorityOrders.pop();
top.status = OrderStatus::Delivered;
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 (orders.empty()) {
cout << "\nNo normal orders to process.\n";
return;
}
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;
service.addRoute("Sector 21");
service.addRoute("Downtown");
service.addRoute("City Center");
int choice;
do {
showMenu();
cin >> choice;
cin.ignore();
if (choice == 1) {
string name;
cout << "Enter customer name: ";
getline(cin, name);
service.displayRoutes();
cout << "Select address by number: ";
int addrChoice;
U23CS452 – Object Oriented Programming using C++ Laboratory 205 | P a g e
cin >> addrChoice;
cin.ignore();
auto it = routes.begin();
advance(it, addrChoice - 1);
string address = *it;
cout << "Is this a priority order? (1 for yes / 0 for no): ";
int p;
cin >> p;
cin.ignore();
} else if (choice == 2) {
service.displayOrders();
} else if (choice == 3) {
service.processPriorityOrders();
} else if (choice == 4) {
service.processNormalOrders();
} else if (choice == 5) {
service.displayRoutes();
} else if (choice == 6) {
cout << "Exiting...\n";
} else {
cout << "Invalid choice! Please try again.\n";
}
return 0;
}
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]
All Orders:
Order ID: 100, Name: sirius, Address: Downtown, Status: Pending
All Orders:
No orders available.
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.