自考新教材p132
Posted bobo哥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自考新教材p132相关的知识,希望对你有一定的参考价值。
源程序:
#include <iostream>
using namespace std;
class myComplex
{
private:
double real, imag;
public:
myComplex();
myComplex(double r, double i);
myComplex addCom(myComplex c);
void outCom();
};
myComplex::myComplex()
{
real = 0;
imag = 0;
}
myComplex::myComplex(double r, double i)
{
real = r;
imag = i;
}
myComplex myComplex::addCom(myComplex c)
{
return myComplex(this->real + c.real, this->imag + c.imag);
}
void myComplex::outCom()
{
cout << "(" << real << "," << imag << ")";
}
int main()
{
myComplex c1(1, 2), c2(3, 4), res;
res = c1.addCom(c2); //c1+c2
c1.outCom();
cout << "+";
c2.outCom();
cout << "=";
res.outCom();
cout << endl;
return 1;
}
以上是关于自考新教材p132的主要内容,如果未能解决你的问题,请参考以下文章