填空题非成员函数应该声明为类的______函数才能访问该类的私有成员。
填空题下列程序运行后的输出结果是______。 #include <iostream.h> void main() int s=0,k; for(k=7;k>=0;k--) switch (k) case 1: case 4: case 7: s++;break; case 2: case 3: case 6: break; case 0: case 5: s+=2;break;
填空题声明长度为10的float型数组a,且初始化为0的语句是
________
。
填空题如下程序定义了“单词”类word,类中重载了<运算符,用于比较“单词”的大小,返回相应的逻辑值。程序的输出结果为:After Sorting:Happy Welcome,请将程序补充完整。
#include<iostream>
#include<string>
using namespace std;
class Word{
public:
Word(strings):str(s){ }
string getStr( ){return str;}
______const{return(str<w.str);}
friend ostream& operator<<(ostream& output,const Word &w){output<<w.str;return output;}
private:
string str;
};
int main( ){
Word wl("Happy"),w2("Welcome");
cout<<"After sorting:";
if(wl<w2)cout<<w1<<"<<w2;
else cout<<w2<<""<<w1:
return 0;
}
填空题若串s="MathTypes",则其子串的数目是 。
填空题请将下列程序的横线处补充完整,使得输出结果为bbaa
#include<iostream>
using namespace std;
class A{
public:
______{cout<<"aa";}
};
class B:public A{
public:
~B(){cout<<"bb";}
};
int main(){
B*p=new B;
delete p;
retum 0;
}
填空题设一棵完全二叉树共有700个结点,则在该二叉树中有{{U}} 【1】 {{/U}}个叶子结点。
填空题下列软件系统结构图的宽度为________。
填空题开发一个C++语言程序的步骤通常包括编辑、 【6】 、链接、运行和调试。
填空题当用数组元素作函数参数时,这属于 【9】 传递。
填空题请将下列类定义补充完整。
class Base{public:void fun(){cout<<"Base::fun"<<end;}};
class Derived:public Base
{
public:
void fun()
{
{{U}} 【13】 {{/U}}//显式调用基类的fun函数
cout<<"Derived::fun"<<endl;
}
};
填空题下列程序中声明了两个类AA和BB,其中函数“print”是类AA的成员函数,但是类BB的友元函数。 请在①、②和⑧处各填入正确的内容,使程序能正常运行。 #include<iostream.h> [12] ; class AA int t; public: AA(int x)t=x; void print(BB ; class BB int s; public: BB(int y)s=y; friend void [13] print(BB BB n(8); m.print(n); 输出结果为:AA:6;BB:8
填空题下列程序编译时发现pb->f(10);语句出现错误,其原因是{{U}} 【12】 {{/U}}。
# include<iostream. h>
class Base
{
public:
void f(int x){cout<<"Base:"<<x<<endl;
};
class Derived: public Base
{
public:
void f(char * str){cout<<"Derivcd:"<<str<<endl;}
};
void main(void)
{
Derived * pd=new Derived;
pd->f(10)
}
填空题在C++中,若需要在程序文件中进行标准输入输出操作,则必须在开始处加入预处理命令#include<iostream.h>,若使用到数学库中的函数时,要在源程序的开始处加入预处理命令 【8】 。
填空题类的静态成员的定义说明语句不能出现在类的外部,而且只能定义 【10】 次。
填空题要想把类的一般成员函数说明为类的常成员函数,则应该使用关键词 【11】 说明成员函数。
填空题假设a、b均是整型变量,则表达式a=2,b=5,a++,b++,a+b值为______。
填空题冒泡排序算法在最好的情况下的元素交换次数为
________
。
填空题以下程序的执行结果是 【9】 。 #include<iostream.h> template<class T> class Sample T n; public: Sample(T i)n=i;) void operator(); void disp()cout<<"n="<<n<<endl;) ; template<class T> void Sample<T>::operator() n=1;//不能用n;因为double型不能用 void main() Sample<char>S('a'); S; s.disp();
填空题下列函数的功能是判断字符串str是否对称,对称则返回true,否则返回false。请在横线处填上适当内容,实现该函数。 bool fun(char*str) int i=o,i=0; while(str[j]) 【6】 ; for(j--;i<ji++,j--); return i 【7】 j;