2、编写程序,声明一个基类shape,再派生出一个retangle和circle类, 二者都有getarea()函数,计算对象
2个回答
展开全部
class Shape
{
public:
virtual double getArea() =0;
};
class Rectangle
{
public:
virtual double getArea(){//具体实现请自己实现}
};
class Circle
{
public:
virtual double getArea(){//具体实现请自己实现}
};
{
public:
virtual double getArea() =0;
};
class Rectangle
{
public:
virtual double getArea(){//具体实现请自己实现}
};
class Circle
{
public:
virtual double getArea(){//具体实现请自己实现}
};
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public abstract class shape{
public abstract double getarea();
}
class circle extends shape{
final double PI=3.14;
private double radius;
public double getRadius(){
return this.radius;
}
public setRadius(dobule r){
this.radius = r;
}
public double getarea(){
return PI*radius*radius;
}
}
class rectangle extends shape{
private double length ;
private double width;
public double getLength (){
return this.length;
}
public setLength(double len){
this.length = len;
}
public double getWidth (){
return this.width;
}
public setWidth(double w){
this.width = w;
}
public double getarea(){
return length*width;
}
}
public abstract double getarea();
}
class circle extends shape{
final double PI=3.14;
private double radius;
public double getRadius(){
return this.radius;
}
public setRadius(dobule r){
this.radius = r;
}
public double getarea(){
return PI*radius*radius;
}
}
class rectangle extends shape{
private double length ;
private double width;
public double getLength (){
return this.length;
}
public setLength(double len){
this.length = len;
}
public double getWidth (){
return this.width;
}
public setWidth(double w){
this.width = w;
}
public double getarea(){
return length*width;
}
}
追问
应该不是这么复杂,要用C++写的啊!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询