You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.1 KiB

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
void InputStudentInfo(vector<pair<string, double>> &students) {
string name, gender;
double score;
cout << "<EFBFBD><EFBFBD>ϵͳֻ֧<EFBFBD>ְٷ<EFBFBD><EFBFBD>Ƴɼ<EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD>ּ<EFBFBD><EFBFBD><EFBFBD>"<<endl;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'end'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룩: ";
while (cin >> name >> gender >> score) {
if (name != "end") {
students.push_back(make_pair(name, score));
} else {
break;
}
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'end'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룩: ";
}
}
void CalculateAverageScore(const vector<pair<string, double>> &students, vector<double> &averages) {
for (const auto &student : students) {
if (student.second >= 60) {
// <20>ٶ<EFBFBD><D9B6>Ա<EFBFBD>Ϊ'm'<27><>ʾ<EFBFBD><CABE><EFBFBD>ԣ<EFBFBD>'f'<27><>ʾŮ<CABE><C5AE>
if (student.first[0] == 'm') {
averages[0] += student.second;
averages[1]++;
} else if (student.first[0] == 'f') {
averages[2] += student.second;
averages[3]++;
} else {
cout << "δ֪<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
}
} else {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>60<EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
}
}
}
void OutputAverageScore(const vector<double> &averages) {
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ: " << averages[0] / averages[1] << endl;
cout << "Ů<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ: " << averages[2] / averages[3] << endl;
}
void SaveToFile(const vector<double> &averages, const string &filename) {
ofstream outfile(filename);
outfile << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ: " << averages[0] / averages[1] << endl;
outfile << "Ů<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ: " << averages[2] / averages[3] << endl;
outfile.close();
}
int main() {
vector<pair<string, double>> students;
vector<double> averages(4, 0); // <20>ֱ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ů<EFBFBD><C5AE>ƽ<EFBFBD><C6BD><EFBFBD>֡<EFBFBD>Ů<EFBFBD><C5AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
InputStudentInfo(students);
CalculateAverageScore(students, averages);
OutputAverageScore(averages);
SaveToFile(averages, "student_stats.txt");
return 0;
}