问题 填空题

请补充main函数,该函数的功能是求方程ax2+bx+c=0的根(方程的系数a,b,c从键盘输入)。
例如, 当a=1,b=2,c=1时, 方程的两个根分别是:
x1=-1.00,x2=-1.00。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#include <conio.h>
#include <math.h>
main()

float a,b,c,disc,x1,x2,p,q;
scanf("%f,%f,%f",&a,&b,&c);
disc=b*b-4*a*c;
clrscr();
printf("****** the result ****+*+\n");
if(disc>=0)

x1= 【1】
x2=(-b-sqrt(disc))/(2*a);
printf("x1=%6.2f,x2=%6.2f\n",x1,x2);

else

p= 【2】
q= 【3】
printf("x1=%6.2f+%6.2f i\n",p,q);
printf("x2=%6.2f-%6.2f i\n",p,q);

答案

参考答案:【1】(-b+sqrq(disc))/(2*a)
【2】-b/(2*a)
【3】sqrt(fabs(disc))/(2*a)

解析:[*]

填空题
问答题

使用VC6打开考生文件夹下的工程test32_3。此工程包含一个test32_3.cpp,其中定义了复数类complex,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。
(1)定义复数类complex的私有数据成员real和image,用来分别表示复数的实部和虚部,它们都是double型的数据。请在注释“//**1**”之后添加适当的语句。
(2)添加复数类complex的带一个参数的构造函数,分别将real和image赋值为参数r的值和0.0,请在注释“//**2**”之后添加适当的语句。
(3)完成复数类complex的“+”运算符重载成员函数的定义,两个复数相加是将复数的实部和虚部分别进行相加,请在注释“//**3**”之后添加适当的语句。
(4)完成复数类complex的友元函数isequal(complex *cl,complex *c2)的定义,如果复数c1与c2相等即c1与c2的实部和虚部分别相等,则返回1,否则返回0。请在注释“//**4**”之后添加适当的语句。
程序输出结果如下:
36+0i=36+0i
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
源程序文件test32_3.cpp清单如下:
#include <iostream.h>
class complex

//** 1 **
public:
complex()real=image=O.O;
complex(double r)

//** 2 **

complex operator+(const complex &c);
friend bool isequal(complex *c1,complex *c2
void display();
;
complex complex::operator+(const complex &c)

//** 3 **
temp.real=real+c.real;
temp.image=image+c.image;
return temp;

bool isequal(complex *c1,complex *c2)

/ /** 4 **
return 1;
else
return 0;

void complex:: display()

cout<<real;
if (image>=0) cout<<"+"<<image<<"i";
else if (image<0) cout<<image<<"i";

void main()

complex c1,c2(36.0);
c1=c1+c2;
c1.display();
if (isequal(&c1,&c2)) cout<<"=";
else coat<<"<>";
c2.display();
cout<<end1;