c++高手进!!!
发布网友
发布时间:2023-05-03 09:59
我来回答
共4个回答
热心网友
时间:2023-06-25 13:10
#include<iostream>
using namespace std;
class AreaClass
{
public:
virtual double Area()=0;
protected:
double height;
double width;
};
class Rectangle :public AreaClass
{
public:
Rectangle(double h,double w)
{
height=h;width=w;
}
double Area()
{
return height*width;
}
};
class Isosceles :public AreaClass
{
public:
Isosceles(double h,double w)
{
height=h;width=w;
}
double Area()
{
return height*width/2;
}
};
int main()
{
Rectangle re(3,5);
Isosceles is(4,6);
AreaClass *pp;
pp=&re;
cout<<pp->Area()<<endl;
pp=&is;
cout<<pp->Area()<<endl;
}
热心网友
时间:2023-06-25 13:11
class Rectangle :public AreaClass
{
public:
double Area()
{return height*width;}
protected:
double height;
double width;
}
class Isosceles :public AreaClass
{
public:
double Area()
{return height*width/2;}
protected:
double height;
double width;
}
热心网友
时间:2023-06-25 13:11
class Rectangle : private AreaClass
{
public:
Rectangle(double h,double w)
{
height=h;
width=w;
}
~Rectangle();
double area()
{
retrun height*width;
}
}
自己也动手学着写下,别老全部抄别人的。
热心网友
时间:2023-06-25 13:12
你自己不会加入控制台输入啊 !!