From fc302a83d88feff20a875e0536a1b3773ee1eb1c Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:44:35 -0800 Subject: [PATCH 01/14] Deletes files --- 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 6ac6c3422cd6426e8b78eb1746d6b74068a412ba Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:45:16 -0800 Subject: [PATCH 02/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 ed8b9d5ea16812bf8c5e1d0939a3d0dad4902efe Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:45:27 -0800 Subject: [PATCH 03/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 92b3fda44c8dd4b13cea6bfa46b9cf7744a0f772 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:45:34 -0800 Subject: [PATCH 04/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 e232301cc1bf9c0faeaaae0c09c2fc23c6889551 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:45:43 -0800 Subject: [PATCH 05/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 2b13f027ad024ee7ca959a566fa67e645b179091 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:45:51 -0800 Subject: [PATCH 06/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 77f7fbe4907aff9d156d47c0ca6b3df294c7c5d5 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:45:57 -0800 Subject: [PATCH 07/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 20793b74d8c096fc3d34fcb6e75dcfa0aab488f2 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:46:04 -0800 Subject: [PATCH 08/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 e7da9c3bd6ef67f61717755195bc7d065094c33c Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:46:11 -0800 Subject: [PATCH 09/14] Delete Zoo.cpp --- 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 fd6c5807c25eeaa374356fec5e8cdc6196f0c9d0 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:46:18 -0800 Subject: [PATCH 10/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 0d48c9c7cbf337d86511d6f3eb80c6cc9dc63681 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:46:24 -0800 Subject: [PATCH 11/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 b1b9ab94f791d2d4c0697ba31e7070075cef98c2 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:46:30 -0800 Subject: [PATCH 12/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 e4d4041bd4ac14e743588bd2278614264fafc4f0 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:46:57 -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 02a1a4df7417236f555e0481a704c2322b12c16c Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Thu, 24 Jan 2019 18:47:55 -0800 Subject: [PATCH 14/14] uploads files --- Animal.cpp | 63 ++++++ Animal.h | 57 +++++ Penguin.cpp | 19 ++ Penguin.h | 27 +++ Tiger.cpp | 19 ++ Tiger.h | 27 +++ Turtle.cpp | 19 ++ Turtle.h | 28 +++ Zoo.cpp | 591 +++++++++++++++++++++++++++++++++++++++++++++++++++ Zoo.h | 30 +++ inputVal.cpp | 43 ++++ inputVal.h | 14 ++ main.cpp | 22 ++ 13 files changed, 959 insertions(+) create mode 100644 Animal.cpp create mode 100644 Animal.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/Penguin.cpp b/Penguin.cpp new file mode 100644 index 0000000..babdddb --- /dev/null +++ b/Penguin.cpp @@ -0,0 +1,19 @@ +/**************************************************************************************************** + * * 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 diff --git a/Penguin.h b/Penguin.h new file mode 100644 index 0000000..d1e09f1 --- /dev/null +++ b/Penguin.h @@ -0,0 +1,27 @@ +/**************************************************************************************************** + * * 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 diff --git a/Tiger.cpp b/Tiger.cpp new file mode 100644 index 0000000..be907f6 --- /dev/null +++ b/Tiger.cpp @@ -0,0 +1,19 @@ +/**************************************************************************************************** + * * 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 diff --git a/Tiger.h b/Tiger.h new file mode 100644 index 0000000..4f8284b --- /dev/null +++ b/Tiger.h @@ -0,0 +1,27 @@ +/**************************************************************************************************** + * * 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 diff --git a/Turtle.cpp b/Turtle.cpp new file mode 100644 index 0000000..476d698 --- /dev/null +++ b/Turtle.cpp @@ -0,0 +1,19 @@ +/**************************************************************************************************** + * * 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 diff --git a/Turtle.h b/Turtle.h new file mode 100644 index 0000000..74a3b2b --- /dev/null +++ b/Turtle.h @@ -0,0 +1,28 @@ +/**************************************************************************************************** + * * 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 diff --git a/Zoo.cpp b/Zoo.cpp new file mode 100644 index 0000000..ebf0a8e --- /dev/null +++ b/Zoo.cpp @@ -0,0 +1,591 @@ +/**************************************************************************************************** + * * 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."<> 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 > 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 >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 dist(1, 3); + event = dist(mt); + + std::cout<<"Today's event is: "< dist2(0,numOfAni-1); + whoSick = dist2(mt); + + // A Tiger gets sick and remove + if(whoSick < numOfTi) { + + std::cout<<"Your Tiger number "<= numOfTi && whoSick < numOfTi+numOfPe) { + + numOfPe -=1; + //arrayOfPe[whoSick-numOfTi]; + int sickP= whoSick -numOfTi; + + 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 "< dist3(250, 500); + bonus= dist3(mt); + std::cout<<"Your today bonus is "<=3){ + numAuPen+=1; + } + } + std::cout<<"Number of Adult penguins: "<=3) { + adultPenguin[j] =i; + j++; + } + } + + for(int j=0; j 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= 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= numOfTi+numOfPe && whoSick < numOfAni + { + std::cout<<"Your Turtle has 10 babies.Congratulations!"<= roomForTu) { + Turtle *temp_tu = new Turtle[roomForTu*2]; + + for(int i=0; i>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= roomForPe) { + Penguin *temp_pe = new Penguin[roomForPe*2]; + + for(int i=0; i= roomForTu) { + Turtle *temp_tu = new Turtle[roomForTu*2]; + + for(int i=0; i>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