全国2006年10月高等教育自学考试
private:
float real, imag;
public:
Complex(float r=0, float i=0 ) { real=r; imag=i;}
void Display(){
cout << real;
if (imag>0) cout<<"+"<<imag<<"i" ;
else if (imag<0) cout<<imag<<"i" ;
cout << endl;
}
Complex operator+ (Complex &b );
friend Complex operator- ( Complex &a, Complex &b );
};
Complex Complex::operator+ (Complex &b)
{
Complex *t = new Complex ( ①________ );
return *t;
}
Complex operator- ( Complex &a, Complex &b )
{
Complex *t = new Complex ( ②________ );
return *t;
}
void main()
{
Complex c1(4.0,5.0),c2(2.0,-5.0),c3;
c3=c1+c2;
c3.Display();
c3=c1-c2;
c3.Display();
}
五、程序分析题(本大题共6小题,每小题5分,共30分)
31.写出下面程序的输出结果。
#include <iostream.h>
#include<iomanip.h>
int i=1;
void other(void)
{
static int a=2, b;
int c=10;
a=a+1; i=i+3; c=c+5;
cout<<setw(5)<<i<<setw(5)<<a<<setw(5)<<b<<setw(5)<<c<<endl;
b=a;
}
void main(void)
{
static int a;
int b=-5, c=0;
════════════════════════════════════════════════════════════════════
- 本套试题共分8页,当前页是第6页-