Bunny Graduation (Long Post)

Here is the project I'm working on. It's mildly entertaining, so I thought I'd pick it up: (I don't know what linked lists are yet) or file input or output.

Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
arrays
pseudo random number generation
strings & string functions
functions
structures/classes
enumerated data
file input/output
pointers
sorting
linked lists
advanced classes

Write a program that creates a linked list of bunny objects.
Each bunny object must have
Sex: Male, Female (random at creation 50/50)
color: white, brown, black, spotted
age : 0-10 (years old)
Name : randomly chosen at creation from a list of bunny names.
radioactive_mutant_vampire_bunny: true/false (decided at time of bunny creation 2% chance of true)

At program initialization 5 bunnies must be created and given random colors.
Each turn afterwards the bunnies age 1 year.
So long as there is at least one male age 2 or older, for each female bunny in the list age 2 or older;
a new bunny is created each turn. (i.e. if there was 1 adult male and 3 adult female bunnies, three new bunnies would be born each turn)
New bunnies born should be the same color as their mother.
If a bunny becomes older than 10 years old, it dies.
If a radioactive mutant vampire bunny is born then each turn it will change exactly one non radioactive bunny into a radioactive vampire bunny.
(if there are two radioactive mutant vampire bunnies two bunnies will be changed each turn and so on...)
Radioactive vampire bunnies are excluded from regular breeding and do not count as adult bunnies.
Radioactive vampire bunnies do not die until they reach age 50.
The program should print a list of all the bunnies in the colony each turn along w/ all the bunnies details, sorted by age.
The program should also output each turns events such as
"Bunny Thumper was born!
Bunny Fufu was born!
Radioactive Mutant Vampire Bunny Darth Maul was born!
Bunny Julius Caesar died!
The program should write all screen output to a file.
When all the bunnies have died the program terminates.
If the bunny population exceeds 1000 a food shortage must occur killing exactly half of the bunnies (randomly chosen)



********************************Header**********************************

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

#ifndef BUNNY_H
#define BUNNY_H

#include <iostream>
#include <string>
#include <ctime> 
using namespace std;

class Bunny
{
	static const int  POSSIBLE_NAMES = 5;
	static const int  POSSIBLE_COLORS = 4;

	static const string possibleNames[ POSSIBLE_NAMES ];
	static const string possibleColors[ POSSIBLE_COLORS ];

public:
	Bunny();

	void setSex( void );
	char getSex() const;

	void setColor( void );
	string getColor() const;

	void setAge( void );
	int getAge() const;

	void setName( void );
	string getName() const;

	void printBunny() const;

private:
	char sex;
	string color;
	int age;
	string name;

	bool radioactive_mutant_vampire_bunny;
};

#endif 



****************************************Bunny.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
67
#include "Bunny.h"

const string Bunny::possibleNames[ POSSIBLE_NAMES ] = {
	"fredrick", "molly", "luke", "stacy", "bill" };

const string Bunny::possibleColors[ POSSIBLE_COLORS ] = {
	"white", "brown", "black", "spotted" };

Bunny::Bunny()
{
	srand( time( 0 ) );

	setSex();
	setColor();
	setAge();
	setName();
}

void Bunny::setSex()
{
	int randomNumber = 1 + rand() % 2;

	( randomNumber == 1 ) ? sex = 'm' : sex = 'f';
}

char Bunny::getSex() const
{
	return sex;
}

void Bunny::setColor()
{
	color = possibleColors[ 0 + rand() % POSSIBLE_COLORS ];
}

string Bunny::getColor() const
{
	return color;
}

void Bunny::setAge()
{
	age = 0;
}

int Bunny::getAge() const
{
	return age;
}

void Bunny::setName()
{
	name = possibleNames[ 0 + rand() % POSSIBLE_NAMES ];
}

string Bunny::getName() const
{
	return name;
}

void Bunny::printBunny() const
{
	cout << "Name: " << getName() << endl;
	cout << "Sex: " << getSex() << endl;
	cout << "Color: " << getColor() << endl;
	cout << "Age: " << getAge() << endl;
}



************************Bunny Graduation**********************************

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
#include "Bunny.h"
#include <vector>
using namespace std;

int main()
{

	vector< Bunny > colony;

	cout << "Welcome to Bunny Graduation!" << endl << endl;

	for( int i = 0; i < 5; ++i )
	{
		colony.push_back( Bunny() );
	}

	for( int i = 0; i < 5; ++i )
	{
		colony[ i ].printBunny();
		cout << endl;
	}

	return 0;
}

	

	



The output I get from this is located here: http://i1263.photobucket.com/albums/ii623/AaronVienneau/Output_zpscfc372fd.png

As you can see all of the bunnies have the same information. This is probably due to the random number seeding I have going on in the constructor for the bunny, but I'm not exactly sure/How to fix it.

I want the bunnies to each have a randomly generated name, sex and color and not pseudo random or, in this case, all the same.

I'm sure you have a million other things you'd like to correct in my code so any other ideas, suggestions would be great. Thanks.
Last edited on
Topic archived. No new replies allowed.