Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

31232 855242 郭凱明 0407作業 #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions 855242/Average_vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <vector>
using namespace std;

int main() {
vector<int> scores = {};

int score = -1, totalScore;
while(score != 0) {
cout << "請請輸入" << scores.size() + 1 << "的成績(輸入0結束):";
cin >> score;
scores.push_back(score);
totalScore += score;
}
scores.pop_back();

int seatNumber = 1, minScore = 101, maxScore = 0;
vector<int> minPerson = {}, maxPerson = {};
for (auto i: scores) {
if (i >= maxScore) {
if (i > maxScore) {
maxScore = i;
maxPerson = {};
}
maxPerson.push_back(seatNumber);
}
if (i <= minScore) {
if (i < minScore) {
minScore = i;
minPerson = {};
}
minPerson.push_back(seatNumber);
}
seatNumber ++;
}

cout << "班級總分為" << totalScore << "分\n";
cout << "班級總平均為" << (float)totalScore / scores.size() << "分\n";
for (auto i : maxPerson) cout << " " << i ;
cout << "號為最高分" << maxScore << "分 ; ";
for (auto i : minPerson) cout << " " << i;
cout << "號為最低分" << minScore << "分";
}