填空题给出以下程序的执行结果 【9】 。 #include <iostream> using namespace std; int n=1; void Fun(); int main () n++; Fun ( ); if (n>0) int n=5; cout<<"Block: n="<<n<< ", "; cout<< "Main: n="<<end1; return 0; void Fun ( ) int n=10; cout<<"Fun: n="<<n<<",";
填空题将一个函数声明为一个类的友元函数必须使用关键字______。
填空题数据库设计包括概念设计、______和物理设计。
填空题数据字典通常包括5个部分,即数据项、数据结构、数据流、{{U}} 【2】 {{/U}}和处理过程。
填空题C++中,派生类继承了基类的全部数据成员和除
________
之外的全部函数成员。
填空题使用VC++6.0打开考生文件夹下的源程序文件1.cpp,该程序运行时有错误,请改正其中的错误,使程序正确运行,并且使程序输出的结果为
OK 注意:错误的语句在//******error******的下面,修改该语句即可。
试题程序: #include<iostream.h> class
TC { public: TC()
{ a=b=0; }
private: int a,b; }; class
TC1:public TC { public:
TC1() { }
//******error****** virtual void func();
}; class TC2:public TC1 {
public: TC2() {
a=0; b=0; } void
func() { //******error******
cout<<"OK"<<end1; } private:
int a; int b; }; void
main() { TC2 obj;
//******error****** TC1 *p=(TC1*)obj;
p—>func(); }
填空题下列程序中,先声明一个圆类circle和一个桌子类table,另外声明一个圆桌类roundtable,它是由 circle和table两个类派生的,要求声明一个圆桌类对象,并输出圆桌的高度,面积和颜色。请填空完成程序
#include<iostream.h>
#include<string.h>
class circle{
double radius;
public:
circle(double r){radius=r;}
double get_area(){return 3.416*radius*radius;}
};
class table{
double height;
public:
table(double h)<height=h;}
double get_height(){return height;}
};
class roundtable:public table,public circle{
char *color;
public:
roundtable(double h,double r,char c[]):{{U}} [10] {{/U}}{
color=new char[strlen(c) +1];
{{U}} [11] {{/U}};
};
char*get_color(){return color;}
}:
void main(){
roundtable rt(0.8,1.0,“白色”);
cout<<"圆桌的高:"<<rt. get_height()<<end1;
cout<<"圆桌面积:"<<rt.get_area()<<end1;
cout<<"圆桌颜色:"<<n.get color()<<end1;
}
填空题使用VC++6.0打开考生文件夹下的源程序文件1.cpp,该程序运行时有错误,请改正错误,使得程序通过运行。 程序输出结果为 5 a 1 注意:不要改动main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在//******error******的下面。 试题程序: #include<iostream> template<class T> //********error******** t min(t x,t y) return(x>y)?y:x; void main() int n=5; //********error******** char c="a"; int d=1; //********error******** cout<<min(n,n)<<end1; cout<<min(c,c)<<end1; cout<<min(d,d)<<end1;
填空题为解决在多重继承环境中因公共基类带来的 【10】 问题,c++语言提供了虚基类机制。
填空题下面程序的预设功能是:统计文件abc.txt中的字符个数。 #include <iostream.h> #include <fstream.h> #include <stdlib.h> void main() fstream file; file.open( "abc.txt", ios::in); if ( !file ) cout<<"Can not open abc.txt"<<end1; abort(); char ch; int i = O; while (______________) file.get(ch); i++; cout<<"Characters : "<<i<<end1; file.close(); 则程序中空白处应该填入的语句是 【15】 。
填空题已知递归函数f的定义如下: int f(int n) if(n<= 1)return 1;//递归结束情况f5=5*f3=5*3*f1 else return n*f(n-2); //递归 则函数调用语句f(5)的返回值是______。
填空题软件危机出现于60年代末,为了解决软件危机,入们提出了 【3】 的原理来设计软件,这就是软件工程诞生的基础。
填空题以下程序的输出结果是{{U}} 【10】 {{/U}}。
#include<iostream.h>
unsigned frn(ullsigned num)
{ unsi9ned k=1;
do{k*=num%10;num/=10;} while(num);
return k;
}
void main()
{ unsigned n=26;
cout<<fun(n) <<endl;
}
填空题下列for语句的循环次数为______。
for(int a=0,b=1;b&&a<5;a++);
填空题下列程序的运行结果是{{U}} 【11】 {{/U}}。
# include<iostream. h>
# include<string. h>
void main()
{
char * a[5]={"stuent","worker","teacher","soldier"," peasant"};
char * p1, * p2;
p1=p2=a[0]
for(int i=0;i<5;i++)
{
if(strcmp(a[i],p1)>0)
p1=a[i];
if(strcmp(a[i],p2)<0)
p2=a[i];
}
cout<<p1<<","<<p2<<endl;
}
填空题深度为n(n>0)的二叉树最多有 [1] 个结点。
填空题派生类中的成员不以直接访问基类中的{{U}} 【11】 {{/U}}成员。
填空题类clasg one在声明func成员函数时发生错误,出错原因是______。
class one
private:
int a;
public:
void func(two
};
class two
{
private:
int b;
friend vold one::func(two
};
void one::func(two
}
填空题下列程序的输出结果是{{U}} 【15】 {{/U}}。
#include <iostream>
using namespace std;
template <typename T>
T total(T* data)
{
Ts=0;
while(*data)
{
s+=*data++;
}
return s;
}
int main()
{
int x[]={2,4,6,8,0,12,14,16,18};
cout<<total(x)<<end1;
return 0;
}
填空题下列程序对加号进行了重载,划线部分的语句是{{U}} 【15】 {{/U}}。
# include<iostream. h>
# include<math. h>
class Triangle
{
int x,y,z;
double area;
public:
Triangle(int i,int j, int k)
{
double s;
x=i;y=j;z=k;
s=(x+y+z)/2.0;
area=sqrt(s*(s-x)*(s-y)*(s-z));
}
void disparea()
{
cout<<"Area="<<area<<endl;
}
friend double operator+(Triangle t1,Triangle t2)
{
______
}
};
void main()
{
Triangle t1(3,4,5),t2(5,12,13);
double s;
cout<<"t1:";t1.disparea()
cout<<"t2:";t2.disparea()
s=t1+t2;
tout<<"总面积:="<<s<<endl;
}
