2条回答 默认 最新
- 索利亚噶通 2021-12-16 19:08关注
这个空行那里注意下(有用请采纳)
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; class Stu{ private: string name; int programScore; int introductionScore; int englishScore; public: Stu(string name, int programScore, int introductionScore, int englishScore); void showInfo(); int getTotalScore() const; int getProgramScore() const; int getIntroductionScore() const; }; Stu::Stu(string name, int programScore, int introductionScore, int englishScore){ this->name = name; this->programScore = programScore; this->introductionScore = introductionScore; this->englishScore = englishScore; } void Stu::showInfo(){ cout << this->name << " "; cout << getTotalScore() << " "; cout << this->programScore << " "; cout << this->introductionScore << " "; cout << this->englishScore << endl; } int Stu::getTotalScore() const{ return this->programScore + this->introductionScore + this->englishScore; } int Stu::getIntroductionScore() const{ return this->introductionScore; } int Stu::getProgramScore() const{ return this->programScore; } bool cmp(const Stu& stu1, const Stu& stu2){ if (stu1.getTotalScore() != stu2.getTotalScore()) // 总分不等的情况下 return stu1.getTotalScore() > stu2.getTotalScore(); if (stu1.getProgramScore() != stu2.getProgramScore()) // C语言成绩不等的情况下 return stu1.getProgramScore() > stu2.getProgramScore(); return stu1.getIntroductionScore() > stu2.getIntroductionScore(); } int main(){ int N, programScore, introductionScore, englishScore; string name; vector<Stu> stuScore; // 存储所有人的分数 while(cin >> N){ for (int i = 0; i < N; i++){ cin >> name >> programScore >> introductionScore >> englishScore; Stu stu = Stu(name, programScore, introductionScore, englishScore); stuScore.push_back(stu); } sort(stuScore.begin(), stuScore.end(), cmp); for(vector<Stu>::iterator it = stuScore.begin(); it != stuScore.end(); it++){ it->showInfo(); } cout << endl; stuScore.clear(); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 在现有系统基础上增加功能
- ¥15 远程桌面文档内容复制粘贴,格式会变化
- ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
- ¥15 这种微信登录授权 谁可以做啊
- ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
- ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
- ¥15 网络设备配置与管理这个该怎么弄
- ¥20 机器学习能否像多层线性模型一样处理嵌套数据
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页