0% found this document useful (0 votes)
12 views8 pages

OOPS - Mini Project

The document outlines the development of a grocery delivery management system that handles both priority and normal orders. It includes an algorithm for managing orders, delivery routes, and processing based on order priority, along with a C++ program implementation. The program features a menu-driven interface for adding orders, displaying them, and processing deliveries successfully.

Uploaded by

ithachiuchiya20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

OOPS - Mini Project

The document outlines the development of a grocery delivery management system that handles both priority and normal orders. It includes an algorithm for managing orders, delivery routes, and processing based on order priority, along with a C++ program implementation. The program features a menu-driven interface for adding orders, displaying them, and processing deliveries successfully.

Uploaded by

ithachiuchiya20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

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 (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);
}

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 (order.isPriority) {
priorityOrders.push(order);
}
cout << "Order added successfully with ID: " << order.id << endl;
}

void displayOrders() const {


cout << "\nAll Orders:\n";
if (orders.empty()) {
cout << "No orders available.\n";
return;
}
for (const auto& o : orders)
o.display();
}

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;

cout << "Delivered Priority -> ";


top.display();

auto it = remove_if(orders.begin(), orders.end(), [&](const Order& o) {


return o.id == top.id;
});
orders.erase(it, orders.end());
}
}

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;
}

cout << "\nProcessing Normal Orders:\n";


auto it = orders.begin();
while (it != orders.end()) {
if (!it->isPriority) {
it->status = OrderStatus::Delivered;
cout << "Delivered -> ";
it->display();
it = orders.erase(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;

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();

const auto& routes = service.getDeliveryRoutes();

if (addrChoice < 1 || addrChoice > (int)routes.size()) {


cout << "Invalid address choice.\n";
continue;
}

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();

bool priority = (p == 1);

int orderId = service.generateOrderId(priority);


Order newOrder(orderId, name, address, priority);
service.addOrder(newOrder);

} 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";
}

} 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

You might also like