简单的题目,第一个答对有高分,100分,限时明天晚上

dbetter 2009-03-20 02:59:52
二、程序阅读题
1.写出下列程序的运行结果。
#include <iostream>
using namespace std;
void num( )
{ extern int x,y;
int a=15,b=10;
x=a-b; y=a+b;
}
int x,y;
int main(void)
{ int a=7,b=5;
x=a+b;
y=a-b;
num( );
cout<<x<<" "<<y<<endl;
return 0;
}


2. 写出下列程序的运行结果。
#include<iostream>
using namespace std;
class A
{friend double count(A&);
public:
A(double t, double r):total(t),rate(r){}
private:
double total;
double rate;
};
double count(A&a)
{
a.total+=a.rate*a.total;
return a.total;
}
int main(void )
{
A x(100,0.5),y(50,0.1);
cout<<count(x)<<’,’<<count(y)<<’\n’;
cout<<count(x)<<’\n’;
return 0;
}


3. 写出下列程序的运行结果。
#include <iostream>
using namespace std;
class Point;
ostream & operator << (ostream &output, const Point &p);
class Point
{
private:
int _x, _y;
public:
Point& operator++();
Point operator++(int);
Point& operator--();
Point operator--(int);
Point() { _x = _y = 0; }
friend ostream & operator << (ostream &output, const Point &p);
};


Point& Point::operator++()
{
_x++;
_y++;
return *this;
}

Point Point::operator++(int)
{
Point temp = *this;
++*this;
return temp;
}

Point& Point::operator--()
{
_x--;
_y--;
return *this;
}

Point Point::operator--(int)
{
Point temp = *this;
--*this;
return temp;
}
ostream & operator << (ostream &output, const Point &p)
{
output<< "A的值为:" << p._x << " , " << p._y << endl;
return output;
}

void main()
{
Point A,B,C,D,E;
cout<<A;
A=B++;
cout<<A;
A=++C;
cout<<A;
A=D--;
cout<<A;
A=--E;
cout<<A;
}


4. 指出main变量i在每条赋值语句执行后的值(15) 。
int x=2, y=x+30;
struct A{
static int x;
int y;
public:
operator int( ){ return x-y; }
A operator ++(int){ return A(x++, y++); }
A(int x=::x+2, int y=::y+3){ A::x=x; A::y=y; }
int &h(int &x);
};
int &A::h(int &x)
{
for(int y=1; y!=1|| x<201; x+=11, y++) if(x>200) { x-=21; y-=2;}
return x-=10;
}
int A::x=23;
void main( ){
A a(54, 3), b(65), c;
int i, &z=i, A::*p=&A::y;
z=b.x; i=a.x; i=c.*p;
i=a++; i=::x+c.y; i=a+b;
b.h(i)=7;
}


5. 写出程序运行结果。
#include <iostream>
using namespace std;
class CT {
public :
CT () {
cout << "Default constructor called" << endl;
}
CT (const CT &rhs) {
cout << "Copy constructor called" << endl;
}
};
int main ()
{
CT ct; CT *p;
cout << "Step1" << endl;
p = new CT;
CT ct3 (*p);
cout << "Step2" << endl;
delete p;
return 0;
}
...全文
386 40 打赏 收藏 转发到动态 举报
写回复
用AI写文章
40 条回复
切换为时间正序
请发表友善的回复…
发表回复
品茶 2009-03-21
  • 打赏
  • 举报
回复
貌似第4题没人答对啊
不会用调试也该想到在赋值语句后面加上输出语句啊。
品茶 2009-03-21
  • 打赏
  • 举报
回复
此帖是为了调动新人积极性的吧。可是分不低啊,要不是有那么多人回复了,我也想混点分了,呵呵。
测试菜鸟 2009-03-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 amei2000go 的回复:]
放 vc 里一编译不就知道了
[/Quote]

同意
fairchild811 2009-03-21
  • 打赏
  • 举报
回复
up

boring
CONLONG 2009-03-20
  • 打赏
  • 举报
回复
一: 5 25
二: 150,55
225
三: A的值为:0 , 0
A的值为:0 , 0
A的值为:1 , 1
A的值为:0 , 0
A的值为:-1 , -1
四: Default constructor called
Step1
Default constructor called
Copy constructor called
Step2
raozhixiang882 2009-03-20
  • 打赏
  • 举报
回复
题有些难度
cxxer 2009-03-20
  • 打赏
  • 举报
回复
唉,
pfeidong 2009-03-20
  • 打赏
  • 举报
回复
无聊呀
pfeidong 2009-03-20
  • 打赏
  • 举报
回复
无聊呀
xmrforever 2009-03-20
  • 打赏
  • 举报
回复
一: 5 25
二: 150,55
225
三: A的值为:0 , 0
A的值为:0 , 0
A的值为:1 , 1
A的值为:0 , 0
A的值为:-1 , -1
四: Default constructor called
Step1
Default constructor called
Copy constructor called
Step2
danxuezx 2009-03-20
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 jimmy_w 的回复:]
100分太少了,你可用分那么多
[/Quote]
ding
dingpin 2009-03-20
  • 打赏
  • 举报
回复
[Quote=引用 27 楼 cnStreamlet 的回复:]
引用 3 楼 chenzhp 的回复:
为什么不在机器上运行一下呢


是啊
[/Quote]
...
yjuufgef 2009-03-20
  • 打赏
  • 举报
回复
laf
[Quote=引用 24 楼 xudeng22 的回复:]
楼主在考验咋们啊,回答答案的,一定被楼主骂为了这点分什么都做
[/Quote]
cnStreamlet 2009-03-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 chenzhp 的回复:]
为什么不在机器上运行一下呢
[/Quote]

是啊
amossavez 2009-03-20
  • 打赏
  • 举报
回复
敲一遍业花不少时间呀!!
上面都给完答案了!!
leewon1988 2009-03-20
  • 打赏
  • 举报
回复
k
还有比我懒的。。。服了
xudeng22 2009-03-20
  • 打赏
  • 举报
回复
楼主在考验咋们啊,回答答案的,一定被楼主骂为了这点分什么都做
Johnsen2009 2009-03-20
  • 打赏
  • 举报
回复
自己放到pc试一下就好了!
  • 打赏
  • 举报
回复
100分太少了,你可用分那么多
M_S_D_N 2009-03-20
  • 打赏
  • 举报
回复
有“分”能使“程序员”“编译”“程序”
q g t m
加载更多回复(19)

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧