建立一个复数类 Complex,具体内容不限,但必须实现以下功能: a. 含两个私有数据成员:实部real, 虚部img,都是float类型 b.分别用函数实现复数的构造、数据修改、显示复数、复数之间的复制、比较两个复数是否相等
时间: 2024-05-22 12:14:41 浏览: 62
class Complex:
def __init__(self, real, img):
self.real = real
self.img = img
def set_real(self, real):
self.real = real
def set_img(self, img):
self.img = img
def get_real(self):
return self.real
def get_img(self):
return self.img
def display(self):
if self.img >= 0:
print(f"{self.real}+{self.img}i")
else:
print(f"{self.real}{self.img}i")
def copy(self):
return Complex(self.real, self.img)
def is_equal(self, other):
if self.real == other.real and self.img == other.img:
return True
else:
return False
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)