0% found this document useful (0 votes)
24 views3 pages

Message

Uploaded by

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

Message

Uploaded by

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

#include <iostream>

#include <vector>
#include <string>

using namespace std;

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

Product(string n, double p, int q) : name(n), price(p), quantity(q) {}


};

class Cart {
public:
vector<Product> items;

void addProduct(const Product& product) {


items.push_back(product);
}

void displayReceipt() {
double total = 0.0;
cout << "\n--- Shopping Receipt ---\n";
for (const auto& item : items) {
cout << "Product Name: " << item.name
<< ", Quantity: " << item.quantity
<< ", Price: $" << item.price * item.quantity << endl;
total += item.price * item.quantity;
}
cout << "Total Price: $" << total << endl;
}
};

class ShoppingCartApp {
public:
void run() {
cout << "Welcome to the Shopping Cart Application!\n";
while (true) {
mainMenu();
}
}

private:
Cart cart;

void mainMenu() {
cout << "\nMain Menu:\n";
cout << "1. Clothes\n";
cout << "2. Cosmetics\n";
cout << "3. Footwear\n";
cout << "4. Exit\n";

int choice;
cout << "Select a category (1-4): ";
cin >> choice;
switch (choice) {
case 1: clothesMenu(); break;
case 2: cosmeticsMenu(); break;
case 3: footwearMenu(); break;
case 4: exit(0);
default: cout << "Invalid choice! Please try again.\n";
}
}

void clothesMenu() {
cout << "\nClothes Categories:\n";
cout << "1. Menwear\n";
cout << "2. Womenwear\n";
cout << "3. Kidswear\n";

int choice;
cout << "Select a category (1-3): ";
cin >> choice;

switch (choice) {
case 1: productList({{"T-Shirt", 20.0, 1}, {"Jeans", 40.0, 1}}); break;
// Example products
case 2: productList({{"Dress", 50.0, 1}, {"Skirt", 30.0, 1}});
break; // Example products
case 3: productList({{"T-Shirt", 15.0, 1}, {"Shorts", 25.0, 1}});
break; // Example products
default: cout << "Invalid choice! Please try again.\n"; clothesMenu();
}
}

void cosmeticsMenu() {
// Similar structure for cosmetics
productList({{"Lipstick", 10.0, 1}, {"Foundation", 25.0, 1}});
}

void footwearMenu() {
// Similar structure for footwear
productList({{"Sneakers", 60.0, 1}, {"Sandals", 30.0, 1}});
}

void productList(const vector<Product>& products) {


cout << "\nAvailable Products:\n";

for (size_t i = 0; i < products.size(); ++i) {


const auto& product = products[i];
cout << i + 1 << ". " << product.name
<< ", Price: $" << product.price
<< ", Available Quantity: " << product.quantity
<< endl;
}

int productChoice;
cout << "Select a product to add to cart (enter number): ";
cin >> productChoice;

if (productChoice > 0 && productChoice <= products.size()) {


cart.addProduct(products[productChoice - 1]);
checkout();
} else {
cout << "Invalid choice! Returning to previous menu.\n";
mainMenu();
}
}

void checkout() {
char paymentMethod;

cart.displayReceipt();

cout << "\nChoose payment method (C for Credit Card / K for Cash): ";
cin >> paymentMethod;

if (paymentMethod == 'C' || paymentMethod == 'K') {


cout << "\nPayment Successful!\n";
char continueShopping;
cout << "Do you want to continue shopping? (Y/N): ";
cin >> continueShopping;

if (continueShopping == 'Y' || continueShopping == 'y') {


mainMenu();
} else {
exit(0);
}
} else {
cout << "Invalid payment method! Returning to main menu.\n";
mainMenu();
}
}
};

int main() {
ShoppingCartApp app;
app.run();

return 0;
}

You might also like