diff --git a/Zoo.cpp b/Zoo.cpp index b204b69..ebf0a8e 100644 --- a/Zoo.cpp +++ b/Zoo.cpp @@ -26,25 +26,23 @@ void Zoo::setDay(int d){ day = d; } -void Zoo::play() { - - std::cout << "Welcome to the Zoo! Now you run this Fantastic Zoo." << std::endl; - std::cout << "First, you need to buy animals. You can buy three animals: Tiger, Penguin, and Turtle." << std::endl; - std::cout << "You can only buy 1 or 2 per animals this first day with the basic given money, $100,000" << std::endl; - std::cout << "You need to pay $10,000 for tiger, $1,000 for Penguin, and $100 for Turtle." << std::endl; - std::cout << "You need to feed those animals everyday. The basic food cost is $10 per day." << std::endl; - std::cout << "The tiger needs 5 times more than the basic food cost, and the turtle only needs half of that cost." - << std::endl; - std::cout << "Yes, it's too much cost, But don't worry. Those animals make money for you everyday" << std::endl; - std::cout << "Tiger makes 20% of its cost, Penguin makes 10% of its cost, and turtle makes 5% of its cost" - << std::endl; - std::cout << std::endl; +void Zoo::play(){ + + std::cout<<"Welcome to the Zoo! Now you run this Fantastic Zoo."<> fBuyTi; numOfTi = inputVal(fBuyTi); - if (!(numOfTi == 1 || numOfTi == 2)) { + if(!(numOfTi ==1 || numOfTi ==2)) { - do { + do{ std::cin.clear(); std::cin.ignore(INT_MAX, '\n'); - std::cout << "Wrong input. You can buy only 1 or 2 Tigers, Please try again: "; + std::cout<<"Wrong input. You can buy only 1 or 2 Tigers, Please try again: "; std::cin >> fBuyTi; numOfTi = inputVal(fBuyTi); - } while (!(numOfTi == 1 || numOfTi == 2)); + }while(!(numOfTi ==1 || numOfTi ==2)); } - for (int i = 0; i < numOfTi; i++) { + for(int i =0; i > fBuyP; numOfPe = inputVal(fBuyP); - if (!(numOfPe == 1 || numOfPe == 2)) { + if(!(numOfPe ==1 || numOfPe ==2)) { - do { + do{ std::cin.clear(); std::cin.ignore(INT_MAX, '\n'); - std::cout << "Wrong input. You can buy only 1 or 2 Penguins, Please try again: "; + std::cout<<"Wrong input. You can buy only 1 or 2 Penguins, Please try again: "; std::cin >> fBuyP; numOfPe = inputVal(fBuyP); - } while (!(numOfPe == 1 || numOfPe == 2)); + }while(!(numOfPe ==1 || numOfPe ==2)); } - for (int i = 0; i < numOfPe; i++) { + for(int i =0; i > fBuyTu; + std::cout<<"How many Turtles do you want to buy? Choose 1 or 2: "; + std::cin>>fBuyTu; numOfTu = inputVal(fBuyTu); - if (!(numOfTu == 1 || numOfTu == 2)) { + if(!(numOfTu ==1 || numOfTu ==2)) { - do { + do{ std::cin.clear(); std::cin.ignore(INT_MAX, '\n'); - std::cout << "Wrong input. You can buy only 1 or 2 Turtles, Please try again: "; - std::cin >> fBuyTu; + std::cout<<"Wrong input. You can buy only 1 or 2 Turtles, Please try again: "; + std::cin>>fBuyTu; numOfTu = inputVal(fBuyTu); - } while (!(numOfTu == 1 || numOfTu == 2)); + }while(!(numOfTu ==1 || numOfTu ==2)); } - for (int i = 0; i < numOfTu; i++) { + for(int i =0; i dist(1, 3); + std::uniform_int_distribution dist(1, 3); event = dist(mt); - std::cout << "Today's event is: " << event << std::endl; + std::cout<<"Today's event is: "< dist2(0, numOfAni - 1); + std::uniform_int_distribution dist2(0,numOfAni-1); whoSick = dist2(mt); // A Tiger gets sick and remove - if (whoSick < numOfTi) { + if(whoSick < numOfTi) { - std::cout << "Your Tiger number " << whoSick + 1 << " got sick and died. So sorry!" << std::endl; + std::cout<<"Your Tiger number "<= numOfTi && whoSick < numOfTi + numOfPe) { + //A Penguin get sick and remove + else if(whoSick>= numOfTi && whoSick < numOfTi+numOfPe) { - numOfPe -= 1; + numOfPe -=1; //arrayOfPe[whoSick-numOfTi]; - int sickP = whoSick - numOfTi; + int sickP= whoSick -numOfTi; - std::cout << "Your Penguin number " << sickP << " got sick and died. So sorry" << std::endl; + std::cout<<"Your Penguin number "<= numOfTi+numOfPe && whoSick < numOfAni { - numOfTu -= 1; - //arrayOfTur[whoSick -(numOfTi + numOfPe)]; - int sickTu = whoSick - (numOfTi + numOfPe); - std::cout << "Your Turtle number " << sickTu << " got sick and died. So sorry" << std::endl; + numOfTu -=1; + //arrayOfTur[whoSick -(numOfTi + numOfPe)]; + int sickTu = whoSick -(numOfTi + numOfPe); + std::cout<<"Your Turtle number "< dist3(250, 500); - bonus = dist3(mt); - std::cout << "Your today bonus is " << bonus * numOfTi << std::endl; - bonus = (bonus * numOfTi); //bonus * number of tiger + std::uniform_int_distribution dist3(250, 500); + bonus= dist3(mt); + std::cout<<"Your today bonus is "< dist5(1, 3); - pickType = dist5(mt); + int * allAnimal= new int [numOfAni]; - std::cout<<"Now Today's event is baby and the animal number is: "<=3){ + numAuPen+=1; + } + } + std::cout<<"Number of Adult penguins: "<=3) { + adultPenguin[j] =i; + j++; + } + } - std::cout<<"Your tiger is gonna have a baby!"<= 3) { - adult = true; - numOfATig += 1; - } - } - int adultTig[numOfATig]; + std::cout<<"Adult Penguin: "<= 3) { - adultTig[i]; + std::uniform_int_distribution dist5(1, 3); + who = dist5(mt); + + //A Tiger has a baby. + if(who < numOfTi) { + std::cout<<"Your tiger has a baby. Congratulations!"<= roomForTi) { + Tiger *temp_ti = new Tiger[roomForTi*2]; + + for(int i=0; i dist6(0, numOfATig - 1); - pickTiger = dist6(mt); - chosenTig = adultTig[pickTiger]; - //Updates the baby record to the tiger who has a baby - arrayOfTi[chosenTig].setNumOfBabies(arrayOfTi[chosenTig].getNumOfBabies() + 1); - numOfTi += 1; - //Resize the array in case the number of tiger is going to be bigger that the size. - if (numOfTi >= roomForTi) { - Tiger *temp_ti = new Tiger[roomForTi * 2]; - - for (int i = 0; i < roomForTi * 2; i++) { - temp_ti[i] = Tiger(0, 0.00, 0, 0.00, 0.00); - } - - for (int i = 0; i < roomForTi; i++) { - temp_ti[i] = arrayOfTi[i]; - } - roomForTi *= 2; - delete[] arrayOfTi; - arrayOfTi = temp_ti; + for(int i=0; i < roomForTi ; i++){ + temp_ti[i] = arrayOfTi[i]; } - //Add the baby at the end of the array. - arrayOfTi[numOfTi - 1] = Tiger(0, tigCost, 0, tiger.getBaseFoodCost(), tiger.getPayoff()); - } else //There is no adult - { - std::cout<<"I'm sorry you don't have adult Tiger. Let's check the Penguin!"<= 3) { - adult = true; - numOfAPen += 1; + //A penguin has 5 babies. + else if(who>= numOfTi && who < numOfTi+numOfPe) { + + std::cout<<"Your penguin has 5 babies. Congratulations!"<= roomForPe) { + Penguin *temp_pe = new Penguin[roomForPe*2]; + + for(int i=0; i= 3) { - adultPen[i]; + for(int i=0; i < roomForPe ; i++){ + temp_pe[i] = arrayOfPe[i]; } + roomForPe *=2; + delete [] arrayOfPe; + arrayOfPe = temp_pe; } - if (adult) { - std::cout<<"You have adult Penguin"< dist7(0, numOfAPen - 1); - pickPenguin = dist7(mt); - chosenPen = adultPen[pickPenguin]; - - //Updates the baby record to the penguin who has 5 babies - arrayOfPe[chosenPen].setNumOfBabies(arrayOfPe[chosenPen].getNumOfBabies() + 1); - numOfPe += 5; - //Resize the array in case the number of tiger is going to be bigger that the size. - - if (numOfPe >= roomForPe) { - Penguin *temp_pe = new Penguin[roomForPe * 2]; - - for (int i = 0; i < roomForPe * 2; i++) { - temp_pe[i] = Penguin(0, 0.00, 0, 0.00, 0.00); - } - - for (int i = 0; i < roomForPe; i++) { - temp_pe[i] = arrayOfPe[i]; - } - roomForPe *= 2; - delete[] arrayOfPe; - arrayOfPe = temp_pe; - } - //Adds the penguin babies to the end of the array of Penguin. - for (int i = 0; i < 5; i++) { - arrayOfPe[numOfPe - 5 + i] = Penguin(0, penCost, 0, penguin.getBaseFoodCost(), - penguin.getPayoff()); - } - } else //There is no adult - { - std::cout<<"I'm sorry you don't have adult Penguin. Let's check the Turtle!"<= numOfTi+numOfPe && whoSick < numOfAni { - std::cout<<"Your Turtle is gonna have babies!"<= 3) { - adult = true; - numOfATur += 1; + std::cout<<"Your Turtle has 10 babies.Congratulations!"<= roomForTu) { + Turtle *temp_tu = new Turtle[roomForTu*2]; + + for(int i=0; i= 3) { - adultTur[i]; + for(int i=0; i < roomForTu ; i++){ + temp_tu[i] = arrayOfTur[i]; } + roomForTu *=2; + delete [] arrayOfTur; + arrayOfTur = temp_tu; } - - if (adult) { - std::cout<<"You have adult turtle"< dist8(0, numOfATur - 1); - pickTurtle = dist8(mt); - chosenTur = adultTur[pickTurtle]; - - //Updates the baby record to the Turtle who has 10 babies - arrayOfTur[chosenTur].setNumOfBabies(arrayOfPe[chosenTur].getNumOfBabies() + 1); - numOfPe += 10; - if (numOfTu >= roomForTu) { - Turtle *temp_tu = new Turtle[roomForTu * 2]; - - for (int i = 0; i < roomForTu * 2; i++) { - temp_tu[i] = Turtle(0, 0.00, 0, 0.00, 0.00); - } - - for (int i = 0; i < roomForTu; i++) { - temp_tu[i] = arrayOfTur[i]; - } - roomForTu *= 2; - delete[] arrayOfTur; - arrayOfTur = temp_tu; - } - //Adds the babies to the array of Turtle. - for (int i = 0; i < 10; i++) { - arrayOfTur[numOfTu - 10 + i] = Turtle(0, turCost, 0, turtle.getBaseFoodCost(), - turtle.getPayoff()); - } - } else { - std::cout << "I'm sorry, but there is no adult animal here. Maybe next time!" << std::endl; + //Adds the babies to the array of Turtle. + for(int i=0; i<10; i++) { + arrayOfTur[numOfTu-10+i] = Turtle(0, turCost, 0, turtle.getBaseFoodCost(), turtle.getPayoff()); } } + + delete [] allAnimal; } - double todayAIncome = - numOfTi * tiger.getPayoff() + numOfPe * penguin.getPayoff() + numOfTu * turtle.getPayoff(); - account = account + bonus + todayAIncome - costPerDay; - std::cout << "Now it's the time to check your balance." << std::endl; - std::cout << "Today's Tiger payoff " << numOfTi * tiger.getPayoff() << std::endl; - std::cout << "The Penguin's payoff " << numOfPe * penguin.getPayoff() << std::endl; - std::cout << "The Turtle's payoff " << numOfTu * turtle.getPayoff() << std::endl; - std::cout << "So, Your total admission fee income is " << todayAIncome << std::endl; - std::cout << "And, today's your bonus income is " << bonus << std::endl; - std::cout << "Now your balance is " << account << std::endl; + double todayAIncome =numOfTi*tiger.getPayoff()+numOfPe*penguin.getPayoff()+numOfTu*turtle.getPayoff(); + account= account + bonus + todayAIncome - costPerDay; + + std::cout<<"Now it's the time to check your balance."<>buyNewOne; + buyNew =inputVal(buyNewOne); + + if(!(buyNew ==1 || buyNew ==2)) { + + do{ + std::cin.clear(); + std::cin.ignore(INT_MAX, '\n'); + std::cout<<"Wrong input. You can only input 1 or 2, Please try again: "; + std::cin>>buyNewOne; + buyNew =inputVal(buyNewOne); + }while(!(buyNew ==1 || buyNew ==2)); + } + if(buyNew==1) { - double buyNewOne; - int buyNew; + double buyChoice; + int buyOneMore; + std::cout + << "So, you want to buy. Good! which animal will you buy; input 1 for Tiger, 2 for Penguin, and 3 for Turtle: "; + std::cin >> buyChoice; + buyOneMore = inputVal(buyChoice); - std::cin.clear(); - std::cin.ignore(INT_MAX, '\n'); - std::cout << "Pretty busy day, right? Now you can buy an adult animal." << std::endl; - std::cout << "Currently, you have " << numOfTi << " Tigers, " << numOfPe << " Penguins, " << numOfTu - << " Turtles" << std::endl; - std::cout << "If you want to buy, input 1, otherwise (it you don't want to buy), click 2: "; - std::cin >> buyNewOne; - buyNew = inputVal(buyNewOne); + if(!(buyOneMore ==1 || buyOneMore ==2 || buyOneMore ==3)) { - if (!(buyNew == 1 || buyNew == 2)) { - - do { + do{ std::cin.clear(); std::cin.ignore(INT_MAX, '\n'); - std::cout << "Wrong input. You can only input 1 or 2, Please try again: "; - std::cin >> buyNewOne; - buyNew = inputVal(buyNewOne); - } while (!(buyNew == 1 || buyNew == 2)); + std::cout<<"Wrong input. You should input 1,2,or 3. Please try again: "; + std::cin >> buyChoice; + buyOneMore = inputVal(buyChoice); + + }while(!(buyOneMore ==1 || buyOneMore ==2 || buyOneMore ==3)); } - if (buyNew == 1) { + if (buyOneMore == 1) { - double buyChoice; - int buyOneMore; - std::cout - << "So, you want to buy. Good! which animal will you buy; input 1 for Tiger, 2 for Penguin, and 3 for Turtle: "; - std::cin >> buyChoice; - buyOneMore = inputVal(buyChoice); + std::cout << "So, you decided to buy a Tiger. Best Choice!" << std::endl; - if (!(buyOneMore == 1 || buyOneMore == 2 || buyOneMore == 3)) { + numOfTi += 1; + if(numOfTi >= roomForTi) { + Tiger *temp_ti = new Tiger[roomForTi*2]; - do { - std::cin.clear(); - std::cin.ignore(INT_MAX, '\n'); - std::cout << "Wrong input. You should input 1,2,or 3. Please try again: "; - std::cin >> buyChoice; - buyOneMore = inputVal(buyChoice); + for(int i=0; i= roomForTi) { - Tiger *temp_ti = new Tiger[roomForTi * 2]; + else if (buyOneMore == 2) { - for (int i = 0; i < roomForTi * 2; i++) { - temp_ti[i] = Tiger(0, 0.00, 0, 0.00, 0.00); - } + std::cout << "So, you decided to buy a Penguin. Fantastic Choice!" << std::endl; + numOfPe += 1; + if(numOfPe >= roomForPe) { + Penguin *temp_pe = new Penguin[roomForPe*2]; - for (int i = 0; i < roomForTi; i++) { - temp_ti[i] = arrayOfTi[i]; - } - delete[] arrayOfTi; - //arrayOfTi[0] = Tiger(0, 0.00, 0, 0.00, 0.00); - arrayOfTi = temp_ti; - //temp_ti[0] = Tiger(0, 0.00, 0, 0.00, 0.00); - roomForTi *= 2; + for(int i=0; i= roomForPe) { - Penguin *temp_pe = new Penguin[roomForPe * 2]; - - for (int i = 0; i < roomForPe * 2; i++) { - temp_pe[i] = Penguin(0, 0.00, 0, 0.00, 0.00); - } - - for (int i = 0; i < roomForPe; i++) { - temp_pe[i] = arrayOfPe[i]; - } - roomForPe *= 2; - delete[] arrayOfPe; - arrayOfPe = temp_pe; + for(int i=0; i < roomForPe ; i++){ + temp_pe[i] = arrayOfPe[i]; } - arrayOfPe[numOfPe - 1] = Penguin(3, penCost, 0, penguin.getBaseFoodCost(), penguin.getPayoff()); - account -= penCost; - std::cout << "After you buy the penguin, your balance is " << account << std::endl; - - } else // (buyOneMore == 3) - { - std::cout << "So, you decided to buy a Turtle. Beautiful Choice!" << std::endl; - - numOfTu += 1; - if (numOfTu >= roomForTu) { - Turtle *temp_tu = new Turtle[roomForTu * 2]; - - for (int i = 0; i < roomForTu * 2; i++) { - temp_tu[i] = Turtle(0, 0.00, 0, 0.00, 0.00); - } - - for (int i = 0; i < roomForTu; i++) { - temp_tu[i] = arrayOfTur[i]; - } - roomForTu *= 2; - delete[] arrayOfTur; - arrayOfTur = temp_tu; - } + roomForPe *=2; + delete [] arrayOfPe; + arrayOfPe = temp_pe; - arrayOfTur[numOfTu - 1] = Turtle(3, turCost, 0, turtle.getBaseFoodCost(), turtle.getPayoff()); - account -= turCost; - std::cout << "After you buy the turtle, your balance is " << account << std::endl; } + arrayOfPe[numOfPe-1] = Penguin(3, penCost, 0, penguin.getBaseFoodCost(), penguin.getPayoff()); + account -= penCost; + std::cout<<"After you buy the penguin, your balance is "<= roomForTu) { + Turtle *temp_tu = new Turtle[roomForTu*2]; - std::cout << "The Penguin is: " << std::endl; - for (int i = 0; i < roomForPe; i++) { - std::cout << "number " << i + 1 << " : " << arrayOfPe[i].getAge() << ", " << arrayOfPe[i].getCost() - << std::endl; - } - std::cout << "The Turtle is: " << std::endl; - for (int i = 0; i < roomForTu; i++) { - std::cout << "number " << i + 1 << " : " << arrayOfTur[i].getAge() << " , " << arrayOfTur[i].getCost() - << std::endl; - } + for(int i=0; i> playAgain; - std::cout << std::endl; + for(int i=0; i < roomForTu ; i++){ + temp_tu[i] = arrayOfTur[i]; + } + roomForTu *=2; + delete [] arrayOfTur; + arrayOfTur = temp_tu; + } - }while (playAgain == 1 && account > 0); + arrayOfTur[numOfTu-1] = Turtle(3, turCost, 0, turtle.getBaseFoodCost(), turtle.getPayoff()); + account -= turCost; + std::cout<<"After you buy the turtle, your balance is "<>playAgain; + std::cout< 0); + if (account < 0){ + std::cout<<"I'm sorry, but your account is empty. Play next time. Good buy!"<