php定义一个矩形类rectangle,c#定义一个类圆Circle或者定义一个矩形类Rectangle,分别计算它们的周长和面积....
时间: 2024-02-21 10:56:57 浏览: 34
PHP定义一个矩形类Rectangle:
```
class Rectangle {
public $length;
public $width;
function __construct($length, $width) {
$this->length = $length;
$this->width = $width;
}
function getArea() {
return $this->length * $this->width;
}
function getPerimeter() {
return 2 * ($this->length + $this->width);
}
}
```
C#定义一个类圆Circle:
```
class Circle {
public double radius;
public Circle(double radius) {
this.radius = radius;
}
public double GetArea() {
return Math.PI * radius * radius;
}
public double GetCircumference() {
return 2 * Math.PI * radius;
}
}
```
C#定义一个矩形类Rectangle:
```
class Rectangle {
public double length;
public double width;
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
public double GetArea() {
return length * width;
}
public double GetPerimeter() {
return 2 * (length + width);
}
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)