版权声明:虽然写的很菜,但我也是有版权的! https://blog.csdn.net/weixin_42093825/article/details/82866726
#include <iostream>
#include <string>
using namespace std;
class Complex
{
public:
Complex() //默认构造函数
{
real = 0;
imag = 0;
}
Complex(double r) //转换构造函数,double转换成Complex
{
real = r;
imag = 0;
}
Complex(double r, double i) //用于初始化的构造函数
{
real = r;
imag = i;
}
friend Complex operator+(Complex c1, Complex c2);
void display();
private:
double real;
double imag;
};
#include "pch.h"
#include <iostream>
#include "Complex.h"
using namespace std;
void Complex::display()
{
cout << "(" << real << "," << imag << "i)" << endl;
}
Complex operator +(Complex c1, Complex c2)
{
return Complex(c1.real + c2.real, c1.imag + c2.imag);
}
#include "pch.h"
#include <stdio.h>
#include <iostream>
#include "Complex.h"
#include <cstring>
using namespace std;
int main()
{
Complex c1(3, 4), c2(5, -10), c3;
c3 = 1.5+c1;
c3.display();
system("pause");
return 0;
}
现在的排名是111万
睡了一早上懒觉的我现在活力满满
927这一天是属于我的!