#include
#include
using namespace std;
#define STUDENTNUM 5
class Student
{
public:
Student() {}
Student(double score, unsigned int num, string name);
double GetScore();
unsigned int GetNum();
private:
double m_dScore;
unsigned int m_iNum;
string m_strName;
};
Student::Student(double score, unsigned int num, string name)
{
m_dScore = score;
m_iNum = num;
m_strName = name;
}
double Student::GetScore()
{
return m_dScore;
}
unsigned int Student::GetNum()
{
return m_iNum;
}
unsigned int GetMaxScore(Student *st)
{
int MaxScoreIndex = 0;
for(int i = 0; i < STUDENTNUM - 1; i++)
{
int Max = ((st + i)->GetScore()) > ((st + i + 1)->GetScore()) ? i : (i + 1);
MaxScoreIndex = ((st + MaxScoreIndex)->GetScore()) > ((st + Max)->GetScore()) ? MaxScoreIndex : Max;
}
return (st + MaxScoreIndex)->GetNum();
}
void main()
{
Student StuInfo[5];
StuInfo[0] = Student(100, 1, "zhangsan");
StuInfo[1] = Student(90, 2, "lisi");
StuInfo[2] = Student(80, 3, "lucy");
StuInfo[3] = Student(70, 4, "hanmeimei");
StuInfo[4] = Student(60, 5, "joey");
int Num = GetMaxScore(StuInfo);
cout<
粗略写了下,希望能看懂。。
刚学c++还在学习
/*包含必要头文件*/
class student
{
int no;
int score;
};
void max(const vector
{
int max=-1;
int no=-1;
for(vector
iter!dat.end();iter++)
{
if (iter->score>max)
{
max=iter->score;
no=iter->no;
}
}
cout<<"学号"<
}
int main(void)
{
vector
/*初始数据*/
max(st);
return 0;
}