Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class BlackPanther {
- private:
- int age;
- std::string habitat;
- double weight;
- bool gender; // true --> 1 --> females // false --> 0 --> males
- bool birth;
- public:
- BlackPanther() {
- age = 0;
- habitat = "";
- weight = 0;
- gender = false;
- birth = false;
- }
- BlackPanther(int a, std::string h, double w, bool g, bool b) {
- age = a;
- habitat = h;
- weight = w;
- gender = g;
- birth = b;
- }
- BlackPanther(int a) {
- age = a;
- habitat = "";
- weight = 0;
- gender = 0;
- birth = 0;
- }
- //setters
- void setAge(int a) {
- age = a;
- }
- void setHabitat(std::string h) {
- habitat = h;
- }
- void setWeight(double w) {
- weight = w;
- }
- void setGender(bool g) {
- gender = g;
- }
- void setBirth(bool b) {
- birth = b;
- }
- //getters
- int getAge() {
- return age;
- }
- std::string getHabitat() {
- return habitat;
- }
- double getWeight() {
- return weight;
- }
- bool getGender() {
- return gender;
- }
- bool getBirth() {
- return birth;
- }
- void eatAnimal(int prey_weight) {
- weight += (double)prey_weight / 100;
- }
- void breed(std::string h, bool g) {
- if (habitat == h && gender != g) {
- //std::cout << "H anaparagwgh pragmatopoihthike" << std::endl;
- printf("H anaparagwgh pragmatopoihthike\n");
- birth = true;
- }
- else {
- //std::cout << "H anaparagwgh den pragmatopoihthike" << std::endl;
- printf("H anaparagwgh den pragmatopoihthike\n");
- }
- }
- void searchFood() {
- age++;
- }
- void printAll() {
- std::cout << "Age: " << age << ", Habitat: " << habitat << ", Weight: " << ((gender) ? "female" : "male") <<((birth) ? "gave birth" : "didnt give birth") << std::endl;
- }
- void has_mated() {
- (birth) ? age = age : age += 2;
- }
- };
- int main() {
- BlackPanther b1 = BlackPanther(4, "Afriki", 65, true, false);
- BlackPanther b2 = BlackPanther(4, "Afriki", 65, false, false);
- BlackPanther b3 = BlackPanther(4, "N. Asia", 65, true, false);
- b1.eatAnimal(7);
- b2.eatAnimal(5);
- b3.eatAnimal(13);
- //cout<<b1.getWeight()<<endl<<b2.getWeight()<<endl<<b3.getWeight()<<endl;
- if (b1.getWeight() > b2.getWeight()) {
- std::cout << "b11" << std::endl;
- if (b1.getWeight() > b3.getWeight()) {
- b1.breed(b2.getHabitat(), b2.getGender());
- b1.breed(b3.getHabitat(), b3.getGender());
- }
- }
- if (b2.getWeight() > b1.getWeight()) {
- std::cout << "b21" << std::endl;
- if (b2.getWeight() > b3.getWeight()) {
- b2.breed(b1.getHabitat(), b1.getGender());
- b2.breed(b3.getHabitat(), b3.getGender());
- }
- }
- if (b3.getWeight() > b1.getWeight()) {
- std::cout << "b31" << std::endl;
- if (b3.getWeight() > b2.getWeight()) {
- b3.breed(b1.getHabitat(), b1.getGender());
- b3.breed(b2.getHabitat(), b2.getGender());
- }
- }
- if (b1.getWeight() < b2.getWeight()) {
- std::cout << "b11" << std::endl;
- if (b1.getWeight() < b3.getWeight()) {
- b1.breed(b2.getHabitat(), b2.getGender());
- b1.breed(b3.getHabitat(), b3.getGender());
- }
- }
- if (b2.getWeight() < b1.getWeight()) {
- std::cout << "b21" << std::endl;
- if (b2.getWeight() < b3.getWeight()) {
- b2.breed(b1.getHabitat(), b1.getGender());
- b2.breed(b3.getHabitat(), b3.getGender());
- }
- }
- if (b3.getWeight() < b1.getWeight()) {
- std::cout << "b31" << std::endl;
- if (b3.getWeight() < b2.getWeight()) {
- b3.breed(b1.getHabitat(), b1.getGender());
- b3.breed(b2.getHabitat(), b2.getGender());
- }
- }
- b1.searchFood();
- b3.searchFood();
- if (b3.getAge() < b1.getAge()) {
- std::cout << "b31" << std::endl;
- if (b3.getAge() < b2.getAge()) {
- b3.breed(b1.getHabitat(), b1.getGender());
- b3.breed(b2.getHabitat(), b2.getGender());
- }
- }
- if (b1.getAge() < b2.getAge()) {
- std::cout << "b11" << std::endl;
- if (b1.getAge() < b3.getAge()) {
- b1.breed(b2.getHabitat(), b2.getGender());
- b1.breed(b3.getHabitat(), b3.getGender());
- }
- }
- if (b2.getAge() < b1.getAge()) {
- std::cout << "b21" << std::endl;
- if (b2.getAge() < b3.getAge()) {
- b2.breed(b1.getHabitat(), b1.getGender());
- b2.breed(b3.getHabitat(), b3.getGender());
- }
- }
- b1.has_mated();
- b2.has_mated();
- b3.has_mated();
- b1.printAll();
- b2.printAll();
- b3.printAll();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement