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
|
#include <iostream>
#include <cstdlib>
#include <limits>
#include <ctime>
using namespace std;
class cBunny{
public:
string bName;
string bSex;
string bColor;
int bAge;
cBunny();
};
cBunny::cBunny() {
string names[] = {"mutant", "spider", "nuclear","vampire","werewolf","racoon","midget","rabbies","furry","Prof"};
const int count = (sizeof(names) / sizeof(*names));
int j=(rand()%count);
int k=(rand()%count);
bName=names[j]+"_"+names[k]+"_"+"bunny";
int g=(rand()%2);
if (g==0){bSex="Female";}
else{bSex="Male";}
string colors[] = {"Brown", "Black", "Spotted", "White","Red"};
const int count2 = (sizeof(colors) / sizeof(*colors));
int n=(rand()%count2);
bColor=colors[n];
bAge=0;
}
int main ()
{
srand(time(NULL));
const int m=5;
cBunny oBunny[m];
cout<< "There are " <<" "<<m<<" "<< "Bunny's created!" <<endl ;
cout<<"---------------------------------------------------"<<endl;
for(int c=0; c<m;c++){
cout<< oBunny[c].bName<<endl;
cout<< oBunny[c].bSex<<endl;
cout<< oBunny[c].bColor<<endl;
cout<< oBunny[c].bAge<<endl;
cout<<endl;
}
cout<<"-------------------------------------------------------------"<<endl;
int turn=0;
int a=m;
while(turn<10){
for(int b=0; b<m;b++){
cout<< oBunny[b].bName;
oBunny[b].bAge=oBunny[b].bAge+1;
cout<<" "<< "is" <<" "<< oBunny[b].bAge<<" "<<"Year's old!" <<endl;
cout<<endl;
}
cout<<"New bunny created!"<<endl;
cout<<"-----------------------------------------"<<endl;
a=a+1;
cout<<a;
// /*
// cBunny* oBunny = new cBunny[a]; //here i want to create an new object and add it to the existing array of bunny's
// /*
// oBunny[a] = new cBunny();
// cout<< oBunny[a].bName<<endl;
// cout<< oBunny[a].bSex<<endl;
// cout<< oBunny[a].bColor<<endl;
// cout<< oBunny[a].bAge<<endl;//*/
cout<<endl;
cout<<"-----------------------------------------"<<endl;
turn++;
cout<<"---------------------- End of"<<" "<<turn<<" "<<"Turn!-------------------------"<<endl;
}
int i;
cin>> i;
return 0;
}
|