题库 题库
🏠 天天查询 > 题库 > C++

C++

填空题 在类的对象被创建的时候,______函数会被自动调用。 查看答案
填空题 在类中,______成员为类的所有对象所共享。 查看答案
填空题 有如下程序:
#include <iostream>
using namespace std;
class Base{
public;
int m,n;
};
class Derived1: ______Base{};
class Derived2: public Derived1{
public:
void SetMN(int M, int N){ M=M; n=N; }
int GetSumMN(){ retum (m+n); }
};
int main(){
Derived2 objD;
objD.SetMN(3,4);
cout<<"M+N="<<objD.m+bojD.n<<endl;
retum 0;
}
编译时只有“cout<<"M+N="<<objD.m+bojD.n<<endl;”有语法错误,程序的其他地方没有语法错误,请判断下
划线处使用的关键字是什么。
查看答案
填空题 有如下程序:
#include <iostream>
using namespace std;
class Base{
int b;
public;
Base(int i) { b=i; }
void disp(){cout<<"Base: b="<<b<<;}
};
class basel; virtual public Base{
public;
Base1(int i): Base(i){}
};
class Base2:virtual public Basc{
public;
Base2(int i):Base(i){}
};
class Derived:public Base2.public Base1{
int d;
public;
Derived(int I,int j):Base1(j), Base2(j), ______
{ d=i; }
void disp() {cout<<"Derived: d="<<d<<"; }
};
int main(){
Derived objD(1,2); objD.disp();
objD.Basce::disp();
objD.Basce1::disp();
objD.Basce2::disp();
return 0;
}
请将程序补充完整,使程序在运行时输出:
Derived: d=1 Base: b=2 Base: b=2 Base: b=2
查看答案
填空题 如下程序声明了一个电话号码类PhoneNumber,重载了流插入运算符<<,以便于电话号码的输出。请将程序补
充完整。
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class PhoneMumber{
public;
void setNumber(string number){ this->number=number; }
//重载流插入操作符
friend______ (ostream &output, const PhoneNumber &num)
{ output<<num.number; return output; }
private;
string number;
};
int main(){
PhoneNumber phone;
phone.setNumber("8008100598");
cout <<"The phone number is:"<<phone << end1;
return 0;
}
查看答案
填空题 如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。
#include <iostream>
#include <string>
using namespace std;
class TwoDShape{ //二维图形类
char name[20];
public;
TwoDShape(char *n="unknown"){
strcpy(name, n);
}
char *getNa:ne(){ return name; }
______=0;
};
class Rec : public TwoDShape{
double width, height;
public;
Rec (double w=0.0, double h=0.0):TwoDShape("rectamgle")
{ width = w; height = h; }
double getWidth(){ return width; }
double getHeight(){ return height;}
double area(){ return width*height; }
};
int main(){
TwoDShape *shape;
shape = new Rec(2.1, 3.0);
cout <<"object is"<<shape->getName()<<"\n";
cout <<"Area is"<<shape->area()<<"\n";
return 0;
}
请将程序补充完整,使程序在运行时输出:
object is triangle
Area is 6.3
查看答案
填空题 如下程序声明了一个使用两个通用数据类型的模板类dataClass,其中构造函数用于初始化两个数据成员,成员
函数show 用于输出两个数据成员的数值。
#include <iostream>
using namespace std;
______
T1 i;
T2 j;
public;
dataClass(T1 a T2 b){ i = a; j=b; }
void show(){ cout << i <<", "<<j<<'\n'; }
};
int main(){
dataClass<int, double> ob1(10, 0.23);
dataClass<char, char *>ob2('X', "my data");
ob1.show();
ob2.show();
retum 0;
}
请将程序补充完整,使程序在运行时输出:
10, 0.23
X, my data__
查看答案
填空题 用树结构表示实体类型及实体间联系的数据模型称为______。 查看答案
填空题 数据流图的类型有______和事务型。 查看答案
填空题 在最坏情况下,堆排序需要比较的次数为______。 查看答案
填空题 软件开发环境是全面支持软件开发全过程的______集合。 查看答案
填空题 冒泡排序算法在最好的情况下的元素交换次数为______。 查看答案
填空题 C++语言标识符是以字母或______开头的,由字母,数字和下划线组成的字符串。 查看答案
填空题 mystrlen函数的功能是计算str所指字符串的长度,并作为函数值返回,请填空。
int mystrlen(char *str)
{ int i;
 for(i=0;______!=′\0′;i++);
return(i);}
查看答案
填空题 如果一个类中定义了成员对象,则该类的对象和成员对象先被初始化的是______。 查看答案
填空题 C++在重载运算符中,如用成员函数重载一元运算符参数表中需要______个参数,如用友元函数重载一元运算符参数表中需要______个参数。 查看答案
填空题 假设int a=1,b=2;,则表达式(++a/b)*b--的值为______。 查看答案
填空题 C++语句const char *const p=″hello″;,所定义的指针p和它所指的内容都不能被______。 查看答案
填空题 对于下面定义的类MyClass,请在函数f(    )中添加对象成员把n的值修改为50。
class MyClass
{
public:
MyClass(int x){n=x;}
void SetNum(int nl){n=nl;}
private:
int n;
};
int f()
{
MyClass *ptr=new MyClass(45);
______
}
查看答案
填空题 表达式operator+(x,y)还可以表示为______。 查看答案
填空题 通过使用new和delete两个运算符进行的分配为______存储分配。 查看答案
填空题 长度为n的顺序存储线性表中,当在任何位置上插入一个元素概率都相等时,插入一个元素所需移动元素的平均个数为______。 查看答案
填空题 用树型结构表示实体类型及实体间联系的数据模型称为______。 查看答案
填空题 类是一个支持集成的抽象数据类型,而对象是类的______。 查看答案
填空题 数据流图的类型有______和事务型。 查看答案
填空题 当数据的物理结构(存储结构、存取方式等)改变时,不影响数据库的逻辑结构,从而不致引起应用程序的变化,这是指数据的______。 查看答案
填空题 在C++语言的面向对象程序设计框架中,______是程序的基本组成单元。 查看答案
填空题 C++语言程序的注释可以出现在程序中的任何地方,一个注释以______作为开始和结束的标记。 查看答案
填空题 以下程序的输出结果是______。
#include<iostream.h>
void fun()
{  static int a=0;
a+=2;
cout << a << " ";}
void main()
{  int cc;
for(cc=1;cc<4;cc++)
fun();
cout << endl;}
查看答案
填空题 用以下语句调用库函数malloc,使字符指针st指向具有11个字节的动态存储空间,请填空。
st=(char*)______;
查看答案
填空题 以下程序的输出结果是______。
#include<iostream.h>
unsigned fun(unsigned num)
{ unsigned k=1;
do{ k *=num%10;num/=10;} while (num);
return k;
}
void main()
{ unsigned n=26;
cout << fun(n)<< endl;
}
查看答案
填空题 下列程序在构造函数和析构函数中申请和释放类的数据成员int *a,申请时使用形参b初始化a,请填空。
class A
{
public:
A(int b);
~A();
private:
int *a;
};
A::A(int b)
{
______;
}
A::~A()
{
______;
}
查看答案
填空题 C++语言中的多态性是在编译时通过 ______和模板体现的,在运行时是通过______体现的。 查看答案
填空题 将x+y*z中的"+"用成员函数重载,"*"用友元函数重载应写为______。 查看答案
填空题 数据的逻辑结构有线性结构和______两大类。 查看答案
填空题 顺序存储方法是把逻辑上相邻的结点存储在物理位置______的存储单元中。 查看答案
填空题 一个类可以从直接或间接的祖先中继承所有属性和方法。采用这个方法提高了软件的______。 查看答案
填空题 软件工程研究的内容主要包括:______技术和软件工程管理。 查看答案
填空题 关系操作的特点是______操作。 查看答案
填空题 C++中封装性、继承性和______是面向对象思想的主要特征。 查看答案
填空题 下面程序的结果为______。
#include<iostream.h>
void main()
{
int a=1,b=2;
bool c=1;
if((a>b)||c)cout<<"true"<<endl;
else
cout<<"false"<<endl;
}
查看答案
填空题 下列for语句的循环次数为______。
for(int a=0,b=1;b&&a<5;a++);
查看答案
填空题 下面程序的输出结果是______。
#include <iostream.h>
void main()
{
int a[6]={1,2,3,4,5,6};
for(int i=0;i<5;i++)
cout<<a[i]<<" ";
cout<<endl;
}
查看答案
填空题 C++程序是从______函数开始执行的。 查看答案
填空题 假定A为一个类,则语句A(A &a);为该类______函数的原型说明。 查看答案
填空题 派生类构造函数的执行顺序是先执行______的构造函数,然后执行成员对象的构造函数,最后执行______的构造函数。 查看答案
填空题 类模板不同于函数模板,类模板只可用______型参数。 查看答案
填空题 下列程序的执行结果为______。
#include<iostream.h>
void main()
{
cout.fill(′*′);
cout.width(10);
cout<<"hello"<<endl;
}
查看答案
填空题 在算法正确的前提下,评价一个算法的两个标准是______。 查看答案
填空题 将代数式Z=   转换成程序设计中的表达式为______。 查看答案