![]() ![]() |
|
二级模拟试题:C++习题与解析(友元-03) | |
作者:佚名 文章来源:不详 点击数 更新时间:2008/4/18 16:08:08 文章录入:杜斌 责任编辑:杜斌 | |
|
|
解: #include #include class student { char name[10]; int deg; public: student(char na[],int d) { strcpy(name,na); deg=d; } char *getname(){ return name;} friend int compare(student &s1,student &s2) { if(s1.deg>s2.deg) return 1; else if(s1.deg==s2.deg) return 0; else return -1; } }; void main() { student st[]={student("王华",78),student("李明",92),student("张伟",62),student("孙强",88)}; int i,min=0,max=0; 来源:www.examda.com for(i=1;i<4;i++) { if(compare(st[max],st[i])==-1) max=i; else if(compare(st[i],st[min])==1) min=i; } cout<<"输出结果:"< 本程序的执行结果如下: 输出结果: 最高分者:李明 最低分者:张伟 |
|
![]() ![]() |