填空题分析以下程序的执行结果______。 #include<iostream.h> class Sample int x,y; public: Sample()x=y=0; Sample(int a,int b)x=a;y=b;) ~Sample() if(x==y) cout<<"x=y"<<end1; else cout<<"x!=y"<<end1; void disp() cout<<"x="<<x<<",y="<<y>>end1; ; void main() Sample s1(2,3); s1.disp();
填空题根据程序中的注释将下列缺失部分补充完整。
class A{
char*a;
public:
A():a(0){}
A(char*aa){//把aa所指字符串复制给a所指向的存储空间
a=______;
strcpy(a,aa);
}
~A(){delete[]a;}
};
填空题请将如下程序补充完整,使得输出结果为:bbaa。 #include<iostream> using naluespace std; class A public: ______eout<<"aa"; ; class B:public A public: ~B( )eont<<"bb"; ; int ulain( ) B*P=new B; delete P; return 0;
填空题void类型的指针是指指针指向的变量的数据类型是不固定的。对该指针进行操作时,应进行 【10】 。
填空题下面程序的功能是将字符数组a中下标值为偶数的元素从小到大排列,其他元素不变,请填空。 #include<iostream.h> #include<string.h> void main( ) char a[ ]="clanguage",t; int i,j,k; k=strlen(A) ; for(i=;0 i < =k-2;i+=2= for(j=i+2;j < =k; 【9】 = if ( 【10】 ) t=a[i];a[i]=a[j];a[j]=t; cout < < a; cout < < end1;=
填空题在下面程序横线处填上适当内容,以使该程序执行结果为:
25 24 23 22 21
0 7.5 6.4 5.3 4.2 3.1
#include <iostream>
using namespace std;
template<class T>
void f(______){
______;
for(int i=0;i<n/2;i++)
t=a[i],a[i]=a[n-1-i],a[n-1-i]=t;
}
int main()
{
int a[5]={21,22,23,24,25};
double d[6]={3.1,4.2,5.3,6.4,7.5};
f(a,5);f(d,6);
for(int i=0;i<5;i++) cout<<a[i]<<"";
cout<<endl;
for(i=0;i<6;i++) cout<<d[i]<<"";
Cout<<endl;
return 0;
}
填空题已知下列程序的输出结果是42,请将画线处缺失的部分补充完整。
#include <iostream>
using namespace std;
class Foo {
int value;
public:
Foo 0=:value(0) {}
void setValue(int value)
{{{U}} 【10】 {{/U}}= value; }//给Foo的数据成员value赋值
void print() { cout << value; }
};
int main()
{
Foo f;
f.setValue(42);
f.print();
return();
}
填空题“图形”类Shape中定义了纯虚函数CalArea(),“三角形”类Triangle继承了类Shape,请将Triangle类中的CalArea函数补充完整。
class Shape{
public:
virtual int CalArea()=0;
}
class Triangle: public Shape{
public:
Triangle{int s, int h}: side(s),height(h) {}
{{U}}【12】{{/U}} { return side*height/2 ; }
private:
int side;
int height;
};
填空题下列程序在构造函数和析构函数中申请和释放类的数据成员int * a,申请时使用形参b初始化a,请填空。
class A
{
public:
A(int b) ;
~A( ) ;
private:
int * a;
};
A: :A(int b)
{
{{U}} 11 {{/U}};
}
A: :~A( )
{
{{U}} 12 {{/U}};
}
填空题请按下面注释的提示,将类B的构造函数定义补充完整。 classA int a; public: A(int aa=0) a=aa;) ; Class B:public A int b; A c; public: //用aa初始化基数A,用aa+1初始化类对象成员c B(int aa): (b=aa+2) ;
填空题使用VC++6.0打开考生文件夹下的源程序文件1.cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,输出的结果为 Constructor,i=0, Destructor 注意:错误的语句在//******error******的下面,修改该语句即可。 试题程序: #include<iostream.h> class TC int i; public: TC(); void display(); ~TC(); ; //******error****** TC:TC() cout<<"Constructor"<<","; i=0; //******error****** TC:display() cout<<"i="<<i<<","<<end1; //******error****** TC:TC() cout<<"Destructor"<<end1; void main() TC a; a.display();
填空题下列函数的功能是判断字符串str是否对称,对称则返回true,否则返回false。请在横线处填上适当内容,实现该函数。 bool fun(char *str) int i=0,j=0; while(str[j])______; for(j--;i<j i++,j--); return i______j;
填空题调用时不必提供参数的构造函数称为__________构造函数。
填空题若需要定义一个标识符常量,并且使得C++能够进行类型检查,则应在定义语句的开始使用保留字{{U}} 【10】 {{/U}}。
填空题下面程序的执行结果是______。
#include<iostream>
#include<iomanip>
using namespace std;
void main(){
cout<<setfill("x")<<setw(10)<<"Hello"<<endl;
}
填空题下列程序的运行结果为______。
#include<iostream.h>
void main( )
{
int i;
for(i=1;i<6;i++)if(i==3)break;
cout<<"i="<<i<<endl;
}
填空题有以下面程序: #include <iostream> using namespace std; long fib(int n) if (n>2) return (fib(n-1)+fib(n-2)); else return 2; int main() cout<<fib(3)<<endl; return 0; 则该程序的输出结果应该是 【12】 。
填空题下列程序运行后的输出结果是______。
#include <iostream.h>
void fun(int,int,int*);
void main()
{
int x,y,z;
fun(5,6,
fun(7,x,
fun(x,y,
cout<<x<<","<<y<<","<<z<<endl;
}
void fun(int a,int b,int *c)
{
b+=a;
*c=b-a;
}
填空题语句cout<<setiosflagags(ios::showpos)<<125<<"/t"<<-125<<endl;的输出结果为
________
。
填空题使用VC6打开考生文件夹下的工程test4_1,此工程包含一个源程序文件test4_1.cpp,但该程序在类的定义中存在问题,请改正类定义中的错误,使程序的输出结果如下: a=3 b=13 a=5 b=13 注意:请勿修改主函数main中的任何内容。 源程序文件rcst4_1.cpp清单如下: #include<iostream.h> class T public: /*********found***+******/ T(int x)a=x; b+=x;) /+********found**********/ void display(T c) cout<<"a="<<c.a<<"/t"<<"b="<<c.b<<endl;) private: const int a; static int b; ; /**********found*********/ int b=5; void main() T A(3),B(5); T::display(A); T::display(B);
