#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這一天是屬於我的!