Inventory system Develop an Product base class to keep track of the products. o
ID: 3708670 • Letter: I
Question
Inventory system Develop an Product base class to keep track of the products. o You need to keep track of the following information in the class Item number . Name Cost .Qty o Your class needs to have methods that perform the following actions .A default constructor A constructor to initialize the item when you read them in from the file A destructor Get the Item Number Get the Name Get the Cost Get the Qty Set the Qty Set the Cost Develop an Inventory class that is derived from the Product class o Your Inventory class should create a dynamic array of objects (products) You will read in from the text file all the products and store them in the array. o Your Inventory class should have the following functionality Be able to add new products Update product information Qty and Cost. Delete products When you program starts you will ask if you are a customer or admin. If they select Admin then you allow them to use the Admin interface. If they select customer they must use theExplanation / Answer
//product base class
class Product{
//access specifier
public:
//variables
int ItemNumber;
string Name;
int cost;
int qty;
//constructor
Product(int num, string nam, int cos, int qt){
ItemNumber = num;
Name = nam;
cost = cos;
qty = qt;
}
//deconstructor
-Product(){
ItemNumber = null;
Name = null;
cost = null;
qty = null;
}
//getter methods
int getItemNumber(){
return ItemNumber;
}
string getName(){
return Name;
}
int getCost(){
return cost;
}
int getQty(){
return qty;
}
//setterbmethods
void setQty(int qt){
qty = qt;
}
void setCost(int cos){
cost = cos;
}
};
//inventory class
clas Inventory{
//public specifier
public:
//variables
Product *products;
//methods
//ading new products
void addProduct(Product prod){
if(products == null) {
products = new Product[1];
products[0] = prod
}
else{
int size = sizeof(products);
Product *prods = new Product[size+1];
for(int i=0; i<size;i++){
prods[i] = products[i];
}
prods[size] = prod;
products = prods;
}
}
//updating existing products
void updateProds(int num, int qt, int cos){
for(int i =0;i<sizeof(products);i++){
if(products[i].ItemNumber == num){
products[i].setCost(cos);
products[i].setQty(qt);
}
}
}
//deleting a product
void deleteProduct(int num){
Product *prods = new Product[sizeof(products)-1];
int check =0;
for(int i=0;i<sizeof(products);i++){
if(products[i].getItemNumber() == num){
check =1;
}
else{
prods[i-check] = products[i];
}
}
products = prods;
}
}
int main(){
//asking user input
cout << "Continue as Admin(A) or Shopper(C) ? ";
char in;
cin >> in;
while(true){
if(in == 'A'){
cout << "Choose an Admin option 1. Add a product 2. Update a product 3.Delete a product 4. Exit"
}
if(in == 'C'){
cout << "Choose an Shopper option 1. Add a product to cart 2. Change qty of product in cart 3. remove product from cart 4. Exit"
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.