单选题
若有以下程序: #include <iostream> using namespace std; class sample { private: int x; public: sample() { } void setx(int i) { x=i; } friend int fun(sample B[],int n) { int m=O; for (int i=O; i<n; i++) { if(B[i].x>m) m=B [i].x; } return m; } }; int main ( ) { sample A[10]; int arr[]={90,87,42,78,97,84,60,55,78,65}; for (int i=O;i<10;i++) A[i]. setx (arr[i]); cout<<fun(A, 10)<<end1; return 0; } 该程序运行后的输出结果是( )。
【正确答案】
A
【答案解析】[解析] 程序中定义了一个类sample,以及类sample的友元函数fun()。在主函数中,通过for循环调用各数组对象中的setx成员函数给各个对象的私有数据成员赋值。而函数fun()的功能是返回各个数组对象中的最大私有成员数据的值。