Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design and implement the following two C++ classes that manage the inventory of

ID: 3682269 • Letter: D

Question

Design and implement the following two C++ classes that manage the inventory of a small store.

Product: For each product, you should store the following info:

product name (i.e. “Apple iPhone 3GS 8GB”, may contain spaces in it, not unique)

locator (string with no spaces, used to physically locate product, not unique)

quantity (how many of this product in stock, greater than or equal to 0)

price (in dollars and cents, greater than 0)

Note: For a given product, the product name AND locator together must be unique. So you may have two entries for “iPhone 5c” if one has “box3” for the locator and the other has “shelf12” (this is different from PA#2).

You should implement the following operations for a Product:

• You should implement two constructors: one that takes no arguments (quantity and price are 0, product name and locator are empty strings), and one that accepts a value for each of the four member variables.

• set and get all instance variables (make the instance variables private).

• bool isEqual(Product): this product is equal to another if they have the same product name and locator values.

• bool greaterThan(Product): this product is greaterThan another if its product name is greater than the others, OR if they have the same product names, if this product’s locator is greater than the other’s locator.

ProductInventory: When a product inventory object is created, it should dynamically allocate an array of Product, using a constructor parameter to specify the size. (You should also implement a destructor).

You should implement the following operations over the small store inventory:

addProduct: takes a product and adds it to the inventory. If the inventory is full, it should call the resize function first (see below). If a product with the same name and locator is already in the inventory, the add should fail and return false. If the quantity or price are invalid, it should fail and return false.

removeProduct: takes a product name and locator and removes any matching Product from the inventory. Returns true if a product was removed.

showInventory: displays a listing of the store inventory to the screen, one product entry per line. Output the locator, then quantity, then price, then product name.

sortInventory: reorders the products in the list, using the greaterThan(Product) function (does not display them).

getTotalQuantity: returns the total number of units of all of the products in the inventory (this is not the size of the inventory array).

resize: internal function that doubles the size of the inventory array (somewhat like duplicateArray). Allocates a new array, and copies all the existing products to it. Be sure to clean up.

Input/Output:

The main function should be a driver program that tests the functionality of the Product and ProductInventory classes. See the website for a driver program that MUST compile with your code (without changing the driver program). I recommend expanding the driver to do more complete testing of your code. Even if your program works correctly with the driver it may still have bugs not exposed by the driver.

NOTES: • Create and use a makefile to compile the executable program. There will be four goals in this makefile, because you will have three .cpp files. Use the following names for your files:

Product.h

Product.cpp

ProductInventory.h

ProductInventory.cpp

ProductDriver.cpp

Put a header comment at the top of each file.

• DO NOT change the names of the classes, functions or files.

• You do NOT need to use binary search for this assignment.

• You do NOT need to keep the array sorted for this assignment. If someone wants the inventory to be sorted, they will need to call sortInventory.

• Do not add extra I/O to the class functions! Only showInventory should do I/O.

• Your program must compile and run, otherwise you will receive a score of 0.

• Your program must pass Test Case 0 or you will receive a score of 30 or less with no credit for the other grading categories (correctness/constraints/style). This test case is in a driver file called TC0Driver.cpp on the class website. It is similar to the ProductDriver.cpp test driver, but it is much shorter. Your code must compile with this driver and produce the expected output (see the comments in the file). Your program must contain a Product class and a ProductInventory class to pass TC0.

Logistics: Since there are multiple files for this assignment, you need to combine them into one file before submitting them. It is not necessary to submit your ProductDriver.cpp file. You can use the zip utility from the Linux/Unix command line:

[...]$zip

assign5_xxxxxx.zip

ProductInventory.cpp

ProductInventory.h

Product.cpp

Product.h makefile

Explanation / Answer

Have is the implementation. I think I have implemented all the functions. Let me know if I missed any! All the best :)

class Product
{
private:
char prod_name[300];
char locator[20];
int quantity;
double price;

Product()
{
prod_name="";
quantity=0;
price=0.0;
locator=""
}

Product(char a[],char b[],int c, double d)
{
prod_name=a;
locator=b;
quantity=c;
price=d;
}

void setProdName(char prod[300])
{
   prod_name=prod;
}

char getProdName()
{
   return prod_name;
}

//create setter and getter for all

bool isEqual(Product p1, Product p2)
{
if(p1.prod_name.equalp2.prod_name)
   if((p1.locator.)equal(p2.locator)
       if(p1.price==p2.price)
           if(p1.quantity==p2.quantity)
               cout<<" Equal! ";
               else cout<<"Not equal!"
}


}


class ProductInventory
{
int i=0;
private:
Product* pvalue = NULL;

ProductInventory(int size)
{
pvalue=new Product[size];
}

~ProductInventory()
{
delete [] pvalue;
}

void addProduct(Product p)
{
if(i==pvalue.size())
//call resize
else
{
pvalue[i]=p;
i++;
}
}


bool removeProduct(String productName)
{
   //search for string productName in the array
}

void showInventory()
{
//print elements of the array

for(int i=0;i<pvalue.size();i++)
{
   cout<<pvalue[i].prod_name;
   cout<<pvalue[i].locator;
   cout<<pvalue[i].quantity;
   cout<<pvalue[i].price;
}

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote