/* Rafay Ahmad 23I-2526 */ #include #include using namespace std; class Product{ int id; char* name; float price; int quantity; public: Product() : id(0), price(0), quantity(0){ name = nullptr; } Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){ int length = strlen(name); this->name = new char[length+1]; strcpy(this->name, name); } ~Product(){ delete[] name; } int getId(){ return id; } char* getName(){ return name; } float getPrice(){ return price; } int getQuantity(){ return quantity; } void setId(int id){ this->id = id; } void setName(char* name){ int length = strlen(name); this->name = new char[length+1]; strcpy(this->name, name); } void setPrice(float price){ this->price = price; } void setQuantity(int quantity){ this->quantity = quantity; } }; class Inventory{ Product* products; int count; int size; public: Inventory(int size) : size(size), count(0){ products = new Product[size]; } void addProduct(int id, char* name, float price, int quantity){ if(countcount;i++){ if(products[i].getId() == id){ products[i].setQuantity(products[i].getQuantity()-count); break; } } } void updateQuantity(int id, int quantityChange){ for(int i=0;i>choice; switch(choice){ case 1: cout<<"Enter id: "; cin>>id; cout<<"Enter name: "; cin>>name; cout<<"Enter price: "; cin>>price; cout<<"Enter quantity: "; cin>>quantity; inventory.addProduct(id, name, price, quantity); break; case 2: cout<<"Enter id: "; cin>>id; inventory.removeProduct(id); break; case 3: cout<<"Enter name: "; cin>>name; inventory.removeProduct(name); break; case 4: cout<<"Enter id: "; cin>>id; cout<<"Enter quantity: "; cin>>quantity; inventory.removeProduct(id, quantity); break; case 5: cout<<"Enter id: "; cin>>id; cout<<"Enter quantity change: "; cin>>quantity; inventory.updateQuantity(id, quantity); break; case 6: cout<<"Enter id: "; cin>>id; cout<<"ID: "<