Jurassic park

closed account (23q2T05o)
Hi, so I have class Dinosaur, I have fields for the dino, I have class Cage, I have fields for the cage and I have Dinosaur*fDinos in class Cage. One of the Cage class fields is char* fSize. If the size is small I can add one Dino, if the size is medium - 3 dinos and large - 10 dinos. I have class Jurassic where I have Cage*fCages.
I have these methods:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Cage::addDinosaur(const Dinosaur& newDinos)
{
	if (fDinos->isValid_dinos())
	{
		if (fSize_dino >= fCapacity_dino)
		{
			this->resizeDinos(fCapacity_dino * 2);
		}
		
		fDinos[fSize_dino] = newDinos;
		fSize_dino++;
	}

	}
}


1
2
3
4
5
6
7
8
9
10
11
12
13
void Jurassic::add_cage(const Cage& newCage)
{
	if (fCages->isValid_cage()) {
		if (fSize_cage >= fCapacity_cage)
		{
			this->resize_cage(fCapacity_cage * 2);
		}

		fCages[fSize_cage] = newCage;
		fSize_cage++;
	}
	
}


So the question is: how to add a dino to the cage if there is space in the cage /for example if it is empty and it is larg I can add 10 dinos, if it is medium and a ihave 1 dino already in there how to add 2 more and so on/? And if I don't have space for the dino I have to add a new cage to Jurassic park. Please help, do I have to create a new method, what parameters should I have, this is for OOP project c++, can't use strings or vectors.
Last edited on
closed account (23q2T05o)
Something like:
if (fCages->getSize() == "Small"){}
if (fCages->getSize() == "Medium"){}
if (fCages->getSize() == "Large"){}
Hello izlezotfilmabrat,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.


You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



The functions are nice, but without the class definition I have no idea if what you are doing is correct because I have no idea what you are working with.

Also without enough of "main" to set up and use these functions I have no idea what should be there.

That is just me. I am more a hands on see how it works type person.

Andy
closed account (23q2T05o)
So my idea is something like that:

we have:
cage[particular cage].dino[i]
or example: cage[4].dino[5] the sixth dino in the fifth dino
so I gotta have a getter in the dino class that will always return 1 cause every dino on their own is just one dino
the in a for cycle
for(int i=0; i<MAX_SIZE_OF_THE_CAGE;i++)
{counter+=cage[particular cgae].dino[i].getnumber();}
and if the counter is less than the max size of the cage I just add a new Dino.
Is that a good idea and how I can improve it?
Topic archived. No new replies allowed.