📄 1051107547-q2.txt
字号:
//Muhammad 'Ifwan B. Md Jalal
//1051107547
//tutorial4b
#include <iostream>
using namespace std;
//create class complex
class Complex {
public:
Complex()
{
real = 0; //initialized real value to 0
imag = 0; //initialized imaginary value to 0
};
Complex(double a, double b)
{
real = a;
imag = b;
};
void addCom(Complex c1, Complex c2); //declare member function addCom
void subCom(Complex c1, Complex c2); //declare member function subCom
void print() {cout << "(" << real << "," << imag << ")" << endl;}; //declare member function of print()
private:
double real, imag; //declare variable
};
void Complex::addCom(Complex c1, Complex c2)
{
real = c1.real + c2.real;
imag = c1.imag + c2.imag;
};
void Complex::subCom(Complex c1, Complex c2)
{
real = c2.real - c1.real;
imag = c2.imag - c1.imag;
};
//call all the member function
void main ()
{
Complex i1(3,5), i2(5,2), i3;
cout << "i1 is ";
i1.print();
cout << "while i2 is ";
i2.print();
cout << endl;
i3.addCom(i1,i2);
i3.print();
i3.subCom(i1,i2);
i3.print();
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -