6.13

#include<iostream>
using namespace std;
class Base
{
	double h;
public:
	Base(double a)
	{h=a;}
	virtual void disp()=0;
double Getterh()
	{return h;}
};

class Cuboid:public Base
{
	double chuang;
	double kuang;
public:
	Cuboid(double a,double b,double c):Base(a)
	{chuang=b;
	kuang=c;
	}
	void disp()
	{
		cout<<"高为:"<<Getterh()<<"  "<<"长为"<<chuang<<"  "<<"宽为"<<kuang<<" "<<"的长方体体积:"<<chuang*kuang*Getterh()<<endl;
	}
};
class Cylinder:public Base
{
	double r;
public:
	Cylinder(double a,double b):Base(a)
	{r=b;}
	void disp()
	{
		cout<<"底面半径为"<<r<<"  "<<"高为"<<Getterh()<<"   "<<"的圆柱体体积为:"<<3.14*r*r*Getterh()<<endl;
	}
};
int main()
{
	Base* p;
	Cuboid a(10.0,5.0,6.0);
	Cylinder b(5.0,1.0);
     p=&a;
	 p->disp();
     p=&b;
	  p->disp();
	  return 0;
}

<img src="https://img-blog.csdn.net/20150502200710075?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHVhbmdjaG9uZ3dlbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" align="bottom" alt="" />

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值