1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
| #include "Zoo.h" #include<iostream> #include<string> #include <ctime> #include <cstdlib> #include<random>
std::string NA1[444] = { "赵", "钱", "孙", "李", "周", "吴", "郑", "王", "冯", "陈", "褚", "卫", "蒋", "沈", "韩", "杨", "朱", "秦", "尤", "许", "何", "吕", "施", "张", "孔", "曹", "严", "华", "金", "魏", "陶", "姜", "戚", "谢", "邹", "喻", "柏", "水", "窦", "章", "云", "苏", "潘", "葛", "奚", "范", "彭", "郎", "鲁", "韦", "昌", "马", "苗", "凤", "花", "方", "俞", "任", "袁", "柳", "酆", "鲍", "史", "唐", "费", "廉", "岑", "薛", "雷", "贺", "倪", "汤", "滕", "殷", "罗", "毕", "郝", "邬", "安", "常", "乐", "于", "时", "傅", "皮", "卞", "齐", "康", "伍", "余", "元", "卜", "顾", "孟", "平", "黄", "和", "穆", "萧", "尹", "姚", "邵", "湛", "汪", "祁", "毛", "禹", "狄", "米", "贝", "明", "臧", "计", "伏", "成", "戴", "谈", "宋", "茅", "庞", "熊", "纪", "舒", "屈", "项", "祝", "董", "梁", "杜", "阮", "蓝", "闵", "席", "季", "麻", "强", "贾", "路", "娄", "危", "江", "童", "颜", "郭", "梅", "盛", "林", "刁", "钟", "徐", "邱", "骆", "高", "夏", "蔡", "田", "樊", "胡", "凌", "霍", "虞", "万", "支", "柯", "昝", "管", "卢", "莫", "经", "房", "裘", "缪", "干", "解", "应", "宗", "丁", "宣", "贲", "邓", "郁", "单", "杭", "洪", "包", "诸", "左", "石", "崔", "吉", "钮", "龚", "程", "嵇", "邢", "滑", "裴", "陆", "荣", "翁", "荀", "羊", "於", "惠", "甄", "麴", "家", "封", "芮", "羿", "储", "靳", "汲", "邴", "糜", "松", "井", "段", "富", "巫", "乌", "焦", "巴", "弓", "牧", "隗", "山", "谷", "车", "侯", "宓", "蓬", "全", "郗", "班", "仰", "秋", "仲", "伊", "宫", "宁", "仇", "栾", "暴", "甘", "钭", "厉", "戎", "祖", "武", "符", "刘", "景", "詹", "束", "龙", "叶", "幸", "司", "韶", "郜", "黎", "蓟", "薄", "印", "宿", "白", "怀", "蒲", "邰", "从", "鄂", "索", "咸", "籍", "赖", "卓", "蔺", "屠", "蒙","池", "乔", "阴", "郁", "胥", "能", "苍", "双", "闻", "莘", "党", "翟", "谭", "贡", "劳", "逄", "姬", "申", "扶", "堵", "冉", "宰", "郦", "雍", "舄", "璩", "桑", "桂", "濮", "牛", "寿", "通", "边", "扈", "燕", "冀", "郏", "浦", "尚", "农", "温", "别", "庄", "晏", "柴", "瞿", "阎", "充", "慕", "连", "茹", "习", "宦", "艾", "鱼", "容", "向", "古", "易", "慎", "戈", "廖", "庾", "终", "暨", "居", "衡", "步", "都", "耿", "满", "弘", "匡", "国", "文", "寇", "广", "禄", "阙", "东", "殴", "殳", "沃", "利", "蔚", "越", "夔", "隆", "师", "巩", "厍", "聂", "晁", "勾", "敖", "融", "冷", "訾", "辛", "阚", "那", "简", "饶", "空", "曾", "毋", "沙", "乜", "养", "鞠", "须", "丰", "巢", "关", "蒯", "相", "查", "後", "荆", "红", "游", "竺", "权", "逯", "盖", "益", "桓", "公", "仉", "督", "晋", "楚", "闫", "法", "汝", "鄢", "涂", "钦", "归", "海","岳", "帅", "缑", "亢", "况", "后", "有", "琴", "商", "牟", "佘", "佴", "伯", "赏", "墨", "哈", "谯", "笪", "年", "爱", "阳", "佟", "言", "福" };
std::string NA2[59] = { "万俟", "司马", "上官", "欧阳", "夏侯", "诸葛", "闻人", "东方", "赫连", "皇甫", "尉迟", "公羊", "澹台", "公冶", "宗政", "濮阳", "淳于", "单于", "太叔", "申屠", "公孙", "仲孙", "轩辕", "令狐", "钟离", "宇文", "长孙", "慕容", "鲜于", "闾丘", "司徒", "司空", "亓官", "司寇", "子车", "颛孙", "端木", "巫马", "公西", "漆雕", "乐正", "壤驷", "公良", "拓跋", "夹谷", "宰父", "谷梁", "百里", "东郭", "南门", "呼延", "羊舌", "微生", "梁丘", "左丘", "东门", "西门", "南宫", "第五" };
std::string ME1m[140] = { "伟", "刚", "勇", "毅", "俊", "峰", "强", "军", "平", "保", "东", "文", "辉", "力", "明", "永", "健", "世", "广", "志", "义", "兴", "良", "海", "山", "仁", "波", "宁", "贵", "福", "生", "龙", "元", "全", "国", "胜", "学", "祥", "才", "发", "武", "新", "利", "清", "飞", "彬", "富", "顺", "信", "子", "杰", "涛", "昌", "成", "康", "星", "光", "天", "达", "安", "岩", "中", "茂", "进", "林", "有", "坚", "和", "彪", "博", "诚", "先", "敬", "震", "振", "壮", "会", "思", "群", "豪", "心", "邦", "承", "乐", "绍", "功", "松", "善", "厚", "庆", "磊", "民", "友", "裕", "河", "哲", "江", "超", "浩", "亮", "政", "谦", "亨", "奇", "固", "之", "轮", "翰", "朗", "伯", "宏", "言", "若", "鸣", "朋", "斌", "梁", "栋", "维", "启", "克", "伦", "翔", "旭", "鹏", "泽", "晨", "辰", "士", "以", "建", "家", "致", "树", "炎", "德", "行", "时", "泰", "盛" };
std::string ME1f[165] = { "秀", "娟", "英", "华", "慧", "巧", "美", "娜", "静", "淑", "惠", "珠", "翠", "雅", "芝", "玉", "萍", "红", "娥", "玲", "芬", "芳", "燕", "彩", "春", "菊", "兰", "凤", "洁", "梅", "琳", "素", "云", "莲", "真", "环", "雪", "荣", "爱", "妹", "霞", "香", "月", "莺", "媛", "艳", "瑞", "凡", "佳", "嘉", "琼", "勤", "珍", "贞", "莉", "桂", "娣", "叶", "璧", "璐", "娅", "琦", "晶", "妍", "茜", "秋", "珊", "莎", "锦", "黛", "青", "倩", "婷", "姣", "婉", "娴", "瑾", "颖", "露", "瑶", "怡", "婵", "雁", "蓓", "纨", "仪", "荷", "丹", "蓉", "眉", "君", "琴", "蕊", "薇", "菁", "梦", "岚", "苑", "筠", "柔", "竹", "霭", "凝", "晓", "欢", "霄", "枫", "芸", "菲", "寒", "欣", "滢", "伊", "亚", "宜", "可", "姬", "舒", "影", "荔", "枝", "思", "丽", "秀", "飘", "育", "馥", "琦", "晶", "妍", "茜", "秋", "珊", "莎", "锦", "黛", "青", "倩", "婷", "宁","蓓", "纨", "苑", "婕", "馨", "瑗", "琰", "韵", "融", "园", "艺", "咏", "卿", "聪", "澜", "纯", "毓", "悦", "昭", "冰", "爽", "琬", "茗", "羽", "希" };
Zoo::Zoo() { day = 0; num_visitor = 0; num_adult = 0; num_child = 0; num_visitor = 0; Money all_earned = Money(0.0, 0.0); }
Zoo::Zoo(const int _day, const int _num_visitor, const int _num_child, const int _num_adult, const Money _all_earned, Zookeeper zookeeper, Sold_person sold_person) : day(_day), num_visitor(_num_visitor), num_adult(_num_adult), num_child(_num_child), all_earned(_all_earned), zookeeper(zookeeper), sold_person(sold_person) { Elephant elephant(2600, 0, 3, 750, 750); Giraffe giraffe(1800, 0, 2.5, 500, 500); Monkey monkey(40, 0, 0.9, 300, 300); this->animalenclosure[1].init(0, 1, 0, elephant); this->animalenclosure[2].init(0, 1, 0, elephant); this->animalenclosure[3].init(0, 1, 0, monkey); this->sold_person.init();
}
Zoo::~Zoo() {} int Zoo::getRand(int min, int max) { std::default_random_engine e; e.seed(time(0)); return (e()%(max - min + 1)) + min; }
bool Zoo::close() { if (!this->zookeeper.close_by_clean() || !this->sold_person.is_open()) { return 1; } else { return 0; } }
void Zoo::work() { while (1) { std::cout << "-----------------------------------------------------------------------------" << std::endl; std::cout << "是否要开启动物园新的一天" << std::endl; std::cout << "需要请输入1" << std::endl; std::cout << "否则输入其他数字" << std::endl; std::cout << "-----------------------------------------------------------------------------" << std::endl; int nums; std::cin >> nums; if (nums != 1) { break; } this->day++; if (this->close()) { std::cout << "-----------------------------------------------------------------------------" << std::endl; std::cout << "动物园不堪重负" << std::endl; std::cout << "在经营了" << this->day << "天后倒闭了" << std::endl; if (!this->zookeeper.close_by_clean()) { std::cout << "倒闭的原因是因为清洁工因为打扫任务过于繁重辞职了" << std::endl; } else { std::cout << "倒闭原因是因为销售员食材不足,无法正常经营动物的伙食了" << std::endl; } std::cout << "历史上,到访的游客总数为" << this->num_visitor << std::endl; std::cout << "其中,成年人游客总数为" << this->num_adult << std::endl; std::cout << "其中,儿童游客总数为" << this->num_child << std::endl; for (int i = 1; i <= 3; i++) { std::cout << "居住场所" << i << "一共被清洁了" << this->animalenclosure[i].display_close_by_clean() << "天" << std::endl; } std::cout << "感谢您陪伴该动物园走到了最后" << "以后再会" << std::endl; break; } else { if (day % 3 == 1) { Animal* animal = new Elephant; std::cout << "今天的动物园节目是"; doplay(*animal); delete animal; } else if (day % 3 == 2) { Animal* animal = new Monkey; std::cout << "今天的动物园节目是"; doplay(*animal); delete animal; } else { Animal* animal = new Giraffe; std::cout << "今天的动物园节目是"; doplay(*animal); delete animal; } int adult_num = getRand(10, 15); this->num_visitor += adult_num; this->num_adult += adult_num; std::cout << "第" << this->day << "天" << "到来了" << adult_num << "个成年人" << std::endl; for (int i = 1; i <= adult_num; i++) { int child_num = getRand(1, 3); this->num_child += child_num; this->num_visitor += child_num; int age = getRand(23, 80); std::string name; name = (rand() % 56 != 5 ? NA1[rand() % 444] : NA2[rand() % 59]); name += (rand() % 2 == 1 ? ME1m[rand() % 140] : ME1f[rand() % 165]); if (rand() % 2 == 0) name += (rand() % 2 == 1 ? ME1m[rand() % 140] : ME1f[rand() % 165]); std::string pass_id = std::to_string(getRand(10000, 99999)); double x = 20.0 + static_cast <double> (rand()) / (static_cast <double> (RAND_MAX / (40.0 - 20.0))); double y = 0 + static_cast <double> (rand()) / (static_cast <double> (RAND_MAX / (99.0 - 0.0))); Money money(x, y); Adult _adult(name, age, money, pass_id, child_num); _adult.display(); for (int j = 1; j <= child_num; j++) { std::string name; int age = getRand(6, 17); name = (rand() % 56 != 5 ? NA1[rand() % 444] : NA2[rand() % 59]); name += (rand() % 2 == 1 ? ME1m[rand() % 140] : ME1f[rand() % 165]); if (rand() % 2 == 0) name += (rand() % 2 == 1 ? ME1m[rand() % 140] : ME1f[rand() % 165]); std::string pass_id = std::to_string(getRand(10000, 99999)); _adult.addChild(name, age, pass_id); } this->all_earned += _adult.buy_ticket(); _adult.buy_food(sold_person); _adult.addfood_child(animalenclosure); }
bool flag = false; for (int i = 1; i <= 3; i++) { if (!flag && !this->animalenclosure[i].isopen()) { this->animalenclosure[i].clean(); this->animalenclosure[i].open(); this->animalenclosure[i].add_day(); this->zookeeper.add(); flag = true; } } for (int i = 1; i <= 3; i++) { this->animalenclosure[i].work(); this->animalenclosure[i].isopen(); } this->all_earned.print(this->day); std::cout << "销售人员手里还有" << this->sold_person.animalfood.get_amount_food(1)<<"unit食物一" << " " << this->sold_person.animalfood.get_amount_food(2) << "unit食物二 " << this->sold_person.animalfood.get_amount_food(3)<<"unit食物三" << std::endl; for (int i = 1; i <= 3; i++) { std::cout << "居住场所" << i << "被清洁了" << this->animalenclosure[i].display_close_by_clean() << "天" << std::endl; } } } }
Money::Money() { this->cents = 0; this->dollars = 0; }
Money::Money(double _dollars, double _cents) { if (_cents > 100) { int x = int(cents / 100.0); _dollars += x; _cents -= x * 100; } this->dollars = _dollars; this->cents = _cents; }
Money::~Money() {}
std::ostream& operator<<(std::ostream& out, const Money& p) { out << "dollars" << ":" << p.dollars << " " << "cents" << ":" << p.cents; return out; }
Money operator+(const Money& A, const Money& B) { Money money(0.0, 0.0); money.dollars = A.dollars + B.dollars; money.cents = A.cents + B.cents; if (money.cents >= 100) { int x = int(money.cents / 100.0); money.dollars += x; money.cents -= x * 100.0; } return money; }
Money operator-(const Money& A, const Money& B) { Money money(0.0, 0.0); money.dollars = A.dollars - B.dollars; money.cents = A.cents - B.cents; if (money.cents < 0) { money.dollars -= 1; money.cents += 100.0; } return money; }
Money operator*(const Money& A, const Money& B) { Money money(0.0, 0.0); double y = B.dollars * 100 + B.cents; double x = A.dollars * 100 + A.cents; x *= y; if (x >= 100) { int c = x / 100.0; x -= 100 * c; y = c; money.dollars = y; money.cents = x; } else { money.dollars = 0; money.cents = x; }
return money; }
Money operator*(const double& A, const Money& B) { Money money(0.0, 0.0); money.dollars = B.dollars * A; money.cents = B.cents * A; if (money.cents >= 100) { int x = money.cents / 100; money.dollars += x; money.cents -= x * 100.0; } return money; }
double operator/ (const Money& A, const Money& B) { Money money(0.0, 0.0); Money temp(0.0, 0.0); money.cents = A.dollars * 100 + A.dollars; temp.cents = B.dollars * 100 + B.cents; double x = money.cents / temp.cents; return x; }
Money operator/(const double& A, const Money& B) { Money money(0.0, 0.0); money.dollars = B.dollars; money.cents = B.cents; money.dollars = money.dollars / A; money.cents = money.cents / A; if (money.cents >= 100) { int x = money.cents / 100.0; money.dollars += x; money.cents -= x * 100.0; } return money; }
Money& Money::operator+=(const Money& A) { this->dollars += A.dollars; this->cents += A.cents; if (this->cents >= 100) { int x = this->cents / 100.0; this->dollars += x; this->cents -= x * 100.0; } return *this; }
Money& Money::operator-= (const Money& A) { this->dollars -= A.dollars; this->cents -= A.cents; if (this->cents < 0) { this->dollars -= 1; this->cents += 100.0; } return *this; }
Money& Money::operator*=(const Money& A) { Money money(0.0, 0.0); Money temp(0.0, 0.0); money.cents = this->dollars * 100 + this->cents; temp.cents = A.dollars * 10 + A.cents; money.cents *= temp.cents; if (money.cents >= 100) { int x = money.cents / 100.0; money.dollars += x; money.cents -= x * 100.0; } *this = money; return *this; }
void Money::print(const int& k) { std::cout << "动物园截至到第" << k << "天的总收入为" << "Dollars" << this->dollars << ";" << "Cents" << this->cents << std::endl; }
AnimalFood::AnimalFood() { this->Foodtype[1] = "Peanuts"; this->Foodtype[2] = "Carrots"; this->Foodtype[3] = "Bananas"; this->amount[1] = 0; this->amount[2] = 0; this->amount[3] = 0; Price[1] = Money(0.0, 20.0); Price[2] = Money(0.0, 30.0); Price[3] = Money(0.0, 50.0); }
AnimalFood::~AnimalFood() {}
void AnimalFood::init() { this->Foodtype[1] = "Peanuts"; this->Foodtype[2] = "Carrots"; this->Foodtype[3] = "Bananas"; this->amount[1] = 10000; this->amount[2] = 7000; this->amount[3] = 4000; Price[1] = Money(0.0, 20.0); Price[2] = Money(0.0, 30.0); Price[3] = Money(0.0, 50.0); }
void AnimalFood::show() { std::cout << "Information " << ":" << std::endl; for (int i = 1; i <= 3; i++) { std::cout << "Foodtype " << i << ":" << this->Foodtype[i] << std::endl; std::cout << "Amount " << i << ":" << this->amount[i] << std::endl; std::cout << "Price " << i << this->Price[i] << std::endl; } }
void AnimalFood::add(const double& A, const double& B, const double& C) { this->amount[1] += A; this->amount[2] += B; this->amount[3] += C; }
void AnimalFood::_delete(const double& A, const double& B, const double& C) { this->amount[1] -= A; this->amount[2] -= B; this->amount[3] -= C; }
void AnimalFood::_init() { this->Foodtype[1] = "Peanuts"; this->Foodtype[2] = "Carrots"; this->Foodtype[3] = "Bananas"; this->amount[1] = 0; this->amount[2] = 0; this->amount[3] = 0; Price[1] = Money(0.0, 20.0); Price[2] = Money(0.0, 30.0); Price[3] = Money(0.0, 50.0); }
double AnimalFood::get_amount_food(const int& A) { return this->amount[A]; }
Money AnimalFood::get_Price_food(const int& k) { return this->Price[k]; }
std::string AnimalFood::get_Foodtye_food(const int& k) { return this->Foodtype[k]; }
AnimalEnclosure::AnimalEnclosure() {};
AnimalEnclosure::AnimalEnclosure(int _dirt_level, bool is, Animal _animal) { this->dirt_level = _dirt_level; this->isopen_close = is; this->close_day = 0; this->animal = _animal; }
AnimalEnclosure::~AnimalEnclosure() {}
int AnimalEnclosure::get_dirt_level() { return this->dirt_level; }
bool AnimalEnclosure::isopen() { if (this->dirt_level >= this->mosthighest_dirt) { this->isopen_close = false; return 0; } else { this->isopen_close = true; return 1; } }
void AnimalEnclosure::add(const int& A) { this->dirt_level = this->dirt_level + A; }
void AnimalEnclosure::clean() { this->dirt_level = 0; }
void AnimalEnclosure::add_day() { this->close_day++; }
void AnimalEnclosure::open() { this->isopen_close = true; }
void AnimalEnclosure::food_out() { if (animal.destory()) { this->add(animal.show_how_destory()); } }
void AnimalEnclosure::add_food(const double& A) { this->animal.add(A); }
int AnimalEnclosure::display_close_by_clean() { std::cout << "今天该动物园居住场所肮脏程度为" << this->dirt_level << std::endl; return this->close_day; }
void AnimalEnclosure::init(int diet_level, bool isopen_close, int close_day, Animal _animal) { this->dirt_level = diet_level; this->isopen_close = isopen_close; this->animal = _animal; this->close_day = close_day; }
void AnimalEnclosure::dispaly_of_food() { this->animal.display(); }
Animal::Animal() { this->weight = 0; this->food_eaten = 0; }
Animal::Animal(int _weight, double _food_eaten) { this->weight = _weight; this->food_eaten = _food_eaten; }
Animal::~Animal() {}
void Animal::add(const double& A) { this->food_eaten += A; }
bool Animal::destory() { if (this->food_eaten >= this->Capcity) { this->food_eaten = 0; return true; } else { return false; } }
double Animal::show_how_destory() { return this->risky; }
void AnimalEnclosure::work() { if (this->animal.destory()) { this->add(this->animal.show_how_destory()); } }
void Animal::display() { std::cout << "该动物的食量为" << this->food_eaten << std::endl; }
void Animal::play() { std::cout << "动物在表演" << std::endl; }
Elephant::Elephant() {}
Elephant::Elephant(int _weight, int _food_eaten, int _trunk_length, int _Capacity, double _risky) { this->weight = _weight; this->food_eaten = _food_eaten; this->trunk_length = _trunk_length; this->Capcity = _Capacity; this->risky = _risky; }
Elephant::~Elephant() {};
void Elephant::play() { std::cout << "大象在敲鼓" << std::endl; }
Giraffe::Giraffe() {}
Giraffe::Giraffe(int _weight, int _food_eaten, int _neck_length, int _Capacity, double _risky) { this->weight = _weight; this->food_eaten = _food_eaten; this->neck_length = _neck_length; this->Capcity = _Capacity; this->risky = _risky; }
Giraffe::~Giraffe() {}
void Giraffe::play() { std::cout << "长颈鹿在吃叶子" << std::endl; }
Monkey::Monkey() {}
Monkey::Monkey(int _weight, int _food_eaten, int _arm_length, int _Capacity, double _risky) { this->weight = _weight; this->food_eaten = _food_eaten; this->arm_length = _arm_length; this->Capcity = _Capacity; this->risky = _risky; }
Monkey::~Monkey() {}
void Monkey::play() { std::cout << "猴子在学人说话" << std::endl; }
Person::Person() { this->name = ""; this->age = 0; }
Person::Person(std::string _name, int _age) { this->name = _name; this->age = _age; }
Person::~Person() {}
Zookeeper::Zookeeper() { this->name = ""; this->age = 0; this->day_of_clean = 0; };
Zookeeper::Zookeeper(std::string _name, int _age, int _day_of_clean) { this->name = _name; this->age = _age; this->day_of_clean = _day_of_clean; }
void Zookeeper::add() { this->day_of_clean += 1; }
bool Zookeeper::close_by_clean() { if (this->day_of_clean >= highest_of_clean) { return 0; } else { return 1; } }
Sold_person::Sold_person() { this->name = ""; this->age = 0; }
Sold_person::Sold_person(std::string _name, int age) { this->name = _name; this->age = age; }
Sold_person::~Sold_person() {}
void Sold_person::init() { this->animalfood.init(); } void Sold_person::add_money(Money money) { this->money = this->money + money; }
bool Sold_person::is_open() { if (this->animalfood.get_amount_food(1) <= 0 || this->animalfood.get_amount_food(2) <= 0 || this->animalfood.get_amount_food(3) <= 0) { return 0; } else { return 1; } }
Visitor::Visitor() { this->name = ""; this->age = 0; this->pass_ID = ""; }
Visitor::Visitor(std::string& _name, int& _age, std::string& _pass_ID) { this->name = _name; this->age = _age; this->pass_ID = _pass_ID; }
Visitor::~Visitor() {}
std::string Visitor::show_ID()const { return this->pass_ID; }
Child::Child() { this->name = ""; this->age = 0; this->pass_ID = ""; }
Child::Child(std::string& name, int& age, std::string& _pass_ID) { this->name = name; this->age = age; this->pass_ID = _pass_ID; }
Child::~Child() {}
void Child::show_food_get() { this->food_get.show(); }
void Child::add(std::string& name, int& age, std::string& _pass_ID) { this->name = name; this->age = age; this->pass_ID = pass_ID; }
void Child::feed_animal(AnimalEnclosure animalEnclosure[4]) { for (int i = 1; i <= 3; i++) { if (animalEnclosure[i].isopen()) { animalEnclosure[i].add_food((i == 1) * this->food_get.get_amount_food(1) + (i == 2) * this->food_get.get_amount_food(2) + (i == 3) * this->food_get.get_amount_food(3)); this->food_get._delete((i == 1) * this->food_get.get_amount_food(1), (i == 2) * this->food_get.get_amount_food(2), (i == 3) * this->food_get.get_amount_food(3)); } else { std::cout << "清洁人员正在打扫" << "第" << i << "个动物居住区域" << std::endl; std::cout << "请下次再来光临" << std::endl; } } }
void Child::addfood(const double& x) { this->food_get.add(x, x, x); }
Money Child::show_ticket() { return this->ticket; }
void Child::init() { this->food_get._init(); }
Adult::Adult() { this->name = ""; this->age = 0; this->pass_ID = ""; };
Adult::Adult(std::string name, int age, Money money_have, std::string _pass_ID, int _cnt_child) { this->name = name; this->age = age; this->money = money_have; this->pass_ID = _pass_ID; this->cnt_Child = _cnt_child; }
Adult::~Adult() {}
void Adult::addChild(std::string& name, int& age, std::string& _pass_ID) { for (int i = 1; i <= cnt_Child; i++) { this->child[i].add(name, age, _pass_ID); this->child[i].init(); } }
void Adult::buy_food(Sold_person& sold_person) { Money money(0.0, 0.0); money = money + sold_person.animalfood.get_Price_food(1) + sold_person.animalfood.get_Price_food(2) + sold_person.animalfood.get_Price_food(3); double x = this->money / money; this->money = this->money - x * (money); this->allcoat(x); sold_person.animalfood._delete(x, x, x); sold_person.add_money(x * money);
}
void Adult::allcoat(const double& x) { for (int i = 1; i <= this->cnt_Child; i++) { this->child[i].addfood(x / this->cnt_Child); } }
Money Adult::buy_ticket() { Money money(0.0, 0.0); money = this->money - 1 * this->ticket - this->cnt_Child * this->child[1].show_ticket(); return (1 * this->ticket + this->cnt_Child * this->child[1].show_ticket()); }
void Adult::addfood_child(AnimalEnclosure animalenclosure[4]) { for (int i = 1; i <= this->cnt_Child; i++) { this->child[i].feed_animal(animalenclosure); } }
void Adult::display()const { std::cout << "-----------------------------------------------------------------------------" << std::endl; std::cout << "姓名是" << this->name << std::endl << "年龄是" << this->age << std::endl; std::cout << "一共有" << this->cnt_Child << "个孩子" << std::endl; std::cout << this->money << std::endl; std::cout<<"通行ID是" << this->pass_ID << std::endl; std::cout << "-----------------------------------------------------------------------------" << std::endl; }
void doplay(Animal& animal) { animal.play(); }
|