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 ansys fluent计算闪退
- ¥15 有关wireshark抓包的问题
- ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
- ¥15 向数据表用newid方式插入GUID问题
- ¥15 multisim电路设计
- ¥20 用keil,写代码解决两个问题,用库函数
- ¥50 ID中开关量采样信号通道、以及程序流程的设计
- ¥15 U-Mamba/nnunetv2固定随机数种子
- ¥15 vba使用jmail发送邮件正文里面怎么加图片
- ¥15 vb6.0如何向数据库中添加自动生成的字段数据。