Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

DSA THEORY ASSIGMENT #1

NAME: MUHAMMAD BILAL


SECTION: BSCS
REGISTRATION: 2112381
SUBMITTED TO: SIR MUZZAMIL MUNEEB
Q no 1:
Implement a system that should handle the
processing of orders in a Grocery store. User can
place order in the store. The system should
generate the bill for the requests. The system
should work on the given rule: The most recent
order should be processed first. Bill should
contain Customer Name, Address, No. of items in
the order and Total amount to be paid.
There is limit for the no. of orders is 100 so the
system should fulfill the needs of the store.
Implement the system using your profound
knowledge.
Solution:
#include <iostream>
#include <string>
#include <queue>

// Class to represent an Order


class Order {
public:
Order(const std::string& customerName, const
std::string& address, int numItems, double
totalAmount)
: customerName(customerName),
address(address), numItems(numItems),
totalAmount(totalAmount) {}

void printOrderDetails() const {


std::cout << "Customer Name: " <<
customerName << "\n";
std::cout << "Address: " << address << "\n";
std::cout << "Number of items: " << numItems
<< "\n";
std::cout << "Total amount to be paid: $" <<
totalAmount << "\n";
}

private:
std::string customerName;
std::string address;
int numItems;
double totalAmount;
};

// Class to handle Grocery store order processing


class GroceryStore {
public:
GroceryStore() : orderQueue(), orderLimit(100)
{}
void placeOrder(const Order& order) {
if (orderQueue.size() >= orderLimit) {
std::cout << "Order limit reached. Cannot
accept more orders.\n";
return;
}

orderQueue.push(order);
std::cout << "Order placed successfully.\n";
}

void processOrders() {
while (!orderQueue.empty()) {
Order currentOrder = orderQueue.front();
orderQueue.pop();

std::cout << "Processing order:\n";


currentOrder.printOrderDetails();
std::cout << "\n";
}
}

private:
std::queue<Order> orderQueue;
const int orderLimit;
};

int main() {
GroceryStore groceryStore;

// Sample orders for testing


Order order1("John Smith", "123 Main St", 5,
35.50);
Order order2("Jane Doe", "456 Elm St", 3,
20.25);
Order order3("Robert Johnson", "789 Oak St", 2,
15.00);

// Placing orders in the store


groceryStore.placeOrder(order1);
groceryStore.placeOrder(order2);
groceryStore.placeOrder(order3);

// Processing orders
groceryStore.processOrders();

return 0;
}

You might also like