有以下程序: include using namespace std; class sample {int x; public:void setx(
有以下程序:
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;
}
执行后的输出结果是【 】。
正确答案:5675,6,7 解析:本题考核对象指针与对象数组的应用。主函数中定义对象数组A,然后调用各自的setx()函数赋值,最后通过for循环输出各自内部变量,所以程序最后输出5,6,7。
词条内容仅供参考,如果您需要解决具体问题
(尤其在法律、医学等领域),建议您咨询相关领域专业人士。
