Trying to create an inventory system

I need to create an inventory system that can add delete and edit. For one player there can be as as many characters as the player wishes to create so for an example a player can have 5 different characters. I want the player to be able to run the program and choose add new character and then be able to type in the characters name and gender and then select the type of character which will have preset values for magical ability, strength, health and wealth. I then want the player to be able to edit the characters name, gender or type or delete that character.

so far this is what I have got and am completely stuck on where to go next.

Inventory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "stdafx.h"
#include "Character.h"
#include "ObjectArray.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
	int count;
	Character one;
	Character a ("Bob", "Male", "Wizard", 9, 3, 6, 8);



	ObjectArray o;
	o.addElement(a);


	//Display the contents of the array
	cout << "The contents of the object array are ...." << endl;
	for(count = 0; count < o.getUsed(); count++)
		cout << "Character Name: " << o[count].getuniquename() << endl;
	for(count = 0; count < o.getUsed(); count++)
		cout << "Sex of Character: " << o[count].getsex() << endl;
	for(count = 0; count < o.getUsed(); count++)
		cout << "Type of Character: " << o[count].gettype() << endl;
	for(count = 0; count < o.getUsed(); count++)
		cout << "Chracters Magical Ability: " << o[count].Character::getmagicalability() << endl;
	for(count = 0; count < o.getUsed(); count++)
		cout << "Characters Strength: " << o[count].Character::getstrength() << endl;
	for(count = 0; count < o.getUsed(); count++)
		cout << "Chacracters Health: " << o[count].Character::gethealth() << endl;
	for(count = 0; count < o.getUsed(); count++)
		cout << "Characters Wealth: " << o[count].getwealth() << endl;
	system ("pause");
 return 0;
}


Character.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "stdafx.h"
#include "Character.h"
#include <string>
#include <iostream>

Character::Character(void)
{
	uniquename = "";
	sex = "";
	type = "";
	magicalability = 0;
	strength = 0;
	health = 0;
	wealth = 0;
}

Character::Character(string un, string s, string t, int ma, int st, int h, int w)
{
	uniquename = un;
	sex = s;
	type = t;
	magicalability = ma;
	strength = st;
	health = h;
	wealth = w;
}

Character::~Character(void)
{
}

string Character::getuniquename()
{
 return uniquename;
}


string Character::getsex()
{
	return sex;
}

string Character::gettype()
{
	return type;
}

int Character::getmagicalability()
{
	return magicalability;
}

int Character::getstrength()
{
	return strength;
}

int Character::gethealth()
{
	return health;
}

int Character::getwealth()
{
	return wealth;
}


Objectarray.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "stdafx.h"
#include "ObjectArray.h"


ObjectArray::ObjectArray(void) :capacity(10), used(0)
{
	a = new Character[capacity];
}


ObjectArray::~ObjectArray(void)
{
	delete [] a; //as we have used a dynamic array we have
	// to do this to return memory to the free store
}

void ObjectArray::addElement(Character element)
{
	a[used] = element;
	used++;
}

Character& ObjectArray::operator[](int index)
{
	return a[index];
}

int ObjectArray::getUsed()
{
	return used;
}


Character.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
#include <string>
using namespace std;

class Character //a record holding all the data on one character
{
	private:
			string uniquename;   //allows for a char called uniquename that can be up to 35 characters long
            string sex;  //allows for a char called sex that can be up to 6 characters long
            string type; //allows for a char called type that can be up to 8 characters long
            int magicalability; //holds the magicalability of the character
            int strength;       //holds the strength of the character
            int health;       //holds the health of the character
            int wealth;       //holds the wealth of the character

public:
	Character(void);
		Character(string, string, string, int, int, int, int);
		~Character(void);
			string getuniquename();
			string getsex();
			string gettype();
			int getmagicalability();
			int getstrength();
			int gethealth();
			int getwealth();
};


Objectarray.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#pragma once
#include "Character.h"

class ObjectArray
{
private:
	Character *a; //used for an array of Person objects
	int capacity;
	int used;
public:
	ObjectArray(void);
	void addElement(Character element);
	Character& operator[](int index);
	int getUsed();
	~ObjectArray(void);
};


Any help will be much appreciated as to how to move on.

Thanks
consider having a selection system that asks the user what they want to do with the character, for example, change age or something.
I can add say for example a menu system asking what they would like to do but have no clue how to implement the edit, add and delete function? I know at present it displays what I have typed in but I know this part is no good if I want to allow the user to change the data.
Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <string>
void ChangeAttribute(Character& Player)
{
    char answer;
    std::string name;
    do
    {
         std::cout<<"Please make a selection:"<<std::endl;
         std::cout<<"Change (N)ame:"<<std::endl;
         std::cin>>answer;
         switch(answer)
        {
          case 'n':
                 std::cout<<"Enter new name:";
                 std::cin>>name;
                 Player.setName(name);
                 break;
         }
     }
     while(answer != 'q');
};


you would need to select the player and pass it to the function.

This is really just a skeleton code framework. you'll need to add extras.
Last edited on
Topic archived. No new replies allowed.