首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

又来有关问题拉` 程序呀\C+

2012-03-24 
又来问题拉``` 程序高手进呀\C+在下面横线处填上适当的语句,使程序功能完整。#include iostream.hclassA{

又来问题拉``` 程序高手进呀\C+
在下面横线处填上适当的语句,使程序功能完整。
#include <iostream.h>
class   A
{
private   :int   x;
public:
  int   get(){_______}\\去X值
  void   init(int   i){x=i;}
};
void   main(){A   a;a.init(3)};
_______;\\说明引用
int   n=r.get();\\   访问所引用对象的成员   n=3
cout < <n;
}

该题中第二个空填:A&r=a           不明白了。。       需要讲下为什么要用&     r


2\下面程序的执行结果是______.
include <iostream.h>
class   CCounter
{
int   value;
public:
CCounter();
CCounter(int   val);
~CCounter();
};
class   CExample
{
int   value;
public:
CCounter   car;
CExample();
CExample(int   val);
void   Display();
~CExample();
};
CCounter::CCounter()
{
cout < < "CCounter   Constructuctor1 " < <endl;
value=0;
}
CCounter::CCounter(int   val)
{
cout < < "CCounter   Constructor2 " < <endl;
value=val;
}
CCounter::~CCounter()
{
cout < < "CCounter   Destructor " < <endl;
}
CExample::CExample()
{
cout < < "CExample   Constructor1 " < <endl;
value=0;
}
CExample::CExample(int   val)
{
cout < < "CExample   Constructor2 " < <endl;
value=val;
}
void   CExample::Display()
{
cout < < "value= " < <value < <endl;
}
CExample::~CExample()
{
cout < < "CExample   Destructor " < <endl;
}
void   main()
{
CExample   e(2);
e.Display();
}


输出结果为:
CCounter   C……1
CCounter   C……2
value=2
CEXAMPLE……DE……
CCounter……DEST……

为什么cout   value之前的构析没COUT。而在最后COUT了。。。

结果

3、下面程序的输出结果是______.
#include <iostream>
using   namespace   std;
class   SS
{
private:
int   x,y;
public:
SS()
{
x=0;
y=0;
}
SS(int   i,int   j)
{
x=i;
y=j;
}
void   disp()
{
cout < < "x= " < <x < < ",y= " < <y < <endl;
}
};
void   main()
{
SS   c[2][4];
int   x=10,y=10;
for(int   i=0;i <2;i++)
for(int   j=0;j <4;j++)
c[i][j]=SS(x+=2,y+=10);
SS(*p)[4]=c;
for(i=0;i <2;i++)
{
for(int   j=0;j <4;j++)
(*(*(p+i)+j)).disp();
}
}

结果是从X=12       Y=20     开始COUT     进行FOR循环

为什么循环8次??  


[解决办法]
作业题 自己看书
别人帮你做是害了你
[解决办法]
哦 错了
该题中第二个空填:A&r=a 不明白了。。 需要讲下为什么要用& r


从main(你多打了一个})中你可以看到 给a初始化了3
这时a.get() ==3
而下面冒出来一个
因为后面用了int n=r.get();\\ 访问所引用对象的成员 n=3
所以r是a的引用,所谓引用,也就是“绰号”的意思
所以那个空子就是要你给a起一个绰号,即:
A &r=a
[解决办法]
第二个没看懂你的意思
[解决办法]
第一个题的第二空,使用&的意思,c++中特有的引用类型的,定义了一个类A的对象a的引用,就是给对象小a起了个别名.建议先去看c++!!!!

热点排行