填空题下面程序的运行结果是 【9】 。 #inChlde<iOStream> using namespace std; class count static int n; public: count() n++; static int test() for(int i=0:i<4;i++) n++; return n; ; int count::n=0; int main() cout<<COUnt::test()<<" "; count c1, c2; cout<<count::test()<<end1; return 0;
填空题类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){ }
};
填空题C++程序是从{{U}} 【10】 {{/U}}函数开始执行的。
填空题已知程序的结果为1 2 3,请填空。 #include<iostream.h> template<class T> class A public: T x,y,z; void display() cout <<x << " " <<y << " " <<z; ; void main() A<int>a1; 【12】 【13】 【14】 a1.display();
填空题软件工程研究的内容主要包括:软件工程管理和{{U}} 【2】 {{/U}}技术。
填空题通过使用new和delete两个运算符进行的分配为 【9】 存储分配。
填空题试题源程序文件清单如下://proj1.cpp#include<iostream>usingnamespacestd;classMyClasspublic:MyClass(intx):value(x)cout<<"Constructor"<<endl;//ERROR**********found**********void~MyClass()(1)cout<<"Destructor"<<endl;voidPrint()const;private://ERROR**********found**********intvalue=0:(2);//ERROR**********found**********voidMyClass::Print()(3)cout<<"Thevalueis"<<value<<endl;intmain()MyClassobject(10);object.Print();return0:
填空题虚函数必须是类的
________
。
填空题有以下程序:
#include<fstream>
#include<string>
using namespace std;
int main(){
char ch[]="The end";
ofstream outstr("______",ios_base::app);
for(int i=0;i<strlen(ch); i++) outstr.put(ch[i]);
outstr.close();
return 0:
}
若程序实现的功能是在文件d:/put.txt的尾部追加写入一串字符,试将程序补充完整。
填空题下面是计算n的阶乘的递归函数,请将该函数的定义补充完整。 unsigned f(unsigned n) if(n<=1) return 1; else return 【10】 ;
填空题Staff类含有int型数据成员ID,两个Staff对象相等是指它们的ID相同。下面的函数重载了运算符“==”,它用来判断两个Staff对象是否相等,相等时返回true,否则返回false。请将横线处缺失部分补充完整。
bool Staff::Staff==(const Staff
}
填空题下面程序的输出结果是______。 #include<iostream> using namespace std; int x; void funA(int&,int); void funB(int,int&); int main() int first; int second=5; x=6; funA(first,seconD) ; fimB(first,seconD) ; cout<<first<<" "<<second<<" "<<x<<end1; return 0; void funA(int &a,int B) int first; first=a+b; a=2*b; b=first+4; void funB(int u,int &v) int second; second=x; v=second+4; x=u+v;
填空题C++语言程序的注释可以出现在程序中的任何地方,一个注释以{{U}} {{/U}}作为开始和结束的标记。
填空题C++程序中的预处理命令以符号 【6】 作为起始标记。
填空题下列程序用于将源文件中的字母进行大小写转换,while的条件是______。
#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
void main( )
{
char ch;
fstream filel,file2;
char fnl[10],fn2[10];
cout<<"输入源文件名:";
cin>>fn1;
cout<<"输入目标文件名:";
cin>>fn2;
filel.open(fnl,ios::in);
file2.open(fn2,ios::out);
while(______)
{
if(ch>='a'
file2.put(ch);
}
filel.close( );
file2.close( );
}
填空题下列程序的输出结果为{{U}} 【13】 {{/U}}。
#include <iostream. h>
void main()
{
char a[]="abcdabcabfgacd";
int i1=0,i2=0,i=0;
while (a[i])
{
if (a[i]=='a') i1++;
if (a[i]=='q') i2++;
i++;
}
cout<<i1<<''<<i2<<end1;
}
填空题在长度为n的线性表中查找一个表中不存在的元素,需要的比较次数为
________
。
填空题以下程序的运行结果是{{U}} 【8】 {{/U}}。
#include<iostream.h>
void main()
{
bool t1=8,t2=0,t3=1;
cout<<t1<<'/t'<<t2<<'/t'<<t3<<end1;
}
填空题使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示学生学号的类StuID,但类StuID的定义并不完整。请按要求完成下列操作,将类StuID的定义补充完整,使程序的运行结果为 学生的学号为:20100401 学生名为:张三 删除学生学号为:20100401 (1)定义StuID类的私有数据成员IDvalue,用于表示学生的学号,学号为long型的数据。请在注释1之后添加适当的语句。 (2)完成默认构造函数StuID的定义,使StuID对象的默认值为:id=0,并把学生的学号赋给IDvalue,并输出“赋给学生的学号:”及学号。请在注释2之后添加适当的语句。 (3)完成默认析构函数StuID的定义,使StuID析构时输出“删除学号:”及学号。请在注释3之后添加适当的语句。 (4)完成默认构造函数StuInfo的定义。对应两个默认参数:定义char stName[],其默认值为“no name”,定义long stID,其默认值设为0,并使它们赋值给相应的类数据成员。请在注释4之后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 试题程序: #include<iostream.h> #include<string.h> class StuID //********1******** public: //********2******** IDvalue=id; cout<<"学生的学号为:"<<IDvalue<<end1; //********3******** cout<<"删除学生学号为:"<<IDvalue<<cnd1; ; class StuInfo private: StuID id; char name[20]; public: //********4******** cout<<"学生名为:"<<stName<<end1; strcpy(name,stName); ; void main() StuInfo st("张三",20100401);
填空题使用VC6打开考生文件夹下的工程test1_1,此工程包含一个源程序文件test1_1.cpp,但该程序运行有问题,请改正main函数中的错误,使该程序的输出结果如下: Constructor called. Default constructor called. Area is 6 Area is 0 Area is 6 源程序文件test1_1,cpp清单如下: #include<iostream.h> class RectAngle private: double ledge,sedge; public: RectAngle() cout<<"Default constructor called."; RectAngle(double l,double s) ledge=l;sedge=s; cout<<"Constructor called."; void Set(double l,double s) ledge=l;sedge=s; void Area() cout<<"Area is"<<ledge*sedge<<endl; ; void main() /***************** found *****************/ RectAngle Rect1(2,3); RectAngle Rect2(1); /**************** found *****************/ RectAnglC Rect3; Rectl.Area(); /***************** found *****************/ RecL2.lodge=0;Rect2.sedge=0; Reck2.Area(); Rect3.Area();
