0% found this document useful (0 votes)
2 views

Project Working

The document outlines a shopping cart and product management program with a main menu offering options for cart management, inventory management, bill checking, STL demonstration, and exit. It details functionalities such as adding/removing products from the cart and inventory, calculating discounts, and using STL containers for data management. The program is designed using object-oriented principles, encapsulating data within classes and ensuring modular design for maintainability.

Uploaded by

shaheerkz12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Project Working

The document outlines a shopping cart and product management program with a main menu offering options for cart management, inventory management, bill checking, STL demonstration, and exit. It details functionalities such as adding/removing products from the cart and inventory, calculating discounts, and using STL containers for data management. The program is designed using object-oriented principles, encapsulating data within classes and ensuring modular design for maintainability.

Uploaded by

shaheerkz12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Shopping Cart and Product Management

Output:
1. Main Menu

• The program starts with a main menu that offers five options:
1. Cart Management
2. Inventory Management
3. Check Discount and Bill
4. Demonstration of STL (Standard Template Library)
5. Exit
• The user selects an option by entering the corresponding number.

2. Cart Management

• Adding a Product to the Cart:


o When the user selects Cart Management and then Add Product, the
program prompts for:
▪ Product name
▪ Price
▪ Available stock
▪ Quantity to add to the cart
o The stock is updated based on the quantity added to the cart. If the stock
allows, the product is successfully added.
o If the user attempts to add a product that is already in the cart, the program
only prompts for the quantity (stock is checked to avoid adding more than
available).
o Example:
▪ Adding 23 Bread (Stock becomes 7)
▪ Adding 3 more Bread (Stock becomes 4)
• Removing a Product from the Cart:
o The user can also remove products from the cart by selecting the Remove
Product option.
o The program prompts for the product name and removes it from the cart if it
exists.
o After removing, the program returns to the Cart Management menu.
• Displaying the Cart:
o This option shows the total price of items in the cart.
o In your case, after removing Bread, the cart was empty, hence the total was
$0.
• Checking the Bill:
o This option returns the program Back to Main

3. Inventory Management

• Adding an Item to the Inventory:


o The user can add items to the inventory by entering the item name, price,
and stock quantity.
o Example:
▪ Added an Apple with a price of 30 and a stock of 200.
• Removing an Item from the Inventory:
o The user can remove items from the inventory by specifying the item name.
o Example:
▪ Removed Apple from the inventory.
• Displaying Inventory:
o This option displays all items currently in inventory.
o After adding and then removing Apple, the inventory became empty.

4. Checking Discount and Bill

• The program calculates the total amount of items in all carts and applies discounts.
o A 10% discount is applied first.
o A fixed discount of $5 is applied afterward.
o Since the cart was empty, the total after discounts resulted in $0 and -$5
respectively.

5. Demonstration of STL

• This section demonstrates the use of STL (Standard Template Library) containers
like vectors.
o In your example, quantities and prices are shown.
o Quantities: 6, 11, 16, 21
o Prices: 0.59, 0.89, 0.99, 1.99
• This indicates that STL vectors were used to store and manipulate these values.

6. Exit

• Finally, the program terminates when the user selects the Exit option from the
main menu.
Technical Working
1. Main Menu and Program Flow

• Structure: The main menu is likely implemented using a loop, possibly a do-while
or while loop, which keeps displaying the menu until the user chooses to exit.
• Switch Case: A switch statement is used to handle user input, where each case
corresponds to one of the menu options (Cart Management, Inventory
Management, Check Discount and Bill, etc.).

int choice;
do {
// Display main menu
cout << "1. Cart Management\n2. Inventory Management\n3. Check
Discount and Bill\n4. Demonstration of STL\n5. Exit\n";
cout << "Enter choice: ";
cin >> choice;

switch (choice) {
case 1: // Cart Management
manageCart();
break;
case 2: // Inventory Management
manageInventory();
break;
case 3: // Check Discount and Bill
checkBill();
break;
case 4: // Demonstration of STL
demonstrateSTL();
break;
case 5: // Exit
cout << "Exiting...\n";
break;
default:
cout << "Invalid choice, please try again.\n";
}
} while (choice != 5);

2. Cart Management

• Class Design:
o A Product class encapsulates product details like name, price, and stock.
o A Cart class manages a collection of Product objects, likely using an STL
container like vector.

class Product {
public:
string name;
double price;
int stock;
int quantity;

Product(string n, double p, int s, int q) : name(n), price(p),


stock(s), quantity(q) {}
};

class Cart {
private:
vector<Product> products;
public:
void addProduct(const Product& product);
void removeProduct(const string& productName);
void displayCart();
double calculateTotal();
};

• Adding a Product:
o When adding a product, the program checks if the product is already in the
cart. If it is, it updates the quantity. Otherwise, it adds a new Product object
to the products vector.
o Stock management is handled by decrementing the available stock each
time a product is added to the cart.

void Cart::addProduct(const Product& product) {


for (auto& p : products) {
if (p.name == product.name) {
p.quantity += product.quantity;
p.stock -= product.quantity;
return;
}
}
products.push_back(product);
}

• Removing a Product:
o Removing a product involves searching the products vector by product
name and then erasing the corresponding element if found.

void Cart::removeProduct(const string& productName) {


auto it = find_if(products.begin(), products.end(), [&](const
Product& p) {
return p.name == productName;
});
if (it != products.end()) {
products.erase(it);
}
}

• Displaying the Cart:


o The cart's total price is calculated by iterating over the products vector and
summing the prices of all items.

void Cart::displayCart() {
double total = 0;
for (const auto& p : products) {
total += p.price * p.quantity;
}
cout << "Total Cart Price: $" << total << "\n";
}

3. Inventory Management

• Inventory Class:
o Like the Cart class, an Inventory class manages a list of products
available in the store. This is again implemented using an STL vector to
store Product objects.

class Inventory {
private:
vector<Product> items;
public:
void addItem(const Product& item);
void removeItem(const string& itemName);
void displayInventory();
};

• Adding/Removing Items:
o The addItem function appends a new product to the items vector, while
removeItem finds and removes a product based on the name.

void Inventory::addItem(const Product& item) {


items.push_back(item);
}

void Inventory::removeItem(const string& itemName) {


auto it = find_if(items.begin(), items.end(), [&](const Product&
p) {
return p.name == itemName;
});
if (it != items.end()) {
items.erase(it);
}
}

• Displaying Inventory:
o This function iterates over the items vector and displays the details of each
product.

void Inventory::displayInventory() {
for (const auto& item : items) {
cout << "Item: " << item.name << ", Type: class Product\n";
}
}

4. Discount and Billing

• Discount Calculation:
o The discount is applied in two steps: first a percentage discount, and then a
fixed discount. The calculateTotal function in the Cart class likely
handles this logic.

double Cart::calculateTotal() {
double total = 0;
for (const auto& p : products) {
total += p.price * p.quantity;
}
double discountedTotal = total * 0.9; // 10% discount
discountedTotal -= 5; // Fixed $5 discount
return discountedTotal;
}

5. STL Demonstration

• Use of Vectors:
o The demonstration likely uses vector to showcase how quantities and
prices can be stored and manipulated. This could involve sorting, modifying,
or simply displaying elements.

void demonstrateSTL() {
vector<int> quantities = { 6, 11, 16, 21 };
vector<double> prices = { 0.59, 0.89, 0.99, 1.99 };

for (auto q : quantities) {


cout << "Modified quantities: " << q << " ";
}
cout << "\n";
for (auto p : prices) {
cout << "Prices: " << p << " ";
}
cout << "\n";
}

6. Exit

• The program exits cleanly, typically by breaking out of the loop when the user
selects the Exit option.

Technical Summary

• Object-Oriented Programming (OOP): The use of classes (Product, Cart,


Inventory) encapsulates the data and functionality related to products, shopping
carts, and inventory management.
• Encapsulation: The data members of classes are private, ensuring that they can
only be accessed and modified through public member functions.
• STL Usage: The program leverages STL containers like vector to manage dynamic
collections of products and related data. This demonstrates the efficiency and
convenience of STL in handling such data structures.
• Modular Design: Each menu option and functionality is modular, likely
implemented in separate functions or class methods, making the code organized
and easier to maintain.

You might also like