单选题C++中的类有两种用法:一种是类的实例化,即生成类的对象,并参与系统的运行,另一种是通过
____
派生出新的类。
单选题下列有关C++流的表述中,错误的是
单选题若AA为一个类,a为该类的非静态数据成员,在该类的一个成员函数定义中访问a时,其书写格式为______。
单选题有如下程序:
#include<iostream>
#include<string>
using namespace std;
class Shape{
public:
void Draw();
string GetName();
private:
string name;
};
class Rectangle:private Shape{
protected:
void Draw() {Shape::Draw();} //A
string GetName() {return name;} //B
};
int main(){
Rectangle rect;
rect.Draw(); //C
rect.GetName(); //D
return 0;
}
带标号的语句中,编译时不会出错的是______。
单选题有如下语句序列: int k=0; dO{k+=5;cout<<'$';) while(k<19); while(k-->0)cout<<'*';执行上面的语句序列输出字符$和*的个数分别是( )。
单选题若已定义 int a[]={0,1,2,3,4,5,6,7,8,9},*p=a,i; 其中0≤i≤9,则对a数组元素不正确的引用是( ) 。
单选题下列程序段中有错的是( )。
单选题下列关于运算符重载的描述中,错误的是( )。
单选题下列符号中可以用作C++标识符的是( )。
单选题有如下程序: #inc1ude <iostream> using namespace std; c1ass C1{ public: ~C10{ cout<<1;} }; c1ass C2: public C1{ public: ~C2(){ cout<<2;} }; int main(){ C2 cb2; C1 *cb1; return 0; } 运行时的输出结果是( )。
单选题若有以下程序: #include <iostream> using
namespace std; class A {
public: A() { } A(int
i) { x1=i;
} void dispa0
{ cout<<"x1="<<x1<<",";
} private: int x1;
}; class B: public A {
public: B() { } B(int
i):A(i+10) {
x2=i; } void dispb()
{ dispa();
cout<<"x2="<<x2<<endl; }
private: int x2; };
int main() { B b(2);
b.dispb(); return 0; }
程序运行后的输出结果是( )。
A.x1=10,x2=2
B.x1=12,x2=10
C.x1=12,x2=2
D.x1=2,x2=2
单选题下列叙述中错误的是( )。
单选题有如下类声明:
class MyBASE{
int k;
public:
void set(int n){k=n;}
int get()const{return k;}
};
class MyDERIVED:protected MyBASE{
protected:
int j;
public:
void set(int m, int n){MyBASE::set(m); j=n;}
int get()const{return MyBASE::get()
+j;}
};
则类MyDERIVED中保护的数据成员和成员函数的个数是______。
单选题有以下类定义: class Point {
public: Point(int x=0,int y=0){_x=x;
_y=y;} void Move(int x Off, int y Off) {_x+=x
Off; _y+=y Off; } void Print() const
{ cout <<'(' << _x << ',' << _y << ')'<< end
1;} private: int
_x,_y; }下列语句中会发生编译错误的是______。
A. Point pt; pr. Print();
B. const Point pt; pt. Print();
C. Point pt; pt. Move(1,2);
D. const Point pt; pt. Move(1,2);
单选题有如下类定义: class Point private: static int how_many; ; ______how_many=0; 要初始化Point类的静态成员how_many,在下画线处应填入的内容是
单选题有下列程序:
#include <stdio.h>
void main()
{
int s[12]={1,2,3,4,4,3,2,1,1,1,2,3},c[]5={0},i;
for(i=0;i<12;i++)c[s[i]]++;
for(i=1;i<5;i++)printf("%d",c[i]);
printf("/n")
}
单选题下面程序的打印结果是______。
#include<iostream>
using namespace std;
class A
{
private:
int x, y;
public:
void set(int i, int j)
{
x=i;
y=j;
}
int get_y(){return y;}
};
class box
{
private:
int length, width;
A label;
public:
void set(int l, int w, int s, int p)
{
length=l;
width=w;
label.set(s, p);
}
int get_area(){return length*width;}
};
int main()
{
box small;
small.set(2, 4, 1, 35);
cout<<small.get_area()<<endl;
return 0;
}
单选题有如下程序: #include<iostream> using namespace std; class Part{ public:Part(int x=0):val(x){cout<<val;} ~Part(){cout<<val;} private: int val; }; class Whole{ public: Whole(int x,int y,int z=0):p2(x),p1(y),val(z){cout<<val;} ~Whole(){cout<<val;} private: Part p1,p2; int val; }; int main(){ Whole obj(1,2,3); return 0; } 程序的输出结果是( )。
单选题定义派生类时,若不使用关键字显式地规定采用何种继承方式,则默认方式为______。
单选题若调用一个函数,且此函数中没有return语句,则正确的说法是该函数{{U}} {{/U}}。
A.没有返回值
B.返回若干个系统默认值
C.有返回值,但返回一个不确定的值
D.返回一个用户所希望的函数值
