store.h
Code:
#ifndef Store_H
#define Store_H
#include "inventory.h"
#include <string>
using namespace std;
class Store
{
public:
static const unsigned SIZE = 500;
// Constructors
Store();
Store(string ID2 , unsigned quantity , double cost);
// Modification Member Functions
void loadInventory ( const inventory &a );
string searchInventory ( string ID2 );
void modInventory ( string ID2, unsigned quantity, double cost );
void removeInventory ( string ID2 , inventory &a );
double showSum () const ;
Private:
// Member Variables
inventory store;
inventory item[SIZE];
unsigned size;
};
#endif
I'll assume those last couple lines being missing from the file is a typo. Also, Private should be private. SIZE cannot be initialized in the manner you have. As a static member, you would need to create and initialize the member variable in the store.cpp file. You would also need a change to how your inventory array was declared. You'd need to make it a pointer instead of an array and dynamically allocate space for it in the constructor and free it in the destructor. I would therefore strongly suggest using an STL container class such as list or vector which would make adding and deleting items easier to deal with and far more flexible than any standard array or pointer. You'd also be able to get rid of the SIZE and size data members since the container would be able to tell you itself how many items it was holding at any given time.
store.cpp
Code:
#include <iostream>
#include <iomanip>
#include <ctype.h>
#include "Store.h"
using namespace std;
// Constructors
Store::Store() { size=0;}
Store::Store(string ID2, unsigned quantity, double cost)
{
store.setInventory(ID2, quantity, cost);
size=0;
}
//Constant Member Functions
void Store::loadInventory (const inventory &a )
{
item[size++] = a;
}
string Store::searchInventory () const
{
string search;
cout << "Which product are you searching for?" << endl;
cin >> search ;
while (search != ID2)
{
item[size++];
}return search;
}
void Store::modInventory ( unsigned quantity, double cost );
{
char choice;
unsigned quantity = 0;
double cost = 0;
cout << "Do you want to change to price of item? Y/N" << endl;
cin >> choice;
if choice = 'Y' or 'y'
(
Again, is the fact you seem to be chopping off source code at the bottom merely a typo? There is a difference between = and ==. The above if test should be if( choice == 'y' || choice == 'Y' ). In the above while loop where you do search != ID2 there is no ID2 variable in scope. The inclusion of a second constructor doesn't seem to do anything. You initialize the store member variable but don't add it to the array (size is still 0)? A better way to initialize the store member would be to use an initialization list. The second constructor could be rewritten (if it really was necessary) as this:
Code:
Store::Store(string ID2, unsigned quantity, double cost) : store(ID2,quantity,cost), size(0)
{
// Don't need to do anything here since it's already been done in the initialization list.
}
inventory.cpp
Code:
#include "inventory.h"
#include <iostream>
using namespace std;
inventory::inventory()
{
ID = "UNDEFINED" ;
quantity = 0;
cost = 0;
}
void inventory::setString(string ID2)
{
ID2 = "A";
}
void inventory::setInventory(string ID2, unsigned quantity, double cost)
{
setString(ID2);
setQuantity(quantity);
setCost(cost);
}
Did you mean ID = ID2;? The above line as it stands does nothing. It will modify the local copy of ID2 to "A" and then when the function exits, the value will be thrown away as the variable is popped off the stack and nothing will have changed in the inventory object itself. A better name for the function might be setID. Also, you're still missing the rest of the functions in the source file, where are they? Is this another typo or simple omission of code?
Originally Posted by
Kross7
I have started it but am stuck on how to modify the item.
Based on the code attached, it would seem you're stuck on just about everything since I see nothing to get user input for new inventory items and add it to a store's inventory list. Start with that, show us some code that gets user input and adds an inventory item to the store. Then we can move on from there to removing an item.