#include
#include
using namespace std;
// Step 1: Enum definition
enum StoreType { Clothing, Electronics, Grocery, FoodCourt };
// Step 2: Struct definition
struct Owner {
string name;
string contact;
int yearsOfExperience;
};
// Step 3: Class definition
class Store {
private:
int storeID;
string storeName;
Owner storeOwner;
StoreType type;
public:
// Default Constructor
Store() {
storeID = 0;
storeName = "Unknown";
storeOwner = {"Unknown", "N/A", 0};
type = Clothing;
cout << "Default Constructor Called" << endl;
}
// Parameterized Constructor
Store(int id, string name, Owner owner, StoreType t) {
storeID = id;
storeName = name;
storeOwner = owner;
type = t;
cout << "Parameterized Constructor Called" << endl;
}
// Copy Constructor
Store(const Store &other) {
storeID = other.storeID;
storeName = other.storeName;
storeOwner = other.storeOwner;
type = other.type;
cout << "Copy Constructor Called" << endl;
}
// Destructor
~Store() {
cout << "Destructor Called" << endl;
}
// Getters
int getStoreID() { return storeID; }
string getStoreName() { return storeName; }
Owner getStoreOwner() { return storeOwner; }
StoreType getStoreType() { return type; }
// Setters
void setStoreID(int id) { storeID = id; }
void setStoreName(string name) { storeName = name; }
void setStoreOwner(Owner owner) { storeOwner = owner; }
void setStoreType(StoreType t) { type = t; }
// Method to display store details
void displayDetails() {
cout << "Store ID: " << storeID << endl;
cout << "Store Name: " << storeName << endl;
cout << "Owner Name: " << storeOwner.name << endl;
cout << "Contact: " << storeOwner.contact << endl;
cout << "Years of Experience: " << storeOwner.yearsOfExperience << endl;
cout << "Store Type: ";
switch (type) {
case Clothing: cout << "Clothing"; break;
case Electronics: cout << "Electronics"; break;
case Grocery: cout << "Grocery"; break;
case FoodCourt: cout << "FoodCourt"; break;
}
cout << endl;
}
};
// Step 5: Main function
int main() {
Owner owner1 = {"Alice", "1234567890", 5};
// Create store using parameterized constructor
Store store1(101, "TechZone", owner1, Electronics);
// Create store using copy constructor
Store store2(store1);
// Display details of both stores
cout << "\nDetails of Store 1:\n";
store1.displayDetails();
cout << "\nDetails of Store 2:\n";
store2.displayDetails();
return 0;
}
- Get link
- X
- Other Apps
Comments
Post a Comment