Project Working
Project Working
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
3. Inventory Management
• 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;
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.
• 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::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.
• 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";
}
}
• 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 };
6. Exit
• The program exits cleanly, typically by breaking out of the loop when the user
selects the Exit option.
Technical Summary