qq_34265777 于 2016.03.12 18:08 提问

#include "stdafx.h"
#include
#include

class complex
{
private:
double x,y,m,a,b,b2;

public:
complex(double xx=0,double yy=0){x=xx;y=yy;};
void Set1(double m){m=16*x*x+16*y*y;};
void Set2(double b2){b2=(-4*x+sqrt(m))/8;};
void Set3(double a){a=y/(2*sqrt(b2));};
void Set4(double b){b=sqrt(b2);};
void Show(){cout<<a<<"+"<<b<<"i";};

};

//int main(int argc, char* argv[])
int main()
{ complex z1(3,4);
z1.Show();

``````return 0;
``````

}

4个回答

bullzerone   2016.03.12 20:37

qq_34265777 怎么调用后面的函数啊？跪求指教~

bealing   2016.03.12 20:48

z1.Show();，输出的a，b还没有通过方法计算出来，你要调用那些方法把a,b计算出来然后在输出

qq_34265777 是要给a和b一个初始值吗？

qq_34265777 是要给a和b一个初始值吗？

qq_34265777 能说一下怎么把a,b计算出来吗？我刚刚接触，不太明白，拜托~

wangtiewei   2016.03.12 22:19

bealing   2016.03.12 22:40
`````` class complex
{
private:
double x,y,m,a,b,b2;
public:
complex(double xx=0,double yy=0){x=xx;y=yy;};
void Set1(){m=16*x*x+16*y*y;};
void Set2(){b2=(-4*x+sqrt(m))/8;};
void Set3(){a=y/(2*sqrt(b2));};
void Set4(){b=sqrt(b2);};
void Show(){cout<<a<<"+"<<b<<"i";};
};
//int main(int argc, char* argv[])
int main()
{ complex z1(3,4);
z1.Set1();
z1.Set2();
z1.Set3();
z1.Set4();
z1.Show();
return 0;
}
``````
qq_34265777 谢谢大神帮忙~感激不尽~