1. 程式人生 > >c++筆記之資料型別轉換

c++筆記之資料型別轉換

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