原文链接:
- 自动车
- 手动车:https://codeeggs.github.io/2021/05/15/2021.05.15%E7%BB%A7%E6%89%BF%E7%90%83%E4%BD%93%E5%92%8C%E5%9C%86%E6%9F%B1%E4%BD%93/
题目:
编写程序,定义抽象基类Container,由此派生出2个派生类球体类Sphere,圆柱体类Cylinder,分别用虚函数分别计算表面积和体积。(不要更改主程序)
int main()
{
Container *ptr;
Sphere s(5);
ptr=&s;
cout<<"The area of sphere is "<<ptr->area()<<endl;
cout<<"The colume of sphere is "<<ptr->volume()<<endl;
Cylinder c(3,7);
ptr=&c;
cout<<"The area of cylinder is "<<ptr->area()<<<