在Java中getarea是什么意思,需要有关getArea()函数的帮助

在Java中getarea是什么意思,需要有关getArea()函数的帮助

我正在尝试使用现有数据(半径,宽度和高度)计算圆和矩形的面积 . 但我有一些错误,我希望你能帮助我解决它 .

#include

#include

#include

using namespace std;

class Shape

{

public:

virtual void Draw () = 0;

virtual void MoveTo (int newx, int newy) = 0;

virtual int GetArea()const = 0;

};

class Rectangle : public Shape

{

public:

Rectangle (int x, int y, int w, int h);

virtual void Draw ();

virtual void MoveTo (int newx, int newy);

int GetArea() {return height * width;}

private:

int x, y;

int width;

int height;

};

void Rectangle::Draw ()

{

cout << "Drawing a Rectangle at (" << x << "," << y

<< "), width " << width << ", height " << height << "\n";

};

void Rectangle::MoveTo (int newx, int newy)

{

x = newx;

y = newy;

}

Rectangle::Rectangle (int initx, int inity, int initw, int inith)

{

x = initx;

y = inity;

width = initw;

height = inith;

}

class Circle : public Shape

{

public:

Circle (int initx, int inity, int initr);

virtual void Draw ();

virtual void MoveTo (int newx, int newy);

int GetArea() {return 3.14 * radius * radius;}

private:

int x, y;

int radius;

};

void Circle::Draw ()

{

cout << "Drawing a Circle at (" << x << "," << y

<< "), radius " << radius <

}

void Circle::MoveTo (int newx, int newy)

{

x = newx;

y = newy;

}

Circle::Circle (int initx, int inity, int initr)

{

x = initx;

y = inity;

radius = initr;

}

int main ()

{

Shape * shapes[2];

shapes[0] = new Rectangle (10, 20, 5, 6);

shapes[1] = new Circle (15, 25, 8);

for (int i=0; i<2; ++i) {

shapes[i]->Draw();

shapes[i]->GetArea();

}

return 0;

}

相关推荐

日常工作和商务合作的电子邮件格式及示例
bet28365365娱乐场

日常工作和商务合作的电子邮件格式及示例

📅 07-06 👁️ 4766
ppt中如何录制旁白(如何为ppt录制旁白)
365bet繁体中文

ppt中如何录制旁白(如何为ppt录制旁白)

📅 06-27 👁️ 8299
手机录像软件排行榜
365beat网址

手机录像软件排行榜

📅 07-05 👁️ 1019
流通貨幣列表
365beat网址

流通貨幣列表

📅 06-29 👁️ 8360
流殇是什么意思,流殇和流觞
365beat网址

流殇是什么意思,流殇和流觞

📅 07-11 👁️ 9921