#include<iostream>
using namespace std;
class CComplex //类名以大写C开头
{
double m_real;
double m_image;
public:
CComplex()
{
m_real = 0;
m_image = 0;
}
CComplex(double r, double i)
{
m_real = r;
m_image = i;
}
void setInfo(double real, double image)
{
m_real = real;
m_image = image;
}
void show()
{
if (m_image >= 0)
cout << m_real << "+" << m_image << "*i" << endl;
else
cout << m_real << "-" << -1 * m_image << "*i" << endl;
}
};
要点
int main()
{
CComplex c1;
c1.setInfo(-3.5,-4.7);
c1.show();
CComplex c2=c1; //两者不合用内存
c2.show();
c2.setInfo(4,6);
c2.show();
c1.show();
return 0;
}