C++高手进来帮忙 急

来源:百度知道 编辑:UC知道 时间:2024/06/23 23:35:45
作业题:
1.有一个学生类student,包括学生姓名、成绩,设计一个友元函数,比较两个学生成绩的高低,并求出最高分者和最低分者。
2.设计一个类sample,它有两个私有数据成员A[ ]和n(A中元素个数),将对A[ ]中数据进行选择法和冒泡法排序的函数放入一个友元类process中。

针对你的题写的算法,实现和调试我没写
第一题:
class student
{
public:
student(string name, float score)
{
this->name = name;
this->score = score;
}
friend void compare(student s1, student s2);
private:
string name;
float score;
};
void compare(student s1, student s2)
{
if(s1.score>s2.socre)
cout<<"最高分"<<s1.name<<"最低分"<<s2.name<<endl;
else
cout<<"最高分"<<s2.name<<"最低分"<<s1.name<<endl;
}

第二题:
class process;
class sample
{
public:
sample(int n)
{
this->n = n;
A = new int[this->n];
}
~sample()
{
delete[] A;
}
friend class process;
private:
int * A;
int n;
};

class process
{
void chooseSort(sample s)
{
//选择排序
}
void bubbleSort(sample s