极坐标形式的复数计算器

任务

《电路理论》中相量法常需进行极坐标形式复数的运算,计算器上没有直接的计算方式,需要记录很多运算结果,往往很复杂。
C++备考时对运算符的重载掌握比较薄弱,一直没有练习的机会,因此决定实现极坐标形式复数类的计算。

已有

  • C++运行环境
  • 复数运算规则

代码实现

/****Complex_p.h****/
#pragma once
#include<iostream>
#include<math.h>
#define PAI 3.1415926
using namespace std;
class Complex
{
   
public:
 Complex();    //constructor without parameter
 Complex(double);      //constructor with one parameter
 Complex(double,double);  //constructor with two parameters
 inline void operator =(const Complex& c)//重载双目运算符赋值
 {
   
  r = c.r;
  a = c.a;
 }
 inline void operator +=(Complex c)//重载双目运算符加赋值
 {
   
  *this = *this + c;
 }
 inline void operator -=(Complex c)//重载双目运算符减赋值
 {
   
  *this = *this - c;
 }
 Complex operator -()const;//重载单目运算符减
 friend Complex operator+(Complex& c1, Complex& c2);//重载双目运算符加
 friend Complex operator-(Complex& c1, Complex& c2);//重载双目运算符减
 friend Complex operator/(Complex& c1, Complex& c2);//重载双目运算符除
 friend Complex operator*(Complex& c1, Complex& c2);//重载双目运算符乘
 friend istream& operator>>(istream& is, Complex& c);//输入
 <
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值