单项选择题

以下程序的执行结果为( )。
#include <iostream.h>
class Sample
int n;
public:
Sample(int i) n=i;
operator++() n++; //前缀重载运算符
operator++(int) n+=2; //后缀重载运算符
void disp()
cout<<"n="<<n<<endl;
;
void main()
Sample A(2),B(2);
A++;
++B;

A.disp();A.disp();
A.n=4
B.n=1
C.n=3
D.n=5
n=3 n=2 n=4 n=6
<上一题 目录 下一题>
热门 试题

单项选择题
下列程序的输出结果是( )。 #include<iostream> using namespace std; int main() char a[]= Hello,World ; char*ptr = a; while(*ptr) if(*ptr>= ’a’ &&*ptr<=’z’) cout<<char(*ptr+’A’-’a’); else cout<<*ptr; ptr++; retur 0;
A.HELLO, WORLD
B.Hello, World
C.HELLO, world
D.hello, world
单项选择题
包容类Contain和内嵌类Embed定义如下: #include <iostream.h> class Contain private: int x; protected: int z; public: class Embed private: int y; public: Embed()y=100; int Embed_Fun(); MyEmbed; int Contain_Fun(); ; 对上面的定义,正确的描述是( )。
A.定义类Embed对象的语句是:Contain::Embed embed;
B.类Contain的成员函数Contain_Fun()中可以用MyEmbed.y的方式访问类Embed的私有成员y
C.类Embed的成员函数Embed_Fun()中可以直接访问类Contain和的私有成员x
D.类Embed的成员函数Embed_Fun()中可以直接访问类Contain的保护成员z
相关试题
  • 以下程序的输出结果是( )。 #include...
  • 若有以下程序: #include <iostream>...
  • 有如下程序: #include <iostream.h>...
  • 包容类Contain和内嵌类Embed定义如下: #...
  • 下列程序的输出结果是( )。 #include...