楼上的是个C#的例子,我简单的写个C++的例子吧,你可以参照一下
abstract class Shape
{
public virtual double area();
public virtual double perimeter();
public virtual double display();
}
class Circle:Shape
{
public double area();
public double perimeter();
public double display();
}
貌似我给的不是C#吧,我没记错的话好象是JAVA哦,还有我定义抽象类的时候少了关键字class了,呵呵,应该是abstract class Shape
为什么我不能回答呢?
1. interface Shape
{
public abstract double area();
public abstract double perimeter();
public abstract double display();
}
2. class Circle implements Shape
{
int x;//横坐标
int y;//纵坐标
double a;//半径
public Circle (int x,int y,double a)//构造函数
{
this.x=x;
this.y=y;
this.a=a;
}
public double area()
{
return 3.14*a*a;
}
public double perimeter()
{
return 2*3.14*a;
}
public void display()
{
System.Out.println("此圆的圆心为a("+this.x+","+this.y+")");
System.Out.println("此圆的半径为r="+this.a);
}
}
3. 4. 就不写了,与圆类似,就多了个drow()函数,你可以去找找这个函数的实现
5. public static void main(String[]args)throws IOException
{
Circle C=new Circle(2,3,5);
System.out.println("所求圆的面积S="+C.area());
System.out.println("所求圆的周长L="+C.perimeter());
C.display();
//其他的测试一样
}