选择题 有如下类声明:
class Base {
protected:
int amount;
public:
Base(int n=0): amount(n) {}
int getAmount()const {return amount;}
};
class Derived: public Base {
protected:
int value;
public:
Derived(int m, int n): vahle(m), Base(f1) {}
int getData()const {return value+amount;}
};
已知x是一个Derived对象,则下列表达式中正确的是______。
选择题 有下列程序:
#include<iosteram.h>
using namespace std;
class Stack
{
public:
Stack(unsignedn=10):size(n){rep_=new int [size];top=O;}
Stack(Stacks):size(s.size)
{
rep_=new int[size];
for(int i=0;i<size;i++)
rep_[i]=s.rep_[i];
top=s.top;
}
~Stack()<delete[]rep_;}
void push(int A) {rep_[top]=a;top++;}
intpop(){--top;return rep_[top];}
bool isEmpty()const {return top==0;}
private:
int*rep_;
unsigned size,top;
};
int main()
{
Stack s1;
for(int i=1;i<5;i++)
s1.push(i);
Stack s2(s1);
for(int i=1;i<3;i++)
cout<<s2.pop()<<',';
s2.push(6);
s1.push(7);
while(!s2.isEmpty())
cout<<s2.pop()<<',';
return 0;
}
执行上面程序的输出结果是 。
选择题 有如下类定义:
class MyClass{
Int value;
public;
MyClass(int n):value(n){}
int gerValue()const{return value;}
};
则类MyClass的构造函数的个数是______。
选择题 在16位计算机中,一个int型数据所占用的内存长度为______字节。
选择题 下列不属于软件设计阶段任务的是______。
选择题 在位运算中,操作数每左移一位,其结果相当于______
选择题 有如下程序:
#include<iostream>
using namespace std;
class Base{
public:
void fun(){cout<<'B';}
};
class Derived:public Base{
public:
void fun(){______cout<<'D';}
};
int main(){
Derived d;
d.fun();
return 0;
}
若程序的输出结果是BD,则划线处缺失的部分是______。
选择题 下列叙述中正确的是______。
选择题 有如下程序:
#nclude<iostremn>
using namespace std;
class Stack{
public:
Stack(unsigned n=10:size(n){rep_=new int[size];top=O;}
Stack(Stacks):size(s.size)
{
rep_=new int[size];
for(int i=0;i<size;i++)rep_[i]=s.rep_[i];
top=s.top;
}
~Stack(){delete[]rep_;}
void push(int a){rep_[top]=a; top++;}
int opo(){--top;return rep_[top];}
bool is Empty()const{return top==O;}
pavate:
int*rep_;
unsigned size,top;
};
int main()
{
Stack s1;
for(int i=1;i<5;i++) s1.push(i);
Stack s2(s1);
for(i=1;i<3;i++) cout<<s2.pop()<<',';
s2.push(6);
s1.push(7);
while(!s2.isEmpty()) cout<<s2.pop()<<',';
return 0;
}
执行上面程序的输出是
选择题 当派生类从一个基类保护继承时,基类中的一些成员在派生类中成为保护成员,这些成员在基类中原有的访问属性是______。
选择题 下列叙述中正确的是______
选择题 若有函数模板mySwap和一些变量定义如下:
template<class T>
void mySwap(T X,T Y);
double d1,d2;int i1,i2;
下列对mySwap的调用中,错误的是______。
选择题 下列描述中正确的是______。
选择题 下列关于C++关键字的说法中正确的是______。
选择题 关于构造函数A()的拷贝构造函数正确的是______
选择题 如果表达式y*x++中,“*”是作为成员函数重载的运算符,“++”是作为友元函数重载的运算符,采用运算符函数调用格式,该表达式还可表示为______
选择题 下面程序的输出结果是______。
#include <iostream>
using namespace std;
int fun(char *s);
int main()
{
cout<<fun('Hello');
return 0;
}
int fun(char *s)
{
char *t=s;
while(*t!='\0')t++;
return(t-s);
}
选择题 若目前D盘根目录下并不存在test.txt文件,则下列打开文件方式不会自动创建test.txt文件的是______。
选择题 有如下程序:
#include<iostream>
using namespace std;
class Base{
public:
Base(int x=0):valB(x){cout<<valB;}
~Base(){cout<<valB;}
private:
int valB;
};
class Derived:public Base{
public:
Derived(int x=0,int y=0):Base(x),valD(y){cout<<valD;}
~Derived(){cout<<valD;}
private:
int valD;
};
int main(){
Derived obj12(2,3);
return 0;
}
运行时的输出结果是______。
选择题 下列关于构造函数的描述中,错误的是______。
