Making a vector of type class?

Pages: 12
Hello MikeyBoy.

Thank you for the suggestion. I cannot get the second method to work for me, but the first one got rid of the error lines so that helps.

As for the second point, I have been at this code for days and have made no progress as of yet. My class is very messy and although I have tried to clean it up, it just keeps getting worse because I cannot understand why things are not working properly.

I started over almost completely and am only using the second piece of code above right now to try and hammer out my mistakes.

My main issue right now is getting my vector to print the contents:

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
#include <iostream>
#include <vector>
using namespace std;



class Animal {
public:
    //enumerators
    enum species_t {LION, FOX, HAWK, RAVEN, TETRA, SALMON};
    enum gender_t {MALE, FEMALE};

    //base constructor
    Animal() {

    }

    //overloaded constructor
    Animal(species_t species, gender_t gender, int age) {

    }

    void addAnimal(species_t species, gender_t gender, int age) {
        animals.push_back(Animal(species, gender, age));
    }

    //getInfo funcs

    species_t specie() {
        return species;
    }

    gender_t gende() {
        return gender;
    }

    int ag() {
        return age;
    }

    //print func
    void printVec(vector<Animal>& myAnimals) {
        for (int i = 0; i < myAnimals.size(); i++) {
            cout << "Animal #" << i + 1 << myAnimals[i].specie() << " " << myAnimals[i].gende() << " " << myAnimals[i].ag();
        }
    }

private:
    //member vars
    int age = 0;
    species_t species = LION;
    gender_t gender = MALE;
    vector<Animal> animals;
};

int main() {
    Animal myAnimals;
    myAnimals.addAnimal(Animal::LION, Animal::MALE, 11);
    myAnimals.printVec(myAnimals);
    return 0;
}


I am getting an error from my printVec call in the class and I do not know how to fix it.

If anyone knows where I should go from here, please let me know. I am completely lost at this point haha.
Last edited on
You've defined Animal::printVec() to take a vector of Animal objects.

On line 59, you're trying to pass a single Animal object.

Hence the error.
As MikeyBoy has said before and I agree - IMO the design isn't right. The Animal class shouldn't have a vector<Animal>

Why???

I suggest before more time is spent on dealing with code issues, the design is re-considered.
Do you mean 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>

class Animals {
public:
	enum species_t { LION, FOX, HAWK, RAVEN, TETRA, SALMON };
	enum gender_t { MALE, FEMALE };

	void addAnimal(species_t species, gender_t gender, unsigned age) {
		animals.emplace_back(species, gender, age);
	}

	void print() const noexcept {
		for (size_t i = 0; i < animals.size(); ++i)
			std::cout << "Animal #" << i + 1 << ' ' << animals[i].specie() << ' ' << animals[i].gende() << ' ' << animals[i].ag() << '\n';
	}

private:
	struct Anim {
		unsigned age {};
		species_t species {};
		gender_t gender {};

		Anim(species_t s, gender_t g, unsigned a) noexcept : species(s), gender(g), age(a) {}

		species_t specie() const noexcept {
			return species;
		}

		gender_t gende() const noexcept  {
			return gender;
		}

		unsigned ag() const noexcept {
			return age;
		}
	};

	std::vector<Anim> animals;
};

int main() {
	Animals myAnimals;

	myAnimals.addAnimal(Animals::LION, Animals::MALE, 11);
	myAnimals.addAnimal(Animals::FOX, Animals::FEMALE, 9);
	myAnimals.print();
}



Animal #1 0 0 11
Animal #2 1 1 9

@seeplus This is pretty much what I am looking for. How do I print out the value of the enum as opposed to the index? So for

myAnimals.addAnimal(Animals::LION, Animals::MALE, 11);

I want to print out "Animal #1 Lion, Male, 11"
Last edited on
One method of equating an actual string-type value for an enum value is to have an array of string, vector maybe, that contain, for example "Lion", "Fox" and so on that correspond to an enum value. If your created Animal object has a species type of HAWK (enum value 2), you can select element[2] of your strings and get "Hawk".

A look-up table.
I want to print out "Animal #1 Lion, Male, 11"
The answer is in the original suggestion.

1
2
3
4
5
enum species_t { LION, COW, DOVE, RAVEN, GUPPY, GOLDFISH } ;
    static constexpr const char* const species_text[] = { "lion", "cow", "dove", "raven", "guppy", "goldfish" };

    enum gender_t { MALE, FEMALE } ;
    static constexpr const char* const gender_text[] = { "male", "female" };


and
1
2
3
4
5
friend std::ostream& operator << ( std::ostream& stm, const animal& a ) {

      return stm << "animal{" << animal::species_text[a.species()] << ','
                 << a.age() << ',' << animal::gender_text[a.gender()] << '}' ;
   }
Oops, I definitely overlooked that. Thank you for pointing that out for me. It was fairly straightforward to implement as well.

I have now made some progress in terms of this project thanks to all of you. I appreciate all of the help over the last few days. Thank you for being patient with me :).
Consider making the vector and its associated functions static members of the class.
https://en.cppreference.com/w/cpp/language/static

For example:
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
#include <iostream>
#include <vector>

class Animal {

    public:
        //enumerators
        enum species_t {LION, FOX, HAWK, RAVEN, TETRA, SALMON};
        enum gender_t {MALE, FEMALE};

        //base constructor
        Animal() = default ;

        //overloaded constructor (it should initialise the member variables)
        Animal(species_t species, gender_t gender, int age) noexcept :
            age_(age), species_(species), gender_(gender) {

            // animals.push_back(*this);
        }

        species_t species() const noexcept { return species_ ; }
        gender_t gender() const noexcept { return gender_ ; }
        int age() const noexcept { return age_ ; }

        // https://en.cppreference.com/w/cpp/language/static
        static void add( species_t species, gender_t gender, int age ) {

            animals.emplace_back( species, gender, age ) ;
        }

        //print func
        static void print() { // https://en.cppreference.com/w/cpp/language/static

            for( std::size_t i = 0 ; i < animals.size() ; ++i ) {

                static const char* const species_text [] = { "LION", "FOX", "HAWK", "RAVEN", "TETRA", "SALMON" };

                std::cout << "Animal #" << i+1 << ' ' << species_text[ animals[i].species() ]
                          << ' ' << ( animals[i].gender() == MALE ? "MALE" : "FEMALE" )
                          << ' ' << animals[i].age() << '\n' ;
            }
        }

    private:
        //member vars
        int age_ = 0;
        species_t species_ = LION;
        gender_t gender_ = MALE;

        // https://en.cppreference.com/w/cpp/language/static
        static std::vector<Animal> animals;
};

// define the static member
// "Static data members are not associated with any object.
// They exist even if no objects of the class have been defined.
// There is only one instance of the static data member in the entire program"
// https://en.cppreference.com/w/cpp/language/static#Static_data_members
std::vector<Animal> Animal::animals ;

int main() {

    // add some animals by calling the static member function of Animal
    // to refer to the static member, we can use its qualified name
    Animal::add(Animal::LION, Animal::MALE, 11);
    Animal::add(Animal::FOX, Animal::FEMALE, 6);
    Animal::add(Animal::HAWK, Animal::FEMALE, 2) ;
    Animal::add(Animal::LION, Animal::FEMALE, 5);

    Animal::print() ;
}

http://coliru.stacked-crooked.com/a/4ed9d80bb08855a6
@OP
And, as far as the animal <vector> is concerned, it is not part of the animal class.
The <vector> is a pile of animals to be played with outside the class, in main.

( PS: My very early comment about parents obviously doesn't/didn't apply to the stated problem. Interestingly there are numerous biological, political (even), historical, cultural and religious absurdities in the scenario - but these are outside the scope of your problem(s) )

1
2
3
4
5
6
7
8
9
10
11
12
int main() 
{

    // create a vector with two animals
    std::vector<animal> animals { animal( animal::COW, animal::FEMALE, 3 ), animal ( animal::LION, animal::MALE, 5 ) } ;

    animals.emplace_back( animal::LION, animal::FEMALE, 4 ) ; // add one more animal
    print(animals) ;

    add_offsprings( animals, animal::LION ) ; // add offsprings for female lions
    print(animals) ;
}
Or stick with the original suggestion and avoid sidetracks/overlaps by 'going static'.
I have decided to take the static route since it really simplifies things for me. I do have a question about some static methods, however. Specifically about 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
  static bool inHeat()  { //checks if animal is in heat (time to reproduce)
        bool heat = false;
        for (auto& a : animals) {
            if (a.species() == Animal::SALMON && a.gender() == Animal::FEMALE) {
                cout << "True Salmon" << endl;
                heat = true;
            }
            else if (a.species() == Animal::TETRA && a.gender() == Animal::FEMALE) {
                cout << "True Tetra" << endl;
                heat = true;
            }
            else if (a.species() == Animal::RAVEN && a.gender() == Animal::FEMALE) {
                cout << "True Raven" << endl;
                heat = true;
            }
            else if (a.species() == Animal::HAWK && a.gender() == Animal::FEMALE) {
                cout << "True Hawk" << endl;
                heat = true;
            }
            else if (a.species() == Animal::LION && a.gender() == Animal::FEMALE) {
                cout << "True Lion" << endl;
                heat = true;
            }
            else if (a.species() == Animal::FOX && a.gender() == Animal::FEMALE) {
                cout << "True Fox" << endl;
                heat = true;
            }
        }

        return heat;
    }


and this:

1
2
3
4
5
6
7
    static void userPrompts() {
        for (auto& a : animals) {
            if (a.inHeat()) {
                cout << "in heat" << endl;
            }
        }
    }


There are too many outputs (which I have learned is due to the userPrompts() function) and I want to tweak it so that I only get "in heat" once per animal who is in heat and nothing else (it prints "True [Animal]" several times even though it should only be using the true/false info from inHeat().
Last edited on
Shouldn't in_heat() // check if this particular animal is in heat be a non-static member function?

For example:
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
94
95
96
97
#include <iostream>
#include <vector>

class Animal {

    public:
        //enumerators
        enum species_t {LION, FOX, HAWK, RAVEN, TETRA, SALMON};
        enum gender_t {MALE, FEMALE};

        //base constructor
        Animal() = default ;

        //overloaded constructor (it should initialise the member variables)
        Animal(species_t species, gender_t gender, int age) noexcept :
            age_(age), species_(species), gender_(gender) {

            // animals.push_back(*this);
        }

        species_t species() const noexcept { return species_ ; }
        gender_t gender() const noexcept { return gender_ ; }
        int age() const noexcept { return age_ ; }

        // https://en.cppreference.com/w/cpp/language/static
        static void add( species_t species, gender_t gender, int age ) {

            animals.emplace_back( species, gender, age ) ;
        }

        //print func

        void print() const { // print info about this one animal (not static)

            static const char* const species_text [] = { "LION", "FOX", "HAWK", "RAVEN", "TETRA", "SALMON" };

            std::cout << species_text[ species() ]
                      << ' ' << ( gender() == MALE ? "MALE" : "FEMALE" )
                      << ' ' << age() << '\n' ;
        }

        static void print_all() { // https://en.cppreference.com/w/cpp/language/static

            for( std::size_t i = 0 ; i < animals.size() ; ++i ) {

                    std::cout << "Animal #" << i + 1 << ": " ;
                    animals[i].print() ;
            }

        }

        bool in_heat() const noexcept { // checks if this particular animal is in heat (note: not static)

            if( gender() == MALE ) return false ;

            // female, check species, age etc.
            // TO DO: rest of logic
            return age() > 1 ; // this is just a place holder for now
        }

    static const std::vector<Animal>& list() { return animals ; }

    private:
        //member vars
        int age_ = 0;
        species_t species_ = LION;
        gender_t gender_ = MALE;

        // https://en.cppreference.com/w/cpp/language/static
        static std::vector<Animal> animals;
};

// define the static member
// "Static data members are not associated with any object.
// They exist even if no objects of the class have been defined.
// There is only one instance of the static data member in the entire program"
// https://en.cppreference.com/w/cpp/language/static#Static_data_members
std::vector<Animal> Animal::animals ;

int main() {

    // add some animals by calling the static member function of Animal
    // to refer to the static member, we can use its qualified name
    Animal::add(Animal::LION, Animal::MALE, 11);
    Animal::add(Animal::FOX, Animal::FEMALE, 6);
    Animal::add(Animal::HAWK, Animal::FEMALE, 2) ;
    Animal::add(Animal::LION, Animal::FEMALE, 5);
    Animal::add(Animal::FOX, Animal::MALE, 6);

    // Animal::print_all() ;

    std::cout << "animals in heat:\n-------------\n" ;
    for( const Animal& a : Animal::list() ) {

        if( a.in_heat() ) a.print() ;
    }
}

http://coliru.stacked-crooked.com/a/af3d279e0e4ab09e
Ahh, I see. I'm still learning all of the technical things so thank you for letting me know when static is actually used. This works perfectly and I appreciate all of the help, JLBorges.
Using (modified) Factory pattern:

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <random>

#include "animal_constants.h"

class Animal
{
public:
    static int COUNTER;
protected:
    int serial_no{-9};
    int species{-9};
    int age{0};
    int gender{-9};
    int reproduction_cycle{-9};
    
public:
    Animal();
    void setSerial();
    void ageByMonth();
    int getSpecies() { return species; }
    bool getBreed();
    
    friend std::ostream& operator<<(std::ostream&, Animal&);
};


int Animal::COUNTER = 0;
Animal::Animal(){setSerial();}
void Animal::setSerial(){serial_no = COUNTER++;}
void Animal::ageByMonth()
{
    int temp = age;
    age = temp + 1;
}

bool Animal::getBreed()
{
    if(
       (age > 0) and
       (gender == FEMALE) and
       (age % Cycle_time[reproduction_cycle] == 0)
       )
    {
        return true;
    }
    else
    {
        return false;
    }
}

std::ostream& operator<<(std::ostream& out, Animal& a)
{
    return out
    << '#' << std::setw(3) << std::right << a.serial_no << ' '
    << std::setw(10) << std::left << Species_name[a.species] << ' '
    << std::setw(6) << std::left << Gender_name[a.gender] << ' '
    << std::setw(3) << std::right << Cycle_time[ a.reproduction_cycle ]
    << std::setw(3) << std::right << a.age << ' '
    << a.getBreed();
}

class Mammal: public Animal
{
public:
    Mammal(){ reproduction_cycle = MAMMAL;};
};

class Cat: public Mammal
{
public:
    Cat(Gender g, int aAge){gender = g; age = aAge; species = CAT;}
};

class Dog: public Mammal
{
public:
    Dog(Gender g, int aAge){gender = g; age = aAge; species = DOG;}
};

class Fish: public Animal
{
public:
    Fish(){species = FISH; reproduction_cycle = FISH;}
};

class Goldfish: public Fish
{
public:
    Goldfish(Gender g, int aAge){gender = g; age = aAge; species = GOLDFISH;}
};

class Shark: public Fish
{
public:
    Shark(Gender g, int aAge){gender = g; age = aAge; species = SHARK;}
};

class Bird: public Animal
{
public:
    Bird(){species = BIRD; reproduction_cycle = BIRD;}
};

class Eagle: public Bird
{
public:
    Eagle(Gender g, int aAge){gender = g; age = aAge; species = EAGLE;}
};

class Parakeet: public Bird
{
public:
    Parakeet(Gender g, int aAge){gender = g; age = aAge; species = PARAKEET;}
};

#include <ctime>
class Ark:public Animal
{
private:
    std::vector<Animal*> boat;
public:
    Ark();
    void display();
    void add(Animal&);
    void ageArkByMonth();
};

Ark::Ark(){ srand (time(nullptr)); }
void Ark::display()
{
    std::cout << "*** ZOO CONTENTS ***\n";
    for(auto i: boat)
        std::cout << *i << '\n';
    std::cout << '\n';
}

void Ark::add(Animal& a){boat.push_back(&a);}

void Ark::ageArkByMonth()
{
    for(auto i: boat)
    {
        i->ageByMonth();
        int gndr = rand()%2;
        
        if( i->getBreed() )
        {
            switch(i -> getSpecies())
            {
                case CAT:
                {
                    Cat* pCat = new Cat(static_cast<Gender>(gndr), 0);
                    add(*pCat);
                    break;
                }
                case DOG:
                {
                    Dog* pDog = new Dog(static_cast<Gender>(gndr), 0);
                    add(*pDog);
                    break;
                }
                case GOLDFISH:
                {
                    Goldfish* pGoldfish = new Goldfish(static_cast<Gender>(gndr), 0);
                    add(*pGoldfish);
                    break;
                }
                case SHARK:
                {
                    Shark* pShark = new Shark(static_cast<Gender>(gndr), 0);
                    add(*pShark);
                    break;
                }
                case EAGLE:
                {
                    Eagle* pEagle = new Eagle(static_cast<Gender>(gndr), 0);
                    add(*pEagle);
                    break;
                }
                case PARAKEET:
                {
                    Parakeet* pParakeet = new Parakeet(static_cast<Gender>(gndr), 0);
                    add(*pParakeet);
                    break;
                }
                default:
                    std::cout << "No such beast\n";
            }
        }
    }
}

int main()
{
    Cat cat0(MALE, 10), cat1(FEMALE,11);
    Dog dog0(FEMALE,10), dog1(MALE,10);
    Goldfish goldfish0(FEMALE, 5), goldfish1(MALE,4);
    Shark shark0(MALE,6), shark1(FEMALE,6);
    Eagle eagle0(FEMALE,7), eagle1(MALE,10);
    Parakeet parakeet0(FEMALE,8),parakeet1(FEMALE,6);
    
    Ark noah;
    
    noah.add(cat0);
    noah.add(cat1);
    noah.add(dog0);
    noah.add(dog1);
    noah.add(goldfish0);
    noah.add(goldfish1);
    noah.add(shark0);
    noah.add(shark1);
    noah.add(eagle0);
    noah.add(eagle1);
    noah.add(parakeet0);
    noah.add(parakeet1);
    
    noah.display();
    
    for(int i = 0; i < 6; i++)
    {
        std::cout << "MONTH: " << i << '\n';
        noah.ageArkByMonth();
        noah.display();
    }
    
    return 0;
}


animal_constants.h
1
2
3
4
5
6
7
8
9
10
#include <string>

enum Gender:int{MALE, FEMALE};
std::string Gender_name[]{"male", "female"};

enum Species:int{CAT,DOG,GOLDFISH,SHARK,EAGLE,PARAKEET};
std::string Species_name[]{"cat","dog","goldfish","shark","eagle","parakeet"};

enum Cycle:int{MAMMAL,FISH,BIRD};
int Cycle_time[]{12,6,9};


*** ZOO CONTENTS ***
#  0 cat        male    12 10 0
#  1 cat        female  12 11 0
#  2 dog        female  12 10 0
#  3 dog        male    12 10 0
#  4 goldfish   female   6  5 0
#  5 goldfish   male     6  4 0
#  6 shark      male     6  6 0
#  7 shark      female   6  6 1
#  8 eagle      female   9  7 0
#  9 eagle      male     9 10 0
# 10 parakeet   female   9  8 0
# 11 parakeet   female   9  6 0

MONTH: 0
*** ZOO CONTENTS ***
#  0 cat        male    12 11 0
#  1 cat        female  12 12 1
#  2 dog        female  12 11 0
#  3 dog        male    12 11 0
#  4 goldfish   female   6  6 1
#  5 goldfish   male     6  5 0
#  6 shark      male     6  7 0
#  7 shark      female   6  7 0
#  8 eagle      female   9  8 0
#  9 eagle      male     9 11 0
# 10 parakeet   female   9  9 1
# 11 parakeet   female   9  7 0
# 13 cat        male    12  0 0
# 14 goldfish   male     6  0 0
# 15 parakeet   female   9  0 0

MONTH: 1
*** ZOO CONTENTS ***
#  0 cat        male    12 12 0
#  1 cat        female  12 13 0
#  2 dog        female  12 12 1
#  3 dog        male    12 12 0
#  4 goldfish   female   6  7 0
#  5 goldfish   male     6  6 0
#  6 shark      male     6  8 0
#  7 shark      female   6  8 0
#  8 eagle      female   9  9 1
#  9 eagle      male     9 12 0
# 10 parakeet   female   9 10 0
# 11 parakeet   female   9  8 0
# 13 cat        male    12  1 0
# 14 goldfish   male     6  1 0
# 15 parakeet   female   9  1 0
# 16 dog        male    12  0 0
# 17 eagle      male     9  0 0

MONTH: 2
*** ZOO CONTENTS ***
#  0 cat        male    12 13 0
#  1 cat        female  12 14 0
#  2 dog        female  12 13 0
#  3 dog        male    12 13 0
#  4 goldfish   female   6  8 0
#  5 goldfish   male     6  7 0
#  6 shark      male     6  9 0
#  7 shark      female   6  9 0
#  8 eagle      female   9 10 0
#  9 eagle      male     9 13 0
# 10 parakeet   female   9 11 0
# 11 parakeet   female   9  9 1
# 13 cat        male    12  2 0
# 14 goldfish   male     6  2 0
# 15 parakeet   female   9  2 0
# 16 dog        male    12  1 0
# 17 eagle      male     9  1 0
# 18 parakeet   female   9  0 0

MONTH: 3
*** ZOO CONTENTS ***
#  0 cat        male    12 14 0
#  1 cat        female  12 15 0
#  2 dog        female  12 14 0
#  3 dog        male    12 14 0
#  4 goldfish   female   6  9 0
#  5 goldfish   male     6  8 0
#  6 shark      male     6 10 0
#  7 shark      female   6 10 0
#  8 eagle      female   9 11 0
#  9 eagle      male     9 14 0
# 10 parakeet   female   9 12 0
# 11 parakeet   female   9 10 0
# 13 cat        male    12  3 0
# 14 goldfish   male     6  3 0
# 15 parakeet   female   9  3 0
# 16 dog        male    12  2 0
# 17 eagle      male     9  2 0
# 18 parakeet   female   9  1 0

MONTH: 4
*** ZOO CONTENTS ***
#  0 cat        male    12 15 0
#  1 cat        female  12 16 0
#  2 dog        female  12 15 0
#  3 dog        male    12 15 0
#  4 goldfish   female   6 10 0
#  5 goldfish   male     6  9 0
#  6 shark      male     6 11 0
#  7 shark      female   6 11 0
#  8 eagle      female   9 12 0
#  9 eagle      male     9 15 0
# 10 parakeet   female   9 13 0
# 11 parakeet   female   9 11 0
# 13 cat        male    12  4 0
# 14 goldfish   male     6  4 0
# 15 parakeet   female   9  4 0
# 16 dog        male    12  3 0
# 17 eagle      male     9  3 0
# 18 parakeet   female   9  2 0

MONTH: 5
*** ZOO CONTENTS ***
#  0 cat        male    12 16 0
#  1 cat        female  12 17 0
#  2 dog        female  12 16 0
#  3 dog        male    12 16 0
#  4 goldfish   female   6 11 0
#  5 goldfish   male     6 10 0
#  6 shark      male     6 12 0
#  7 shark      female   6 12 1
#  8 eagle      female   9 13 0
#  9 eagle      male     9 16 0
# 10 parakeet   female   9 14 0
# 11 parakeet   female   9 12 0
# 13 cat        male    12  5 0
# 14 goldfish   male     6  5 0
# 15 parakeet   female   9  5 0
# 16 dog        male    12  4 0
# 17 eagle      male     9  4 0
# 18 parakeet   female   9  3 0
# 19 shark      male     6  0 0

Program ended with exit code: 0
I appreciate all of the additional help but I actually completed the project yesterday. I don't want you all to waste any more of your time :).
Have no fear! My time spent has been for self interest to see if the Factory pattern can be applied, so no waste of time for me :)

Interestingly, as with everything, cats can be skinned in many ways, and I just this minute found a reference at Stanford.
http://www-cs-students.stanford.edu/~wolfe/cpp/assign.html


Topic archived. No new replies allowed.
Pages: 12