填空题写出执行完下列代码段之后指定变量的值: bool x=true ,y=false,z=false; x=x&&y||z; y=x||y&&z; z=!(x!=y)||(y==z); 则x=false,y= 【6】 ,z= 【7】 。
填空题类time可以输出12小时或24小时制的时间,现需要设计一个缺省构造函数,缺省值为0时0分0秒。该缺省构造函数为______。
#include<iostream.h>
class Time
{
int h,m,s;
public:
Time(int hour=0,int min=0,int sec=0){settime(hour,min,sec);}
void settime(int hour,int min,int sec){h=hour;m=min;s=sec;}
void show24( )
{ cout<<(h<10?"0":"")<<h<<":"<<(m<10?"0":"")<<
m<<":"<<(s<10?"0":"")<<s<<endl;
}
void showl2( )
{ int temp=(h= =0 || h= =12)? 12:h%12;
cout<<(temp<10?"0":"")<<temp<<":"<<(m<10?"0":"")
<<m<<":"<<(s<10?"0":"")<<s<<((temp>0
}
};
void main( )
{
Time t(15,43,21);
t.showl2( );
t.show24( );
}
填空题数据结构分为逻辑结构与存储结构,循环队列属于 【1】 。
填空题以下程序的执行结果是{{U}} 【9】 {{/U}}。
#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();
}
填空题使用VC6打开考生文件夹下的工程test19_1,此工程包含一个源程序文件test19_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下: 1: weight:5 age:0 2: weight:7 age:9 源程序文件test19_1.cpp 清单如下: #include <iostream.h> class animal public: /**************** found *******************/ friend void setvalue(animal /**************** found *******************/ void print() protected: int itsweight; int itsage; ; void animal::print() cout<<"weight:"<<itsweight<<end1; cout<<"age:"<<itsage<<end1; void setvalue(animal ta.ihsage=0; void setvalue(animal ta.itsage=tn; void main() /**************** found *******************/ animal peppy setvalue(peppy,5); cout<<"1:"<<end1; peppy.print(); setvalue(peppy,7,9); cout<<"2:"<<end1; peppy.print();
填空题数据独立性分为逻辑独立性和物理独立性。当总体逻辑结构改变时,其局部逻辑结构可以不变,从而根据局部逻辑结构编写的应用程序不必修改,称为【3】 。
填空题若要将函数“void FriFun();”声明为类MyClass的友元函数,则应在类MyClass的定义中加入语句______。
填空题假定q所指对象的值为25,q+1所指对象的值为46,则执行"(*q)++;"语句后,q所指对象的值为______。
填空题使用VC++6.0打开考生文件夹下的源程序文件1.cpp,该程序运行时有错误,请改正错误,使得程序输出:
Hello test
注意:不要改动main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在//******error******的下面。
试题程序: #include<iostream>
//********error******** template(T) void fun(T
t) { std::cout<<"test"<<std::end1;
} //********error********
template<bool> void fun(bool t) {
std::cout<<(t?"Hello":"Hi")<<std::end1; }
int main() {
//********error******** bool flag=TRUE;
fun(flag); fun((int)flag); return 0;
}
填空题算法的复杂度包括时间复杂度和{{U}} 【1】 {{/U}}。
填空题假设int a =1,b =2;则表达式a+++--b的值为 【7】 。
填空题假定用户没有给一个名为MyClass的类定义析构函数,则系统为其定义的默认析构函数首部形式为{{U}} 【10】 {{/U}}。
填空题有以下程序: #include <iostream> #include <fstream> using namespace std; int main() ofstream ofile("D://test.txt"); if(!ofile) cout<<"test.txt can't open"<<end1; return 0; ofile<<"This book is C++"<<" "<<12345<<end1; ofile.close(); ifstream ifile("D://test.txt"); if ( ! ifile) cout<<"test.txt can't open"<<end1; return 0; char str[80]; ifile>>str; ifile.close(); cout<<str<<end1; return 1; 程序执行后的输出结果是 【15】 。
填空题评价一个算法时间性能的主要标准是算法的{{U}} 【1】 {{/U}}复杂度。
填空题如果在一棵二叉树中有17个度为2的结点,则该二叉树中有 【4】 个叶子结点。
填空题下列程序的输出结果是______。 #include <iostream> using namespace std; template <typename T> T total(T *data) T s=0; while(*data) return s; int main() int x[]= 2,4,6,8,0,12,14,16,18 ; cout<<total(x)<<endl; return 0;
填空题有如下类定义,请将Sample类的拷贝构造函数补充完整。
class Sample{
public:
Sample(){)
~Sample(){if(p)delete p;)
Sample(const Sample}
private:
int*p;
};
填空题以下程序的执行结果是______。 #inelude<iostream.h> class Sample public: int x; int y; void disp( ) cout<<"x="<<x<<",y="<<y<<endl; ; void main( ) int Sample::*pc; Sample s; pc= s.*pc=10; pc= s.*pc=20; s.disp( );
填空题下面程序的输出结果为:Base::fun,请将程序补充完整。 #include<iostream.h> class Base public: 【12】 fun()cout<<"Base::fun"<<end1; ; class Derived:public Base public: 【13】 fun()cout<<"Derived::fun"<<end1; ; int main() Base a,*pb; Derived b; pb=&b; pb->tim(); return 0;
填空题在数据库技术中,实体集之问的联系可以是一对一或一对多或多对多的,那么“学生”和“可选课程”的联系为______。