On Feb 5, 8:09=A0pm, wrote:
Ok so basically my spec file is set up as follows:
#ifndef INVENTORY
#define INVENTORY
#include <string>
using namespace std;
struct Product
{
=A0 =A0 =A0 =A0int prodCode;
=A0 =A0 =A0 =A0string description;
=A0 =A0 =A0 =A0double price;
};
class Inventory
{
=A0 =A0private:
=A0 =A0 =A0 Product items[25];
=A0 =A0 =A0 int maxItems;
=A0 =A0 =A0 int curNoProd;
=A0 =A0 =A0 int findProduct(int /*Product Code*/);
=A0 =A0public:
=A0 =A0 =A0 Inventory(string /*File Name*/, int /*Max Items*/);
=A0 =A0 =A0 void addProduct(int /*Product Code*/, string /*Description*/,
double /*Price*/);
=A0 =A0 =A0 void displayProduct(int /*Product Code*/);
=A0 =A0 =A0 void writeToFile(ofstream&);
=A0 =A0 =A0 bool isArrayFull(){return (curNoProd =3D=3D maxItems);};
=A0 =A0 =A0 int getCurrentNoElems() const {return curNoProd;};
=A0 =A0 =A0 void increasePrice(int /*Product Code*/, double /*Price
Increase*/);};
#endif
Now in my implementation file i have most of the function defined
however my problem occurs when trying to define my addProduct and
increasePrice functions. Currently i have this:
void Inventory::addProduct(int newProductCode, string newDescription,
double newPrice)
{
=A0 =A0 =A0if (newPrice <=3D 0 || newPrice > 50)
=A0 =A0 =A0 =A0 cout<<"Price is out of range, must be greater than 0, with=
a
max of 50"<<endl;
=A0 =A0 =A0else if (newProductCode < 10000 || newProductCode > 99999)
=A0 =A0 =A0 =A0 =A0 =A0 cout<<"Product code must be a 5 digit number."<<en=
dl;
=A0 =A0 =A0 =A0 =A0else
=A0 =A0 =A0 =A0 =A0{
=A0 =A0 =A0 =A0 =A0 =A0 =A0int location =3D findProduct(newProductCode);
=A0 =A0 =A0 =A0 =A0 =A0 =A0if (location !=3D curNoProd)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cout<<"Product "<<newProductCode<<" alread=
y
exists."<<endl;
=A0 =A0 =A0 =A0 =A0 =A0 =A0else if (isArrayFull())
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cout<<"No more room for items, =
current max is
"<<maxItems<<endl;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 items.prodCode[location] =3D n=
ewProductCode;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 items.description[location] =
=3D newDescription;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 items.price[location] =3D newP=
rice;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 curNoProd++;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
=A0 =A0 =A0 =A0 =A0}
}
I am getting three errors on for each of my assignment statements.
request for member `prodCode' in `((Inventory*)this)->Inventory::items', w=
hich is of non-class type `Product[25]'
request for member `description' in `((Inventory*)this)->Inventory::items'=
, which is of non-class type `Product[25]'
request for member `price' in `((Inventory*)this)->Inventory::items',
which is of non-class type `Product[25]'
those are my errors and i cannot figure out why these errors are
occuring.
It should be items[location].prodCode instead of
items.prodCode[location]
-Sunita
.