填空题类Base、Component和Derived的定义如下,请将横线处缺失部分补充完整。
class Base{
double data;
public:
Base(double d):data(d){ }
};
class Component{
int data;
public:
Component(int d):data(d){ }
};
class Derived:public Base{
Component com;
char character;
public:
Derived(double a,int b,char c):
//使用参数a初始化基类成员,使用参数b初始化成员对象com
______,character(c){}
};
填空题诊断和改正程序中错误的工作通常称为 【3】 。
填空题设有定义语句:int a=12;,则表达式a*=2+3的运算结果是【 】。
填空题以下程序的输出结果是 。 #include<iostream.h> class object private: int val; public: object( ) ; object(int i) ; ~object( ) ;; object: :object( ) val=0; cout < < "Default constructor for object" < < endl; object: :object(int i) val=i; cout < < "Constructor for object" < < val < < endl; object: :~object( ) cout < < "Destructor for object" < < val < < endl; class container private: object one; object two; int data; public: container( ) ; container(int i,int j,int k) ; ~container( ) ;; container: :container( ) data=0; cout < < "Default constructor for container" < < endl; container: :container(int i,int j,int k) :two(i) ,one(j) data=k; cout < < "Constructor for container" < < endl; container: :~container( ) cout < < "Destructor for container" < < endl; void main( ) container anObj(5,6,10) ;
填空题若要把类 FriendClass 定义为类 MyClass 的友元类,则应在类 MyClass 的定义中加入语句{{U}} {{U}} {{/U}} {{/U}}。
填空题以下程序的输出结果是 [9] 。 #include<iostream. h> viod main() char sl[5]= "ABCD", s2=[5]; int k; for(k=0;k<4:k++) s2[k]=(sl[k]- '0' +1) + '0' ; s2[k]= '/0' ; cout<<s2;
填空题有以下程序: #include <iostream.h> #include <fstream.h> #include <stdlib.h> int main() fstream filel,file2; char line[100]; filel.open("source.txt",ios::in); if(!file1) cout<<"Can't open file source.txt!"<<end1; abort(); file2.open("dest.txt",ios::out); if(!file2) cout<<"Can't open file dest.txt!"<<end1; abort(); while(!file1.eof()) filel.getline(1ine,100); file2<<line; file2<<end1; filel.close(); file2.close(); return 0; 此程序实现的功能是 【15】 。
填空题常数据成员和静态数据成员在使用前共同的要求是要进行{{U}} 【11】 {{/U}}。
填空题继承与 [2] 机制,是面向对象程序中实现重用的主要手段。
填空题下列程序编译错误,因为add函数返回值是一个引用,故对return后返回值的要求是{{U}} {{/U}}。 #include<iostream. h> int void main( ) int i=3,j=19; cout<<(add(i,j)+ =20)<<end1;
填空题在下面函数的横线处填上适当的内容,使该函数能够利用递归方法求解字符串str的长度 (不得使用系统提供的字符串处理函数)。 int GetLen(char*str) if(______)return ______; else return 1+GetLen(str+1);
填空题有以下程序:
#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)<<end1;
return 0;
}
则该程序的输出结果应该是{{U}} 【12】 {{/U}}。
填空题要采用“cin,tout”进行输入输出时,必须包含的头文件是 【14】 。
填空题输出带引号的字符串“hello world!”的语句是 【14】 。
填空题重载的流运算符函数应该被定义为类的 【7】 函数。
填空题冒泡排序算法在最好的情况下的元素交换次数为{{U}} 【1】 {{/U}}。
填空题下面是复数类complex的定义,其中作为友元函数重载的运算符“--”的功能是将参数对象的实部减1,然后返回对该对象的引用;请补充完整。 class complex private: int real; int imag; public: complex(int r=0,int i=0):real(r),imag(i) void show () cout<<real<<(imag<0?"-":"+")<<imag<<'i'; ______; ; complex return c;
填空题下列程序的执行结果是{{U}} 【12】 {{/U}}。
#include<iostream. h>
class Student
{
public:
Student(int xx){x=xx;}
virtual float calcFuition( );
protected:
int x;
}
float Student:: calcTuition()
{
return float(x* x)
class GraduateStudent:public Student
{
public:
GraduateStudent(int xx) :Student(xx) {}
float calcTuition( )
};
float GraduateStudent:: calcTuition( )
{
return float(x * 2);
}
void main( )
{
Student s(20);
GraduateStudent gs(30);
cout<<s.calcTuition()<<" "<<gs. calcTuition()==end1;
//计算学生s和研究生gs的学费
}
填空题通过使用new和delete两个运算符进行的分配为【 】存储分配。
填空题有以下程序:
#include<iostream.h>
classA
{
int x;
public:
A(int A)
{
x=a;
}
friend class B;
};
class B{
public:
void print(AA) {
a.x--;
cout<<a.x<<end1;
}
};
void main()
{
Aa(10);
Bb;
b.print(A) ;
}
程序执行后的输出结果是{{U}} 【14】 {{/U}}。
