C++高手进来!

来源:百度知道 编辑:UC知道 时间:2024/06/12 12:39:01
1. 定义一个学生成绩类marks,它可以存放若干学生的成绩(单科),分别用友元函数和友元类两种方法,求出所有学生中成绩最高与最低的学生。

//计算总分吧?
#include<iostream>
#define P(x1) cout<<#x1"="<<x1<<endl;
using namespace std;

class X {
int chemistry,physics,chinese,
math,biology;
int count()
{
return this->biology+this->chemistry
+this->chinese+this->math
+this->math+this->physics;}
friend class marks;
};
class marks {
X* x;
public:
int d() const{
return x->count();}
marks(int a=0,int b=0,int c=0,int d=0,int e=0){
x= new X;
x->biology =a;x->chemistry=b;x->chinese=c;
x->math=d;x->physics=e;
}
~marks(){
delete x;}
};
int f1(const marks* h);
int f2(const marks* h);
int main(){
marks m1[]={
marks(50,60,70,80,90),
marks(55,65,75,85,95),
marks(56,66,76,86,96),
};
cout<<"The max value is "<<f1(m1)<<endl;