item:
Code:
#define empty "-"
class item
{
public:
char name[100];
int price, value;
item(char *n, int p, int v);
item();
~item();
item &operator=(const item & cpy);
bool operator==(const item & cmp);
bool operator!=(const item & cmp);
bool isEmpty();
void removeItem();
};
item::item(char *n, int p, int v)
{
strcpy(name, n);
price = p;
value = v;
}
item::item()
{
*this = item(empty, 0, 0);
}
item::~item()
{}
item &item::operator =(const item & cpy)
{
strcpy(name, cpy.name);
price = cpy.price;
value = cpy.value;
return *this;
}
bool item::operator ==(const item & cmp)
{
if(!strcmp(name, cmp.name) && price == cmp.price && value == cmp.value)
return true;
return false;
}
bool item::operator !=(const item & cmp)
{
return *this == cmp ? false : true;
}
bool item::isEmpty()
{
return *this == item(empty, 0, 0) ? true : false;
}
void item::removeItem()
{
*this = item(empty, 0, 0);
}
file: (looks healthy)
Code:
0
15
10
1
20
10
Health Potion
5
5
-
0
0
-
0
0
-
0
0
-
0
0
Weapon is declared as an item, and the inventory is an array of five items. Hope that helps! :D