填空题
有以下程序:
#include <iostream>
using namespace std;
class sample
{
int x;
public:
void setx(int i)
{
x=i;
}
int putx ()
{
return x;
}
};
int main ( )
{
sample *p;
sample A[3];
A[0] .set>:(5);
A[1] .setx(6);
A[2] .setx(7);
for (int j=0;j<3;j++)
{
p=&A[j];
cout<<p->putx () <<", ";
}
cout<<end1;
return 0;
}
执行后的输出结果是{{U}} 【14】 {{/U}}。
【正确答案】
1、5,6,7
【答案解析】[解析] 本题考核对象指针与对象数组的应用。主函数中定义对象数组A,然后调用各自的setx()函数赋值,最后通过for循环输出各自内部变量,所以程序最后输出5,6,7。