From 1f791e58ac8cb91b1624dd0ea344a081189a3823 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:35:27 -0800 Subject: [PATCH 01/14] completes DArray classm but --- Zoo.cpp | 646 -------------------------------------------------------- 1 file changed, 646 deletions(-) delete mode 100644 Zoo.cpp diff --git a/Zoo.cpp b/Zoo.cpp deleted file mode 100644 index b204b69..0000000 --- a/Zoo.cpp +++ /dev/null @@ -1,646 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Zoo.cpp file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - -#include "Zoo.h" -#include "Animal.h" -#include "inputVal.h" -#include -#include -#include "Tiger.h" -#include "Penguin.h" -#include "Turtle.h" - - -Zoo::Zoo()=default; -Zoo::~Zoo()=default; - -int Zoo::getDay(){ - return this -> day; -} -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; - - double account = 100000.00; - - Animal animal; - //animal.setBaseFoodCost(10.00); - // double baseCost = animal.getBaseFoodCost(); - Tiger tiger; - Penguin penguin; - Turtle turtle; - double baseCost = 10.00; - tiger.setCost(10000.00); - double tigCost = tiger.getCost(); - penguin.setCost(1000.00); - double penCost = penguin.getCost(); - turtle.setCost(100.00); - double turCost = turtle.getCost(); - - tiger.setBaseFoodCost(baseCost * 5); - penguin.setBaseFoodCost(baseCost); - turtle.setBaseFoodCost(baseCost * 0.5); - - tiger.setPayoff(tigCost * 0.2); - penguin.setPayoff(penCost * 0.1); - turtle.setPayoff(turCost * 0.05); - - int roomForTi = 10; - //Tiger * arrayOfTi = new Tiger(); - Tiger *arrayOfTi = new Tiger[roomForTi]; - - for (int i = 0; i < roomForTi; i++) { - arrayOfTi[i] = Tiger(0, 0.00, 0, 0.00, 0.00); - } - - int roomForPe = 10; - Penguin *arrayOfPe = new Penguin[roomForPe]; - - for (int i = 0; i < roomForPe; i++) { - - arrayOfPe[i] = Penguin(0, 0.00, 0, 0.00, 0.00); - } - - int roomForTu = 10; - Turtle *arrayOfTur = new Turtle[roomForTu]; - - for (int i = 0; i < roomForTu; i++) { - - arrayOfTur[i] = Turtle(0, 0.00, 0, 0.00, 0.00); - } - - double fBuyTi; - int numOfTi = 0; - double fBuyP; - int numOfPe = 0; - double fBuyTu; - int numOfTu = 0; - int playAgain; - - - //std::cin.clear(); - //std::cin.ignore(INT_MAX, '\n'); - std::cout << std::endl; - std::cout << "Now, did you decide how many each animals buy" << std::endl; - std::cout << "How many tigers do you want? input just 1 or 2: "; - std::cin >> fBuyTi; - numOfTi = inputVal(fBuyTi); - - if (!(numOfTi == 1 || numOfTi == 2)) { - - 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::cin >> fBuyTi; - numOfTi = inputVal(fBuyTi); - } while (!(numOfTi == 1 || numOfTi == 2)); - } - - for (int i = 0; i < numOfTi; i++) { - - arrayOfTi[i] = Tiger(0, tigCost, 0, tiger.getBaseFoodCost(), tiger.getPayoff()); - } - account -= (numOfTi * tigCost); - - std::cin.clear(); - std::cin.ignore(INT_MAX, '\n'); - std::cout << "How many Penguins are you willing to buy? choose 1 or 2: "; - std::cin >> fBuyP; - numOfPe = inputVal(fBuyP); - - if (!(numOfPe == 1 || numOfPe == 2)) { - - 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::cin >> fBuyP; - numOfPe = inputVal(fBuyP); - } while (!(numOfPe == 1 || numOfPe == 2)); - } - - for (int i = 0; i < numOfPe; i++) { - - arrayOfPe[i] = Penguin(0, penCost, 0, penguin.getBaseFoodCost(), penguin.getPayoff()); - } - - account -= (numOfPe * penCost); - - std::cin.clear(); - std::cin.ignore(INT_MAX, '\n'); - 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)) { - - 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; - numOfTu = inputVal(fBuyTu); - } while (!(numOfTu == 1 || numOfTu == 2)); - } - - for (int i = 0; i < numOfTu; i++) { - - arrayOfTur[i] = Turtle(0, turCost, 0, turtle.getBaseFoodCost(), turtle.getPayoff()); - } - account -= (numOfTu * turCost); - - std::cout << "After the purchase, your account balance is " << account << std::endl; - - do { - setDay(getDay() + 1); - std::cout << "The day: " << day << std::endl; - - for (int i = 0; i < numOfTi; i++) { - - arrayOfTi[i].setAge(arrayOfTi[i].getAge() + 1); - } - - for (int i = 0; i < numOfPe; i++) { - - arrayOfPe[i].setAge(arrayOfPe[i].getAge() + 1); - } - - for (int i = 0; i < numOfTu; i++) { - - arrayOfTur[i].setAge(arrayOfTur[i].getAge() + 1); - } - - double costPerDay; - //Feed the animals and deduct the cost from the account. - costPerDay = (numOfTi * baseCost * 5) + (numOfPe * baseCost) + (numOfTu * baseCost * 0.5); - std::cout << "Today's feeding cost is " << costPerDay << std::endl; - - //Random Event! - int event; - double bonus = 0.00; - - std::random_device ran; - std::mt19937 mt(ran()); - std::uniform_int_distribution dist(1, 3); - event = dist(mt); - - std::cout << "Today's event is: " << event << std::endl; - - //Sickness occurs and one animal that is chosen will die. - if (event == 1) { - //another random needed to pick one animal. - int numOfAni = numOfTi + numOfPe + numOfTu; - int whoSick; - - int *allAnimal = new int[numOfAni]; - - for (int i = 0; i < numOfTi; i++) { - - allAnimal[i] = i; - } - for (int i = numOfTi; i < numOfTi + numOfPe; i++) { - - allAnimal[i] = i; - } - for (int i = numOfTi + numOfPe; i < numOfAni; i++) { - - allAnimal[i] = i; - } - - std::uniform_int_distribution dist2(0, numOfAni - 1); - whoSick = dist2(mt); - - // A Tiger gets sick and remove - if (whoSick < numOfTi) { - - std::cout << "Your Tiger number " << whoSick + 1 << " got sick and died. So sorry!" << std::endl; - numOfTi -= 1; - - for (int j = whoSick; j < roomForTi; j++) { - - Tiger temp = arrayOfTi[j]; - arrayOfTi[j] = arrayOfTi[j + 1]; - arrayOfTi[j + 1] = temp; - } - arrayOfTi[roomForTi - 1] = Tiger(0, 0.00, 0, 0.00, 0.00); - } - //A Penguin get sick and remove - else if (whoSick >= numOfTi && whoSick < numOfTi + numOfPe) { - - numOfPe -= 1; - //arrayOfPe[whoSick-numOfTi]; - int sickP = whoSick - numOfTi; - - std::cout << "Your Penguin number " << sickP << " got sick and died. So sorry" << std::endl; - - for (int j = sickP; j < roomForPe; j++) { - - Penguin temp = arrayOfPe[j]; - arrayOfPe[j] = arrayOfPe[j + 1]; - arrayOfPe[j + 1] = temp; - } - arrayOfPe[roomForPe - 1] = Penguin(0, 0.00, 0, 0.00, 0.00); - - } - //A turtle get sick and remove - else // whoSick >= 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; - - for (int j = sickTu; j < roomForTu; j++) { - - Turtle temp = arrayOfTur[j]; - arrayOfTur[j] = arrayOfTur[j + 1]; - arrayOfTur[j + 1] = temp; - } - arrayOfTur[roomForTu - 1] = Turtle(0, 0.00, 0, 0.00, 0.00); - } - - delete[] allAnimal; - } - - // A boom in zoo attendance occurs - else if (event == 2) { - //another random need to set the bonus - - std::uniform_int_distribution dist3(250, 500); - bonus = dist3(mt); - std::cout << "Your today bonus is " << bonus * numOfTi << std::endl; - bonus = (bonus * numOfTi); //bonus * number of tiger - } - - //This event gives babies to the animal - else //event ==3 - { - int pickType; - - std::uniform_int_distribution dist5(1, 3); - pickType = dist5(mt); - - std::cout<<"Now Today's event is baby and the animal number is: "<= 3) { - adult = true; - numOfATig += 1; - } - } - int adultTig[numOfATig]; - - for (int i = 0; i < numOfTi; i++) { - if (arrayOfTi[i].getAge() >= 3) { - adultTig[i]; - } - } - - if (adult) { - std::cout<<"You have adult Penguin"< 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; - } - //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; - } - } - int adultPen[numOfAPen]; - - for (int i = 0; i < numOfTi; i++) { - if (arrayOfPe[i].getAge() >= 3) { - adultPen[i]; - } - } - - 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!"<= 3) { - adult = true; - numOfATur += 1; - } - } - int adultTur[numOfATur]; - - for (int i = 0; i < numOfTu; i++) { - if (arrayOfTur[i].getAge() >= 3) { - adultTur[i]; - } - } - - 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; - } - } - } - 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 buyNewOne; - int buyNew; - - 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 (!(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 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); - - if (!(buyOneMore == 1 || buyOneMore == 2 || buyOneMore == 3)) { - - 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); - - } while (!(buyOneMore == 1 || buyOneMore == 2 || buyOneMore == 3)); - } - - if (buyOneMore == 1) { - - std::cout << "So, you decided to buy a Tiger. Best Choice!" << std::endl; - - numOfTi += 1; - 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]; - } - 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; - } - arrayOfTi[numOfTi - 1] = Tiger(3, tigCost, 0, tiger.getBaseFoodCost(), tiger.getPayoff()); - account -= tigCost; - std::cout << "After you buy the tiger, your balance is " << account << std::endl; - } else if (buyOneMore == 2) { - - 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 < 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; - - } - 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; - } - - 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; - } - - std::cout << "After the purchase now you have " << numOfTi << " Tigers, " << numOfPe << " Penguins, " - << numOfTu << " Turtles" << std::endl; - } - - else if (buyNew == 2) { - std::cout << "so you don't want to buy more. That's fine." << std::endl; - } - - std::cout << "The Tiger is: " << std::endl; - for (int i = 0; i < roomForTi; i++) { - std::cout << "number " << i + 1 << " : " << arrayOfTi[i].getAge() << ", " << arrayOfTi[i].getCost() - << std::endl; - } - - 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; - } - - std::cin.clear(); - std::cin.ignore(INT_MAX, '\n'); - std::cout << "If you want to play again, input 1. Otherwise, click any keys! "; - std::cin >> playAgain; - std::cout << std::endl; - - }while (playAgain == 1 && account > 0); - - if (account < 0) { - std::cout << "I'm sorry, but your account is empty. Play next time. Good buy!" << std::endl; - } - delete[] arrayOfTi; - delete[] arrayOfPe; - delete[] arrayOfTur; - - if (playAgain != 1) { - - std::cout << "You want to stop. Good bye! See you again!" << std::endl; - } - -} - From 58b8b0615c58c6e69bc88c551577fb32e9726d81 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:35:51 -0800 Subject: [PATCH 02/14] Delete Animal.cpp --- Animal.cpp | 63 ------------------------------------------------------ 1 file changed, 63 deletions(-) delete mode 100644 Animal.cpp diff --git a/Animal.cpp b/Animal.cpp deleted file mode 100644 index 71c8162..0000000 --- a/Animal.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Animal.cpp file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - - - -#include "Animal.h" -#include - -Animal::Animal()=default; - -Animal::Animal(int age, double cost, int numOfBabies, double baseFoodCost, double payoff){ - this -> age =age; - this -> cost =cost; - this -> numOfBabies = numOfBabies; - this -> baseFoodCost = baseFoodCost; - this -> payoff = payoff; -} -Animal::~Animal()=default; - -int Animal::getAge() { - return this -> age; -} - -void Animal::setAge(int a){ - age = a; -} -double Animal::getCost(){ - return this ->cost; - -} -void Animal::setCost(double co){ - cost = co; - -} -int Animal::getNumOfBabies(){ - return this ->numOfBabies; - -} -void Animal::setNumOfBabies(int babies){ - numOfBabies = babies; - -} -double Animal::getBaseFoodCost(){ - return this -> baseFoodCost; - -} -void Animal::setBaseFoodCost(double fCost){ - baseFoodCost =fCost; - -} -double Animal::getPayoff(){ - return this -> payoff; - -} -void Animal::setPayoff(double pay){ - payoff = pay; - -} From dc360882f4243fd378d35c8fab4a3a5e8f41f7ae Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:01 -0800 Subject: [PATCH 03/14] Delete Animal.h --- Animal.h | 57 -------------------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 Animal.h diff --git a/Animal.h b/Animal.h deleted file mode 100644 index d9bd122..0000000 --- a/Animal.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Animal.h file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - - - -#ifndef ANIMAL_H -#define ANIMAL_H - - -class Animal { - -private: - -protected: - int age; - double cost ; - int numOfBabies; - double baseFoodCost; - double payoff; - -public: - Animal(); - - Animal(int age, double cost, int numOfBabies, double baseFoodCost, double payoff); - virtual ~Animal(); - - int getAge(); - - void setAge(int a); - - double getCost(); - - void setCost(double co); - - int getNumOfBabies(); - - void setNumOfBabies(int Babies); - - double getBaseFoodCost(); - - void setBaseFoodCost(double fCost); - - double getPayoff(); - - void setPayoff(double pay); - - - -}; - - -#endif //PROJECT2_ANIMAL_H From 18267e33d92b8ce91172d48183c8fe0ffa332879 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:08 -0800 Subject: [PATCH 04/14] Delete Penguin.cpp --- Penguin.cpp | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 Penguin.cpp diff --git a/Penguin.cpp b/Penguin.cpp deleted file mode 100644 index babdddb..0000000 --- a/Penguin.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Animal.h file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - - -#include "Penguin.h" - -Penguin::Penguin() =default; -Penguin::~Penguin()=default; - -Penguin::Penguin(int age, double cost, int numOfBabies, double baseFoodCost, double payoff) - :Animal(age, cost, numOfBabies, baseFoodCost, payoff) -{ - -} \ No newline at end of file From 60ca2564338354ec8c8a759704acb7eb4fe85bfb Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:15 -0800 Subject: [PATCH 05/14] Delete Penguin.h --- Penguin.h | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 Penguin.h diff --git a/Penguin.h b/Penguin.h deleted file mode 100644 index d1e09f1..0000000 --- a/Penguin.h +++ /dev/null @@ -1,27 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Animal.h file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - -#include "Animal.h" -#ifndef PROJECT2_PENGUIN_H -#define PROJECT2_PENGUIN_H - - -class Penguin: - public Animal -{ -private: - -public: - Penguin(); - ~Penguin() override; - Penguin(int age, double cost, int numOfBabies, double baseFoodCost, double payoff); - -}; - - -#endif //PROJECT2_PENGUIN_H From edb1e0f633718ecd0160e559c65c6c217baabbf6 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:21 -0800 Subject: [PATCH 06/14] Delete Tiger.cpp --- Tiger.cpp | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 Tiger.cpp diff --git a/Tiger.cpp b/Tiger.cpp deleted file mode 100644 index be907f6..0000000 --- a/Tiger.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Animal.h file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - -#include "Tiger.h" - -Tiger::Tiger() =default; - -Tiger::~Tiger()=default; - -Tiger::Tiger(int age, double cost, int numOfBabies, double baseFoodCost, double payoff) - :Animal(age, cost, numOfBabies, baseFoodCost, payoff) - { - -} \ No newline at end of file From d7eed2ad73dde32e5afa81d94d0d3a09ae9227a8 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:28 -0800 Subject: [PATCH 07/14] Delete Tiger.h --- Tiger.h | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 Tiger.h diff --git a/Tiger.h b/Tiger.h deleted file mode 100644 index 4f8284b..0000000 --- a/Tiger.h +++ /dev/null @@ -1,27 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Animal.h file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - -#include "Animal.h" -#ifndef PROJECT2_TIGER_H -#define PROJECT2_TIGER_H - - -class Tiger: - public Animal -{ -private: - -public: - explicit Tiger(); - ~Tiger() override; - Tiger(int age, double cost, int numOfBabies, double baseFoodCost, double payoff); - -}; - - -#endif //PROJECT2_TIGER_H From 46b5e92a5991559d3c732f974a0ddf8f1b6b13f3 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:34 -0800 Subject: [PATCH 08/14] Delete Turtle.cpp --- Turtle.cpp | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 Turtle.cpp diff --git a/Turtle.cpp b/Turtle.cpp deleted file mode 100644 index 476d698..0000000 --- a/Turtle.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Animal.h file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - - -#include "Turtle.h" - -Turtle::Turtle()=default; -Turtle::~Turtle()=default; - -Turtle::Turtle(int age, double cost, int numOfBabies, double baseFoodCost, double payoff) - :Animal(age, cost, numOfBabies, baseFoodCost, payoff) -{ - -} \ No newline at end of file From 1f6dc356b49d65938a420beb3cc317cf68531748 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:41 -0800 Subject: [PATCH 09/14] Delete Turtle.h --- Turtle.h | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 Turtle.h diff --git a/Turtle.h b/Turtle.h deleted file mode 100644 index 74a3b2b..0000000 --- a/Turtle.h +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Animal.h file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - -#include "Animal.h" -#ifndef PROJECT2_TURTLE_H -#define PROJECT2_TURTLE_H - - -#include "Animal.h" - -class Turtle: - public Animal -{ -private: - -public: - Turtle(); - ~Turtle() override; - Turtle(int age, double cost, int numOfBabies, double baseFoodCost, double payoff); -}; - - -#endif //PROJECT2_TURTLE_H From c8d9552c5f5421b97212ad2239379e9a2a89bed2 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:47 -0800 Subject: [PATCH 10/14] Delete inputVal.cpp --- inputVal.cpp | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 inputVal.cpp diff --git a/inputVal.cpp b/inputVal.cpp deleted file mode 100644 index ae1bac4..0000000 --- a/inputVal.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is inputVal.cpp file for CS162 Project2 - * * This function check users' input validation, so if the input is not integer, keeps asking users - * * to input the correct input. - ******************************************************************************************************/ - - -#include "inputVal.h" -#include -#include - - -int inputVal(double in) { - - // Check type validation first using std::cin.fail() - - - if( std::cin.good() && in > 0 && (in - (int)in == 0)) { - return (int)in; - } - - else{ - - do { - //std::cout << "Input" << input << std::endl; - std::cout << "Wrong input! You need to input proper value!" << std::endl; - - std::cin.clear(); - std::cin.ignore(INT_MAX, '\n'); - - std::cout << "Please try again. Input here: " << std::endl; - std::cin >> in; - //decimalCheck(input); - - } while(!(std::cin.good() && in > 0 && (in - (int)in == 0) )); - - } - - return (int)in; -} \ No newline at end of file From 1a1187acd37cd0b3dbd9cc1b1b13276ac947e033 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:53 -0800 Subject: [PATCH 11/14] Delete inputVal.h --- inputVal.h | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 inputVal.h diff --git a/inputVal.h b/inputVal.h deleted file mode 100644 index c1f28a5..0000000 --- a/inputVal.h +++ /dev/null @@ -1,14 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is inputVal.h file for CS162 Project2 - ******************************************************************************************************/ - - -#ifndef PROJECT2_INPUTVAL_H -#define PROJECT2_INPUTVAL_H - -int inputVal(double in); - -#endif //PROJECT2_INPUTVAL_H From 6d1df95c9640bc2be53d32df49488b36a84e54dc Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:36:59 -0800 Subject: [PATCH 12/14] Delete Zoo.h --- Zoo.h | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 Zoo.h diff --git a/Zoo.h b/Zoo.h deleted file mode 100644 index 88be6cf..0000000 --- a/Zoo.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is Zoo.h file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - -#ifndef PROJECT2_ZOO_H -#define PROJECT2_ZOO_H - - -class Zoo { - -private: - - int day = 0; - - -public: - Zoo(); - ~Zoo(); - int getDay(); - void setDay(int d); - void play(); - -}; - - -#endif //PROJECT2_ZOO_H From f109c4b2fc32d40d580a2a52fcb342676b2321e2 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:37:06 -0800 Subject: [PATCH 13/14] Delete main.cpp --- main.cpp | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 main.cpp diff --git a/main.cpp b/main.cpp deleted file mode 100644 index dce981b..0000000 --- a/main.cpp +++ /dev/null @@ -1,22 +0,0 @@ - -/**************************************************************************************************** - * * Program name: CS162 Project2 - * * Author: Taekyoung Kim - * * Date: 01/21/2019 - * * Description: This is main.cpp file for CS162 Project2 - * * This project shows a zoo that has a few animals. We needs inheritance and class...... - ******************************************************************************************************/ - - - - -#include -#include "Zoo.h" - -int main() { - //std::cout << "Hello, World!" << std::endl; - - Zoo zoo; - zoo.play(); - return 0; -} \ No newline at end of file From a4ae6d19a20f95eb157094ba6b0e9705a3e8527e Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:40:08 -0800 Subject: [PATCH 14/14] uploads files uploads after completing DArray class before separating --- Animal.cpp | 63 ++++++++ Animal.h | 57 +++++++ DArray.cpp | 400 ++++++++++++++++++++++++++++++++++++++++++++++++ DArray.h | 48 ++++++ Penguin.cpp | 19 +++ Penguin.h | 27 ++++ Tiger.cpp | 21 +++ Tiger.h | 28 ++++ Turtle.cpp | 19 +++ Turtle.h | 28 ++++ Zoo.cpp | 419 +++++++++++++++++++++++++++++++++++++++++++++++++++ Zoo.h | 40 +++++ inputVal.cpp | 43 ++++++ inputVal.h | 14 ++ main.cpp | 22 +++ 15 files changed, 1248 insertions(+) create mode 100644 Animal.cpp create mode 100644 Animal.h create mode 100644 DArray.cpp create mode 100644 DArray.h create mode 100644 Penguin.cpp create mode 100644 Penguin.h create mode 100644 Tiger.cpp create mode 100644 Tiger.h create mode 100644 Turtle.cpp create mode 100644 Turtle.h create mode 100644 Zoo.cpp create mode 100644 Zoo.h create mode 100644 inputVal.cpp create mode 100644 inputVal.h create mode 100644 main.cpp diff --git a/Animal.cpp b/Animal.cpp new file mode 100644 index 0000000..71c8162 --- /dev/null +++ b/Animal.cpp @@ -0,0 +1,63 @@ +/**************************************************************************************************** + * * Program name: CS162 Project2 + * * Author: Taekyoung Kim + * * Date: 01/21/2019 + * * Description: This is Animal.cpp file for CS162 Project2 + * * This project shows a zoo that has a few animals. We needs inheritance and class...... + ******************************************************************************************************/ + + + +#include "Animal.h" +#include + +Animal::Animal()=default; + +Animal::Animal(int age, double cost, int numOfBabies, double baseFoodCost, double payoff){ + this -> age =age; + this -> cost =cost; + this -> numOfBabies = numOfBabies; + this -> baseFoodCost = baseFoodCost; + this -> payoff = payoff; +} +Animal::~Animal()=default; + +int Animal::getAge() { + return this -> age; +} + +void Animal::setAge(int a){ + age = a; +} +double Animal::getCost(){ + return this ->cost; + +} +void Animal::setCost(double co){ + cost = co; + +} +int Animal::getNumOfBabies(){ + return this ->numOfBabies; + +} +void Animal::setNumOfBabies(int babies){ + numOfBabies = babies; + +} +double Animal::getBaseFoodCost(){ + return this -> baseFoodCost; + +} +void Animal::setBaseFoodCost(double fCost){ + baseFoodCost =fCost; + +} +double Animal::getPayoff(){ + return this -> payoff; + +} +void Animal::setPayoff(double pay){ + payoff = pay; + +} diff --git a/Animal.h b/Animal.h new file mode 100644 index 0000000..d9bd122 --- /dev/null +++ b/Animal.h @@ -0,0 +1,57 @@ +/**************************************************************************************************** + * * Program name: CS162 Project2 + * * Author: Taekyoung Kim + * * Date: 01/21/2019 + * * Description: This is Animal.h file for CS162 Project2 + * * This project shows a zoo that has a few animals. We needs inheritance and class...... + ******************************************************************************************************/ + + + +#ifndef ANIMAL_H +#define ANIMAL_H + + +class Animal { + +private: + +protected: + int age; + double cost ; + int numOfBabies; + double baseFoodCost; + double payoff; + +public: + Animal(); + + Animal(int age, double cost, int numOfBabies, double baseFoodCost, double payoff); + virtual ~Animal(); + + int getAge(); + + void setAge(int a); + + double getCost(); + + void setCost(double co); + + int getNumOfBabies(); + + void setNumOfBabies(int Babies); + + double getBaseFoodCost(); + + void setBaseFoodCost(double fCost); + + double getPayoff(); + + void setPayoff(double pay); + + + +}; + + +#endif //PROJECT2_ANIMAL_H diff --git a/DArray.cpp b/DArray.cpp new file mode 100644 index 0000000..56c453d --- /dev/null +++ b/DArray.cpp @@ -0,0 +1,400 @@ +/**************************************************************************************************** + * * Program name: CS162 Project2 + * * Author: Taekyoung Kim + * * Date: 01/21/2019 + * * Description: This is Zoo.cpp file for CS162 Project2 + * * This project shows a zoo that has a few animals. We needs inheritance and class...... + ******************************************************************************************************/ + + +#include "DArray.h" +#include "Zoo.h" +#include "Animal.h" +#include "Penguin.h" +#include "Turtle.h" +#include "Tiger.h" +#include +#include + + +DArray::DArray() =default; +DArray::~DArray()=default; + +int DArray::getRoomOfTi(){ + return roomOfTi; + +} +void DArray::setRoomOfTi(int ti){ + roomOfTi = ti; + +} +int DArray::getRoomOfPe(){ + return roomOfPe; +} +void DArray::setRoomOfPe(int pe){ + roomOfPe = pe; + +} +int DArray::getRoomOfTu(){ + return roomOfTu; + +} +void DArray::setRoomOfTu(int tu){ + roomOfTu = tu; + +} +void DArray::arrayTiger(Tiger *arr, int roomOfTi){ + + Tiger *temp_ti = new Tiger[roomOfTi * 2]; + + for (int i = 0; i < roomOfTi * 2; i++) { + temp_ti[i] = Tiger(0, 0.00, 0, 0.00, 0.00); + } + + for (int i = 0; i < roomOfTi; i++) { + temp_ti[i] = arr[i]; + } + setRoomOfTi(roomOfTi*2); + // delete[] arr; + // for (int i = 0; i < sizeOfTi * 2; i++) { + // arr[i] = Tiger(0, 0.00, 0, 0.00, 0.00); + // } + + arr = temp_ti; + +} +void DArray::arrayPen(Penguin *arra, int roomOfPe){ + + Penguin *temp_pe = new Penguin[roomOfPe * 2]; + + for (int i = 0; i < roomOfPe * 2; i++) { + temp_pe[i] = Penguin(0, 0.00, 0, 0.00, 0.00); + } + + for (int i = 0; i < roomOfPe; i++) { + temp_pe[i] = arra[i]; + } + setRoomOfPe(roomOfPe*2); + + for (int i = roomOfPe; i < roomOfPe * 2; i++) { + arra[i] = Penguin(0, 0.00, 0, 0.00, 0.00); + } + + arra = temp_pe; + +} +void DArray::arrayTur(Turtle *array, int roomOfTu){ + + Turtle *temp_tu = new Turtle[roomOfTu * 2]; + + for (int i = 0; i < roomOfTu * 2; i++) { + temp_tu[i] = Turtle(0, 0.00, 0, 0.00, 0.00); + } + + for (int i = 0; i < roomOfTu; i++) { + temp_tu[i] = array[i]; + } + + setRoomOfTu(roomOfTu*2); + // delete[] array; + + for (int i = roomOfTu; i < roomOfTu * 2; i++) { + array[i] = Turtle(0, 0.00, 0, 0.00, 0.00); + } + + array = temp_tu; + +} + +void DArray::pickRemove(int &ti, int &pe, int &tu, Tiger *arr, Penguin *arra, Turtle *array) { + + Zoo nyc; + + //int numOfAni = nyc.getNumOfTig()+ nyc.getNumOfPeng()+ nyc.getNumOfTurt(); + int numOfAni = ti + pe + tu; + + std::cout << "Tiger num " << ti << " "; + std::cout << "Penguin num " << pe << " "; + std::cout << "Turtle num " << tu << " " << std::endl; + + int whoSick; + + int *allAnimal = new int[numOfAni]; + + for (int i = 0; i < ti; i++) { + + allAnimal[i] = i; + } + for (int i = ti; i < ti + pe; i++) { + + allAnimal[i] = i; + } + for (int i = ti + pe; i < numOfAni; i++) { + + allAnimal[i] = i; + } + + if (numOfAni <= 0) { + std::cout<<"I don't know how to say in this case, But you don't have any animal.so no animal dies."<0 + + std::cout<<"The Turtle is (before the rolling dice): "< dist2(1, numOfAni); + whoSick = dist2(mt) - 1; + + std::cout << "Who sick? number is: " << whoSick + 1 << std::endl; + + // A Tiger gets sick and remove + if (whoSick < ti) { + + std::cout << "Your Tiger number " << whoSick + 1 << " got sick and died. So sorry!" << std::endl; + ti -= 1; + //nyc.setNumOfTig(ti); + + for (int j = whoSick; j < roomOfTi; j++) { + + Tiger temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + arr[roomOfTi - 1] = Tiger(0, 0.00, 0, 0.00, 0.00); + } + //A Penguin get sick and remove + else if (whoSick >= ti && whoSick < ti + pe) { + + pe -= 1; + + int sickP = whoSick - ti; + + std::cout << "Your Penguin number " << sickP + 1 << " got sick and died. So sorry" << std::endl; + + for (int j = sickP; j < roomOfPe; j++) { + + Penguin temp = Penguin(0, 0.00, 0, 0.00, 0.00); + //Penguin temp = arra[j]; + temp = arra[j]; + arra[j] = arra[j + 1]; + arra[j + 1] = temp; + } + arra[roomOfPe - 1] = Penguin(0, 0.00, 0, 0.00, 0.00); + + std::cout<<"The Turtle is (after the penguin die): "<= numOfTi+numOfPe && whoSick < numOfAni + { + tu -= 1; + + int sickTu = whoSick - (ti + pe); + std::cout << "Your Turtle number " << sickTu + 1 << " got sick and died. So sorry" << std::endl; + + + for (int j = sickTu; j < roomOfTu; j++) { + + //Turtle temp = array[j]; + Turtle temp = Turtle(0, 0.00, 0, 0.00, 0.00); + temp = array[j]; + array[j] = array[j + 1]; + array[j + 1] = temp; + + } + array[roomOfTu - 1] = Turtle(0, 0.00, 0, 0.00, 0.00); + } + + } + delete[] allAnimal; +} + +void DArray::whoHasBaby(int &numTi, int &numPen, int &numTurt, Tiger *arr, Penguin *arra, Turtle *array){ +//void whoHasBaby(Tiger *arr, Penguin *arra, Turtle *array) { + Zoo zoo; + int draw; + + int numAdTi = 0; + for (int i = 0; i < numTi; i++) { + + if (arr[i].getAge() >= 3) { + numAdTi += 1; + } + } + std::cout <<"Number of Adult Tigers: " << numAdTi << std::endl; + + int *adultTiger = new int[numAdTi]; + + int j = 0; + for (int i = 0; i < numTi; i++) { + if (arr[i].getAge() >= 3) { + adultTiger[j] = i; + j++; + } + } + + int numAdPen = 0; + for (int i = 0; i < numPen; i++) { + if (arra[i].getAge() >= 3) { + numAdPen += 1; + } + } + std::cout <<"Number of Adult penguins: " << numAdPen << std::endl; + + int *adultPenguin = new int[numAdPen]; + + int k = 0; + for (int i = 0; i < numPen; i++) { + if (arra[i].getAge() >= 3) { + adultPenguin[k] = i; + k++; + } + } + + int numAdTur = 0; + for (int i = 0; i < numTurt; i++) { + if (array[i].getAge() >= 3) { + numAdTur += 1; + } + std::cout<<"Age of Turtles: "<= 3) { + adultTurtle[l] = i; + l++; + } + } + + //to just show an check + std::cout<<"Your Adult penguin: "; + for (int m = 0; m < numAdPen; m++) { + + std::cout << "number " << adultPenguin[m]+1 <<" , "; + } + + int numAdAnimal = numAdTi + numAdPen + numAdTur; + + std::random_device ran1; + std::mt19937 mt1(ran1()); + std::uniform_int_distribution dist(1, numAdAnimal); + draw = dist(mt1)-1; + + + if (numAdAnimal <= 0) { + std::cout << "Sorry. You don't have any adult animals. Maybe next time!" << std::endl; + } + + + else { + //A Tiger has a baby. + if (draw < numAdTi) { + //Tiger ti; + //ti.cost; + //std::cout<<"Tiger cost inside whohasbaby fuct"<= roomOfTi) { + + this->DArray::arrayTiger(arr, roomOfTi); + + std::cout<<"Room For Tiger after resizing "<< roomOfTi<= numAdTi && draw < numAdTi + numAdPen) { + //Penguin pe; + Animal *peng = new Penguin(); + peng->getCost(); + int chosenPen; + chosenPen = adultPenguin[draw - numAdTi]; + std::cout << "Your penguin number "<= roomOfPe) { + + arrayPen(arra, roomOfPe); + std::cout<<"Room For penguin after resizing "<= numOfTi+numOfPe && whoSick < numOfAni + { + + int chosenTurtle; + chosenTurtle = adultTurtle[draw - numAdTi - numAdPen]; + std::cout << "Your Turtle number "<= roomOfTu) { + + arrayTur(array, roomOfTu); + std::cout<<"Room For Turtle after resizing "< +#include +#include "Tiger.h" +#include "Penguin.h" +#include "Turtle.h" +#include "DArray.h" + +Zoo::Zoo()=default; +Zoo::~Zoo()=default; + +int Zoo::getDay(){ + return this -> day; +} +void Zoo::setDay(int d){ + day = d; +} +int Zoo::getNumOfTig(){ + return numOfTig; +} +void Zoo::setNumOfTig(int tig){ + numOfTig =tig; + +} +int Zoo::getNumOfPeng(){ + return numOfPeng; + +} +void Zoo::setNumOfPeng(int pen){ + numOfPeng = pen; + +} +int Zoo::getNumOfTurt(){ + return numOfTurt; + +} +void Zoo::setNumOfTurt(int turt){ + numOfTurt =turt; +} + +void Zoo::play(){ + + std::cout<<"Welcome to the Zoo! Now you run this Fantastic Zoo."<> fBuyTi; + setNumOfTig(inputVal(fBuyTi)); + + if(!(numOfTig==1 || numOfTig ==2)) { + + 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::cin >> fBuyTi; + setNumOfTig(inputVal(fBuyTi)); + }while(!(numOfTig ==1 || numOfTig==2)); + } + + for(int i =0; i > fBuyP; + setNumOfPeng(inputVal(fBuyP)); + + if(!(numOfPeng ==1 || numOfPeng ==2)) { + + 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::cin >> fBuyP; + setNumOfPeng(inputVal(fBuyP)); + }while(!(numOfPeng ==1 || numOfPeng ==2)); + } + + for(int i =0; i >fBuyTu; + setNumOfTurt(inputVal(fBuyTu)); + + if(!(numOfTurt ==1 || numOfTurt ==2)) { + + 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; + setNumOfTurt(inputVal(fBuyTu)); + + }while(!(numOfTurt ==1 || numOfTurt ==2)); + } + + for(int i =0; i dist(1, 3); + event = dist(mt); + + std::cout<<"Today's event is: "< dist3(250, 500); + bonus= dist3(mt); + std::cout<<"Your today bonus is "<>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 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); + + if(!(buyOneMore ==1 || buyOneMore ==2 || buyOneMore ==3)) { + + 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); + + }while(!(buyOneMore ==1 || buyOneMore ==2 || buyOneMore ==3)); + } + + if (buyOneMore == 1) { + + std::cout << "So, you decided to buy a Tiger. Best Choice!" << std::endl; + if(numOfTig >= room.getRoomOfTi()) { + + room.arrayTiger(arrayOfTi, room.getRoomOfTi()); + + } + //Adds a new tiger to the array. + arrayOfTi[numOfTig] = Tiger(3, tiger.getCost(), 0, tiger.getBaseFoodCost(), tiger.getPayoff()); + setNumOfTig(numOfTig+1); + account -= tiger.getCost(); + std::cout<<"After you buy the tiger, your balance is "<= room.getRoomOfPe()) { + + room.arrayPen(arrayOfPe, room.getRoomOfPe()); + + } + arrayOfPe[numOfPeng] = Penguin(3, penguin.getCost(), 0, penguin.getBaseFoodCost(), penguin.getPayoff()); + setNumOfPeng(numOfPeng+1); + account -= penguin.getCost(); + std::cout<<"After you buy the penguin, your balance is "<= room.getRoomOfTu()) { + + room.arrayTur(arrayOfTur, room.getRoomOfTu()); + + } + arrayOfTur[numOfTurt] = Turtle(3, turtle.getCost(), 0, turtle.getBaseFoodCost(), turtle.getPayoff()); + setNumOfTurt(numOfTurt+1); + account -= turtle.getCost(); + 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!"< +#include + + +int inputVal(double in) { + + // Check type validation first using std::cin.fail() + + + if( std::cin.good() && in > 0 && (in - (int)in == 0)) { + return (int)in; + } + + else{ + + do { + //std::cout << "Input" << input << std::endl; + std::cout << "Wrong input! You need to input proper value!" << std::endl; + + std::cin.clear(); + std::cin.ignore(INT_MAX, '\n'); + + std::cout << "Please try again. Input here: " << std::endl; + std::cin >> in; + //decimalCheck(input); + + } while(!(std::cin.good() && in > 0 && (in - (int)in == 0) )); + + } + + return (int)in; +} \ No newline at end of file diff --git a/inputVal.h b/inputVal.h new file mode 100644 index 0000000..c1f28a5 --- /dev/null +++ b/inputVal.h @@ -0,0 +1,14 @@ +/**************************************************************************************************** + * * Program name: CS162 Project2 + * * Author: Taekyoung Kim + * * Date: 01/21/2019 + * * Description: This is inputVal.h file for CS162 Project2 + ******************************************************************************************************/ + + +#ifndef PROJECT2_INPUTVAL_H +#define PROJECT2_INPUTVAL_H + +int inputVal(double in); + +#endif //PROJECT2_INPUTVAL_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..dce981b --- /dev/null +++ b/main.cpp @@ -0,0 +1,22 @@ + +/**************************************************************************************************** + * * Program name: CS162 Project2 + * * Author: Taekyoung Kim + * * Date: 01/21/2019 + * * Description: This is main.cpp file for CS162 Project2 + * * This project shows a zoo that has a few animals. We needs inheritance and class...... + ******************************************************************************************************/ + + + + +#include +#include "Zoo.h" + +int main() { + //std::cout << "Hello, World!" << std::endl; + + Zoo zoo; + zoo.play(); + return 0; +} \ No newline at end of file