回复 10楼 hujihong520
你逻辑是乱的...而且基本语法也不懂...
就是几个代码段来回切换着拼...
急着交作业啊?
我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
#include <iostream> #include <vector> #include <string> using namespace std; class student { public: student(int n, string nam, float s) : no(n), name(nam), score(s) {} int no; char num; string name; float score; }; int main() { char ch; std::vector<student> vecStu; cout << "输入q结束" << endl; int num; std::string name; float score; while(ch != 'q') { cout<<"请输入学生1的学号:"; cin>>num; cout<<"请输入学生1的姓名:"; cin>>name; cout<<"请输入学生1的成绩:"; cin>>score; student stu(num, name, score); vecStu.push_back(stu); } if(vecStu.size() > 0) { int max = 0, min = 0; float sum = 0.0f; for (int index = 1; index < vecStu.size(); ++index) { sum += vecStu.at(index).score; if(vecStu.at(index).score > vecStu.at(max).score) { max = index; } else if(vecStu.at(index).score < vecStu.at(min).score) { min = index; } } cout<<"平均分:"<<"ave="<<sum/vecStu.size()<<endl; cout<<"最高分学号:"<<vecStu[max].num<<"最高分姓名:"<<vecStu[max].name<<"最高分分数:"<<vecStu[max].score<<endl; cout<<"最低分学号:"<<vecStu[min].num<<"最低分姓名:"<<vecStu[min].name<<"最低分分数:"<<vecStu[min].score<<endl; } return 0; }