Message
Message
#include <vector>
#include <string>
class Product {
public:
string name;
double price;
int quantity;
class Cart {
public:
vector<Product> items;
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}});
}
int productChoice;
cout << "Select a product to add to cart (enter number): ";
cin >> productChoice;
void checkout() {
char paymentMethod;
cart.displayReceipt();
cout << "\nChoose payment method (C for Credit Card / K for Cash): ";
cin >> paymentMethod;
int main() {
ShoppingCartApp app;
app.run();
return 0;
}