#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
string num;
string name;
float sc;
Student()
{
num = "101";
name = "张三";
sc = 100.0;
}
Student(string n, string nam, float sc1) :num(n), name(nam), sc(sc1) {}
//插入数据函数
void update(int i);
void display();
};
void Student::update(int i)
{
cout << "请输入第" << i + 1 << "名学生的学号、姓名、成绩" << endl;
cout << "学号:";
cin >> num;
cout << "姓名:";
cin >> name;
cout << "成绩:";
cin >> sc;
cout << "\n";
}
void Student::display()
{
cout << "成绩最好者的学号:" << num <<
"\t" << "成绩最好者的姓名:" << name << endl;
}
//找到最高成绩的下标
int max1(const Student* p0)//常指针
{
float max = p0->sc;
int i;
int ans;
for (i = 0; i < 5; i++)
{
if (max < p0->sc)
{
max = p0->sc;
ans = i;
}
p0++;
}
//ans= i;
return ans;
}
int main()
{
int i;
//int best;
Student stu[5];
//输入
for (i = 0; i < 5; i++)
{
stu[i].update(i);
}
//输出结果
stu[max1(&stu[0])].display();
return 0;
}
求5名学生的最高的分者的学号和姓名 指针做函数参数
最新推荐文章于 2022-11-27 17:59:51 发布