描述
代码填空,使得程序能够自动统计当前各种动物的数量
#include <iostream> using namespace std;// 在此处补充你的代码void print() { cout << Animal::number << " animals in the zoo, " << Dog::number << " of them are dogs, " << Cat::number << " of them are cats" << endl; } int main() { print(); Dog d1, d2; Cat c1; print(); Dog* d3 = new Dog(); Animal* c2 = new Cat; Cat* c3 = new Cat; print(); delete c3; delete c2; delete d3; print(); }输入
无
输出
0 animals in the zoo, 0 of them are dogs, 0 of them are cats
3 animals in the zoo, 2 of them are dogs, 1 of them are cats
6 animals in the zoo, 3 of them are dogs, 3 of them are cats
3 animals in the zoo, 2 of them are dogs, 1 of them are cats样例输入
None样例输出
0 animals in the zoo, 0 of them are dogs, 0 of them are cats 3 a
002:编程填空:统计动物数量
最新推荐文章于 2023-12-08 15:34:00 发布
该编程问题旨在通过多态特性来统计动物园中不同动物的数量。程序根据输入展示不同动物种类及其数量,强调了在基类析构函数使用virtual关键字的重要性以及静态成员变量的定义和内存分配。
摘要由CSDN通过智能技术生成