From 816d93d4074c71f57ea772ff5179fc891e4b8478 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:02:57 -0800 Subject: [PATCH 01/14] makes new branch --- 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 745c0928223d70c0bf4b5230ddcb2a147083fda4 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:03:14 -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 d0839fc38cdead0f7d7fa0873906ed8ecacd3704 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:03:20 -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 773ec8f57870b443789c444e5154eac280a8d574 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:03:27 -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 08972a08c87df321fbfc6a89c12c0fa1f129f464 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:03:33 -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 faaf2760243e31f6408b045e07260d42ac5d2a4b Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:03:40 -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 7eacbf149c79afe0712134da40674bbd4186092a Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:03:48 -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 588b3062ed5f08eff0b32bbee788d72ace179a8d Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:03:54 -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 8562dc05b6709f0571e6492a55e3abde3bb013dc Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:04:00 -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 79b0130e2e7c73e838c7bfa89604a332049d38f7 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:04:07 -0800 Subject: [PATCH 10/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 d1d1d76ab341323b819856aa53b5477c717672b5 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:04:13 -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 d42b1f3e2d92ffc3a6760ac2ef314363d0dffbe3 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:04:18 -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 51924a4144b2a0f4872f3af80d50fe2ff43e89a7 Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:04:24 -0800 Subject: [PATCH 13/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 c6e0c6cb2affd59e8416b0addd8b29cd38fb948b Mon Sep 17 00:00:00 2001 From: Owl <40027596+tkim949@users.noreply.github.com> Date: Fri, 25 Jan 2019 00:06:17 -0800 Subject: [PATCH 14/14] uploads files --- Animal.cpp | 63 +++++ Animal.h | 57 +++++ DArray.cpp | 101 ++++++++ DArray.h | 46 ++++ Penguin.cpp | 19 ++ Penguin.h | 27 +++ Tiger.cpp | 19 ++ Tiger.h | 27 +++ Turtle.cpp | 19 ++ Turtle.h | 28 +++ Zoo.cpp | 653 +++++++++++++++++++++++++++++++++++++++++++++++++++ Zoo.h | 39 +++ inputVal.cpp | 43 ++++ inputVal.h | 14 ++ main.cpp | 22 ++ 15 files changed, 1177 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..d876025 --- /dev/null +++ b/DArray.cpp @@ -0,0 +1,101 @@ +/**************************************************************************************************** + * * 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" + + +DArray::DArray() =default; +DArray::~DArray()=default; + +int DArray::getSizeOfTi(){ + return sizeOfTi; + +} +void DArray::setSizeOfTi(int ti){ + sizeOfTi = ti; + +} +int DArray::getSizeOfPe(){ + return sizeOfPe; +} +void DArray::setSizeOfPe(int pe){ + sizeOfPe = pe; + +} +int DArray::getSizeOfTu(){ + return sizeOfTu; + +} +void DArray::setSizeOfTu(int tu){ + sizeOfTu = tu; + +} +void DArray::arrayTiger(Tiger *arr, int sizeOfTi){ + + Tiger *temp_ti = new Tiger[sizeOfTi * 2]; + + for (int i = 0; i < sizeOfTi * 2; i++) { + temp_ti[i] = Tiger(0, 0.00, 0, 0.00, 0.00); + } + + for (int i = 0; i < sizeOfTi; i++) { + temp_ti[i] = arr[i]; + } + setSizeOfTi(sizeOfTi*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 sizeOfPe){ + + Penguin *temp_pe = new Penguin[sizeOfPe * 2]; + + for (int i = 0; i < sizeOfPe * 2; i++) { + temp_pe[i] = Penguin(0, 0.00, 0, 0.00, 0.00); + } + + for (int i = 0; i < sizeOfPe; i++) { + temp_pe[i] = arra[i]; + } + setSizeOfPe(sizeOfPe*2); + + for (int i = sizeOfPe; i < sizeOfPe * 2; i++) { + arra[i] = Penguin(0, 0.00, 0, 0.00, 0.00); + } + + arra = temp_pe; + +} +void DArray::arrayTur(Turtle *array, int sizeOfTu){ + + Turtle *temp_tu = new Turtle[sizeOfTu * 2]; + + for (int i = 0; i < sizeOfTu * 2; i++) { + temp_tu[i] = Turtle(0, 0.00, 0, 0.00, 0.00); + } + + for (int i = 0; i < sizeOfTu; i++) { + temp_tu[i] = array[i]; + } + + setSizeOfTu(sizeOfTu*2); + // delete[] array; + + for (int i = sizeOfTu; i < sizeOfTu * 2; i++) { + array[i] = Turtle(0, 0.00, 0, 0.00, 0.00); + } + + array = temp_tu; + +} \ No newline at end of file diff --git a/DArray.h b/DArray.h new file mode 100644 index 0000000..2bcdccb --- /dev/null +++ b/DArray.h @@ -0,0 +1,46 @@ +/**************************************************************************************************** + * * 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...... + ******************************************************************************************************/ + + +#ifndef PROJECT2_DARRAY_H +#define PROJECT2_DARRAY_H +#include "Turtle.h" +#include "Animal.h" +#include "Penguin.h" +#include "Tiger.h" + + +class DArray { + +protected: + int sizeOfTi; + int sizeOfPe; + int sizeOfTu; + + Tiger *arr; + Penguin *arra; + Turtle *array; + +public: + DArray(); + ~DArray(); + int getSizeOfTi(); + void setSizeOfTi(int ti); + int getSizeOfPe(); + void setSizeOfPe(int pe); + int getSizeOfTu(); + void setSizeOfTu(int tu); + void arrayTiger(Tiger *arr, int sizeOfTi); + void arrayPen(Penguin *arra, int sizeOfPe); + void arrayTur(Turtle *array, int sizeOfTu); + + +}; + + +#endif //PROJECT2_DARRAY_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..fbaded8 --- /dev/null +++ b/Zoo.cpp @@ -0,0 +1,653 @@ +/**************************************************************************************************** + * * 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" +#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(!(getNumOfTig()==1 || getNumOfTig() ==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(!(getNumOfTig() ==1 || getNumOfTig()==2)); + } + + for(int i =0; i > fBuyP; + setNumOfPeng(inputVal(fBuyP)); + + if(!(getNumOfPeng() ==1 || getNumOfPeng() ==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(!(getNumOfPeng() ==1 || getNumOfPeng() ==2)); + } + + for(int i =0; i >fBuyTu; + setNumOfTurt(inputVal(fBuyTu)); + + if(!(getNumOfTurt() ==1 || getNumOfTurt() ==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(!(getNumOfTurt() ==1 || getNumOfTurt() ==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 < getNumOfTig()) { + + std::cout<<"Your Tiger number "<= getNumOfTig() && whoSick < getNumOfTig()+getNumOfPeng()) { + + setNumOfPeng(getNumOfPeng()-1); + //arrayOfPe[whoSick-numOfTi]; + int sickP= whoSick -getNumOfTig(); + + std::cout<<"Your Penguin number "<= numOfTi+numOfPe && whoSick < numOfAni + { + setNumOfTurt(getNumOfTurt()-1); + //arrayOfTur[whoSick -(numOfTi + numOfPe)]; + int sickTu = whoSick -(getNumOfTig() + getNumOfPeng()); + std::cout<<"Your Turtle number "< dist3(250, 500); + bonus= dist3(mt); + std::cout<<"Your today bonus is "<= 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 < getNumOfPeng(); i++) { + if (arrayOfTi[i].getAge() >= 3) { + adultTiger[j] = i; + j++; + } + std::cout<<"Age of Penguins: "<= 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 < getNumOfPeng(); i++) { + if (arrayOfPe[i].getAge() >= 3) { + adultPenguin[k] = i; + k++; + } + } + + + int numAdTur = 0; + for (int i = 0; i < getNumOfTurt(); i++) { + if (arrayOfTur[i].getAge() >= 3) { + numAdTur += 1; + } + std::cout<<"Age of Turtles: "<= 3) { + adultTurtle[l] = i; + l++; + } + } + + + //to just show an check + for (int m = 0; m < numAdPen; m++) { + + std::cout << "Adult Penguin: " << adultPenguin[m] << std::endl; + } + + int numAdAnimal = numAdTi + numAdPen + numAdTur; + + std::uniform_int_distribution dist5(0, numAdAnimal - 1); + draw = dist5(mt); + + //A Tiger has a baby. + if (numAdAnimal <= 0) { + std::cout << "Sorry. You don't have any adult animals. Maybe next time!" << std::endl; + } + + else { + if (draw < numAdTi) { + int chosenTi; + chosenTi = adultTiger[draw]; + std::cout << "Your tiger number: "<= roomForTi) { + + DArray arr; + arr.setSizeOfTi(roomForTi); + arr.arrayTiger(arrayOfTi, roomForTi); + roomForTi = arr.getSizeOfTi(); + + std::cout<<"Room For Tiger inside "<= numAdTi && draw < numAdTi + numAdPen) { + int chosenPen; + chosenPen = adultPenguin[draw - numAdTi]; + std::cout << "Your penguin number "<= roomForPe) { + + //resize(arrayOfPe, roomForPe); + DArray arra; + arra.setSizeOfPe(roomForPe); + arra.arrayPen(arrayOfPe, roomForPe); + roomForPe = arra.getSizeOfPe(); + + std::cout<<"Room For penguin inside "<= numOfTi+numOfPe && whoSick < numOfAni + { + int chosenTurtle; + chosenTurtle = adultTurtle[draw - numAdTi - numAdPen]; + std::cout << "Your Turtle number "<= roomForTu) { + + DArray array; + array.setSizeOfTu(roomForTu); + array.arrayTur(arrayOfTur, roomForTu); + roomForTu = array.getSizeOfTu(); + + } + //Adds the babies to the array of Turtle. + for (int i = 0; i < 10; i++) { + arrayOfTur[getNumOfTurt() - 10 + i] = Turtle(0, turCost, 0, turtle.getBaseFoodCost(), + turtle.getPayoff()); + } + } + + //delete [] allAnimal; + } + } + + double todayAIncome =getNumOfTig()*tiger.getPayoff()+getNumOfPeng()*penguin.getPayoff()+getNumOfTurt()*turtle.getPayoff(); + account= account + bonus + todayAIncome - costPerDay; + + std::cout<<"Now it's the time to check your balance."<>buyNewOne; + buyNew =inputVal(buyNewOne); + + if(!(buyNew ==1 || buyNew ==2)) { + + do{ + std::cin.clear(); + std::cin.ignore(INT_MAX, '\n'); + std::cout<<"Wrong input. You can only input 1 or 2, Please try again: "; + std::cin>>buyNewOne; + buyNew =inputVal(buyNewOne); + }while(!(buyNew ==1 || buyNew ==2)); + } + + if(buyNew==1) { + + double 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(getNumOfTig() >= roomForTi) { + + DArray arr; + arr.setSizeOfTi(roomForTi); + arr.arrayTiger(arrayOfTi, roomForTi); + roomForTi = arr.getSizeOfTi(); + + } + //Adds a new tiger to the array. + arrayOfTi[getNumOfTig()] = Tiger(3, tigCost, 0, tiger.getBaseFoodCost(), tiger.getPayoff()); + setNumOfTig(getNumOfTig()+1); + account -= tigCost; + std::cout<<"After you buy the tiger, your balance is "<= roomForPe) { + //resize(arrayOfPe, roomForPe); + DArray arra; + arra.setSizeOfPe(roomForPe); + arra.arrayPen(arrayOfPe, roomForPe); + roomForPe = arra.getSizeOfPe(); + + } + arrayOfPe[getNumOfPeng()] = Penguin(3, penCost, 0, penguin.getBaseFoodCost(), penguin.getPayoff()); + setNumOfPeng(getNumOfPeng()+1); + account -= penCost; + std::cout<<"After you buy the penguin, your balance is "<= roomForTu) { + //resize(arrayOfTur, roomForTu); + DArray array; + array.setSizeOfTu(roomForTu); + array.arrayTur(arrayOfTur, roomForTu); + roomForTu = array.getSizeOfTu(); + + } + arrayOfTur[getNumOfTurt()] = Turtle(3, turCost, 0, turtle.getBaseFoodCost(), turtle.getPayoff()); + setNumOfTurt(getNumOfTurt()+1); + account -= turCost; + std::cout<<"After you buy the turtle, your balance is "<>playAgain; + std::cout< 0); + + if (account < 0){ + std::cout<<"I'm sorry, but your account is empty. Play next time. Good buy!"< +#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