Arrays-PLEASE HELP

Hi there
I currently have a sample Array(which i have named Arsenal). But i need to change it so i can load bullets and shotgunshells (randomly generated).I have these as classes
i have a bullet class
and a shotgunshell class
I need help on what part of the loop/or Array i need to change to add those specific classes.

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  //You are to create the following classes • Point, • AmmunitionManager
//has Ammunition, using inheritance, is a, Bullet, ShotgunShell 
//• WeaponManager has Weapons, using inheritance, is a, Pistol,
//Shot Gun • Player, • Game has Player, AmmunitionManager, WeaponManager
//Each class in the Game has as one of its attributes a Point object.
//The other attributes and functions have to be determined by you.
//You are to create a dynamic array of Ammunition (the arsenal). 
//You are to load the dynamic array of Ammunition with a mixture of
//bullets and shot gun shells (randomly generated).
//Once the arsenal is defined with bullets and shotgun shells you are
//to load your bullets or shot gun shells into a chamber
//(holds a fixed number of bullets) or barrel (single or double)
//into the respective weapons. 
//You are to use cout’s in the constructors of each of the objects
//to output messages to the console as to what is happening in the game.
//You are to create multiple constructors for each object;
//override the default constructor and at least one other custom
//constructor

#include "iostream"
#include "bullet.h"
#include "point.h"
#include "game.h"
#include "AmmunitionManager.h"
#include "bullet.h"
#include "ShotgunShell.h"
#include "WeaponManager.h"
#include "Shotgun.h"
#include "Pistol.h"

using namespace std; 
void InitialiseArray( int *, int);	//As arrays are pointers I can pass an array as a pointer
void DisplayArray( int [], int);	//Passing an array, array syntax
int main()
{
	const int ciSize = 10;
	int ArsenalArray[ciSize];		//One dimensional array

	int Arsenal[ciSize] = {2,7,12,-5,9,10};
	DisplayArray( Arsenal, ciSize);
	cout << endl << endl;

	InitialiseArray( ArsenalArray, ciSize);
	DisplayArray( ArsenalArray, ciSize);
	cout << endl << endl;

	//Pistol pistol1;
	//pistol1.setpgColour();
//WeaponManager Shotgun;
//Shotgun.setmiWeapons(23);
	//WeaponManager weapon1;
	//weapon1.setmiWeapons(100);
	//Bullet theBullet;				//object of bullet
	//Bullet theBullet2(23,24);
	//Game theGame;
	//Game theGame2(45,23);
	//Point thePoint;
	//ShotgunShell shot1;

//theBullet.setDamage(23);
//Bullet theBullet2(3,4);
//theBullet.setX(10);
//theBullet.setY(24);

//	Ammunition theAmmunition;
//	Ammunition theAmmunition2(1,2);
//theAmmunition.setA(45);
//theAmmunition.setB(15);

//Bullet ihBullet;
//Bullet ihBullet2;
//ihBullet.setA(23);
//ihBullet2.setB(0);


system("pause");

	
}
void InitialiseArray( int *aNumbers, int iS )
{
	for( int i=0; i < iS; i++ )
	{
		aNumbers[i] = -1;
	}
}
void DisplayArray( int aNumbers[], int iS )
{
	for( int i=0; i < iS; i++ )
	{
		cout << aNumbers[i] << " ";
	}
}
Why is your arsenal an array of integers? The basics for your program should be something like this:

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
class Ammunition //abstract class
{
public:
	virtual int get() = 0;
};

class Bullet : public Ammunition
{
public:
	Bullet() { std::cout << "Created a bullet.\n"; }
	int get() { return 1; }
};

class ShotgunShell : public Ammunition
{
public:
	ShotgunShell() { std::cout << "Created a shotgun shell.\n"; }
	int get() { return 2; }
};

int main()
{
	int arsenalSize;
	Ammunition ** Arsenal; //Arsenal is an array of Ammunition pointers

	//do input operations to find out arsenalSize
	Arsenal = new Ammunition*[arsenalSize];

	//do your other stuff
	for (int i = 0; i < arsenalSize; ++i)
		delete Arsenal[i];
	delete[] Arsenal;
	return 0;
}
im using microsoft visual express, and i didnt want to bombard the page with all the class codes.
What is your question at this point?

Lines 37-39: Arsenal and ArsenalArray are fixed arrays, not dynamic arrays as specified in the comments.

@cplubeginner89

I just wanted to point out that you are supposed to be creating a dynamic array of Bullets and ShotgunShells, both derived from Ammunition, and not a fixed array of integers.
Topic archived. No new replies allowed.