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: 3685356 • 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

step 1:

#include <iostream>

#include <string>

#include <fstream>

#include <cstdlib>

#include <conio.h>

#include <iomanip>

class Inventory {

   private:

      int ProdID, qty_stock, reord_lev;

      string ProdDesc, manu;

      float unitcost;

       

   public:

      Inventory(int, string, string, float, int, int);

      void listcurinv_1();

      void listcurinv_2();

      void add_stock();

      void rmv_stock();

      void add_prod();

      void rmv_prod();

      void calc_inv();

      void list_reord();

};

Inventory::Inventory(int id, string desc, string manufac, float cost, int qty, int r_level) {          // constructor

   ProdID = id;

   ProdDesc = desc;

   manu = manufac;

   unitcost = cost;

   qty_stock = qty;

   reord_lev = r_level;

}

void Inventory::listcurinv_1() {

   // read records from data file

   int i = 0;

   ifstream infile("a:\CO856 Assignment 1\sportsstore.txt");

   while (!infile.eof() || i < 100) {

      infile.getline(Product[i].ProdID, 10, ',');

      infile.getline(Product[i].ProdDesc, 30, ',');

      infile.getline(Product[i].manu, 15, ',');

      infile.getline(Product[i].unitcost, 10, ',');

      infile.getline(Product[i].qty_stock, 5, ',');

      infile.getline(Product[i].reord_lev, 5, ' ');

      i++;

   }

     

   // sorting by product description

   string spare;

   for (int j = 0; j < i-1; j++) {

      for (int k = 0; k < i; k++) {

         if (Product[j].ProdDesc > Product[k].ProdDesc) {

            spare = Product[j].ProdDesc;

            Product[j].ProdDesc = Product[k].ProdDesc;

            Product[k].ProdDesc = spare;

         }

      }

   }

   // reset i record counter to 0

   i = 0;

   // display data from the file

   while (!infile.eof() || i < 100) {

      cout << setw(10) << Product[i].ProdID;

      cout << setw(30) << Product[i].ProdDesc;

      cout << setw(15) << Product[i].manu;

      cout << setw(10) << Product[i].unitcost;

      cout << setw(5) << Product[i].qty_stock;

      cout << setw(5) << Product[i].reord_lev << endl;

   }

}

or

program 2:


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cctype>

using namespace std;

//void main()

const int DESC_SIZE = 51; // holds inventory description size
const int DATE_SIZE = 11; // holds date size

struct InventoryItem // inventory structure

{

char desc[DESC_SIZE]; // description holds 31 charaters
int quantity; // variable to hold quantity
double whlCost; // variable to hold wholesale cost
double rtlCost; // variable to hold retail cost
char date[DATE_SIZE]; // variable to hold date

};

int main()
{

void addRec(fstream &); // function prototype to add a record
void viewRec(fstream &); // function prototype to view a record
void chgRec(fstream &); // function prototype to change a record


{

long selection; // variable to hold menu selection
long recNum; // variable to hold the record number of the inventory item

fstream inventory ("Inventory.dat", ios::in | ios::out | ios::binary);
InventoryItem record = {" ", 0, 0.0};

cout << fixed << showpoint << setprecision(2);
cout << "Inventory Managment"<<endl;


for (int count = 0; count < 5; count++) // write the blank records

{

inventory.write(reinterpret_cast<char *>(&record),sizeof(record));

}

inventory.close();

inventory.open("Inventory.dat", ios::out | ios::binary);

while (selection != 4)

{
switch (selection)
{

case 1: // Add a new record

{
addRec(inventory);
break;
}

case 2: //View record

{
viewRec(inventory);
break;
}

case 3: //Change record

{
chgRec(inventory);
break;
}

default: //Invalid selection

{
cout << "Invalid selection" << endl;
}

selection = menu();

}

}

cout<<"Hava a nice day."<<endl;
inventory.close();
system("pause");

return 0;

}
int menu()
{
int choice;

cout << "Please make a selection, 1 through 4." << endl;
cout << "1. Add a new record"<<endl;
cout << "2. View an exisitng record"<<endl;
cout << "3. Change an exisitng record"<<endl;
cout << "4. Exit"<<endl;
cout << endl;
cout << "Enter your choice (1-4): ";

cin>>choice;

while(choice < 1 || choice > 4)

{
cout<<"Invaild selection!"<<endl;
cout<<"Please enter your choice (1-4) : ";

cin>>choice;
}

cout << endl;
return choice;

}

void addRec(fstream &file) // function to add new information to inventory

{
cout<<"Enter the following inventory data:"<<endl;

fstream inventory("Inventory.dat", ios::out | ios::binary);

InventoryItem record;

//Enter new data

cout << "Description: ";

cin.ignore();
cin.getline(record.desc, 51);
cin >> record.desc;

cout < <"Quantity: ";
cin >> record.quantity;

cout << "Wholesale cost: ";
cin >> record.whlCost;

cout << "Retail price: ";
cin >> record.rtlCost;

cout << "Date added to inventory (in 00/00/0000 format): ";
cin >> record.date;

inventory.write(reinterpret_cast<char *>(&record),sizeof(record));
cout<<"Record added to file."<<endl;

file.close();

}

void viewRec(fstream &file) // function to view record

{

fstream inventory ("Inventory.dat", ios::out | ios::binary);
InventoryItem record;

long recNum;

cout << "Enter the record number of the item to view:";
cin >> recNum;

// Move to the record and read it.

inventory.seekg(recNum * sizeof(record), ios::beg);
inventory.read(reinterpret_cast<char *>(&record),sizeof(record));

cout << "Description: " << record.desc << endl;
cout << "Quantity: " << record.quantity << endl;
cout << "Wholesale cost: " << record.whlCost << endl;
cout << "Retail price: " << record.rtlCost << endl;
cout << "Date (in 00/00/0000 format): " << record.date << endl;

if(file.fail())
file.clear();
file.close();

}
void chgRec(fstream &file) // function to change a record
{

fstream inventory ("InventoryFile.dat", ios::out | ios::binary);
InventoryItem record;

long recNum;

cout << "Enter the record number of the item you want to edit: ";
cin >> recNum; // Move to the record and read it.

inventory.seekg(recNum * sizeof(record), ios::beg);
inventory.read(reinterpret_cast<char *>(&record),sizeof(record));

cout << "Description: " << record.desc << endl;
cout << "Quantity: " << record.quantity << endl;
cout << "Wholesale cost: " << record.whlCost << endl;
cout << "Retail price: " << record.rtlCost << endl;
cout << "Date (in 00/00/0000 format): " << record.date << endl;
cout << endl;

// Move back to the beginning of this record's position

inventory.seekp(recNum * sizeof(record), ios::beg);

// Write new record over the current record

// inventory.write(reinterpret_cast<char *>(&record),sizeof(record));

// Close the file.

inventory.close();
}

system("pause");
return 0;

}

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