0% found this document useful (0 votes)
19 views7 pages

DSA Summer Theory Assigment 1

The document describes a C++ program that implements an order processing system for a grocery store. The system allows users to place orders, stores up to 100 orders in a queue, and processes the most recent orders first by printing out billing details. The program defines an Order class to represent customer orders, a GroceryStore class to handle order processing using a queue, and main() to test the system by placing 3 sample orders and processing them.

Uploaded by

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

DSA Summer Theory Assigment 1

The document describes a C++ program that implements an order processing system for a grocery store. The system allows users to place orders, stores up to 100 orders in a queue, and processes the most recent orders first by printing out billing details. The program defines an Order class to represent customer orders, a GroceryStore class to handle order processing using a queue, and main() to test the system by placing 3 sample orders and processing them.

Uploaded by

Sarwar Bh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy