一种班级量化评分的管理系统

· · 科技·工程

使用说明

直接复制源代码即可使用。

可对 Reason(加分/减分原因), REASONSIZE(加分/减分原因数量), SCORE(每个原因对应的加减分),A(班级名单文件存储位置), EXPORT(导出文件存储位置) 等变量进行调整以符合班级实际情况。

源代码

#include <bits/stdc++.h>
#include <unistd.h>
#include <fcntl.h>
using namespace std;
constexpr int REASONSIZE = 3, STARTSCORE = 80; //按照实际情况自行修改
string Reason[REASONSIZE] = {"竞赛", "考试成绩突出", "上课讲话与违纪"}; //按照实际情况自行修改
map<string, int> Student2Id;
int Score[REASONSIZE] = {10, 5, -5}; //按照实际情况自行修改
class TStudent {
public:
    string Name;
    int ThisScore;
    int Times[REASONSIZE];

    void Init(string Name1) {
        Name = Name1;
        ThisScore = 80;
        for (int &i: Times) {
            i = 0;
        }
    }

    void Init(string Name1, int Score1, int Times1[]) {
        Name = Name1;
        ThisScore = Score1;
        for (int j = 0; j < REASONSIZE; j++) {
            Times[j] = Times1[j];
        }
    }

    void Edit(int ReasonId) {
        Times[ReasonId]++;
        ThisScore += Score[ReasonId];
    }
} Students[55];

int N, Mode;
#define NAMES
#define A "data.txt" //可调整
#define EXPORT "scores.csv" //可调整

int main() {
    //自动导入
    ifstream File(A);
    streambuf *Original = cin.rdbuf();
    cin.rdbuf(File.rdbuf());
    cin >> N >> Mode;
    cerr << N << ' ' << Mode << '\n';
    for (int i = 1; i <= N; i++) {
        string Str;
        cin >> Str;
        if (Mode == 0) {
            Students[i].Init(Str);
        } else {
            int Score2, Times[REASONSIZE];
            cin >> Score2;
            for (int &j: Times) {
                cin >> j;
            }
            Students[i].Init(Str, Score2, Times);
        }
        Student2Id[Str] = i;
    }
    cerr << N << '\n';
    cin.rdbuf(Original);
    File.close();
#ifdef NAMES
    cout << "学生名单\n";
    for (int i = 1; i <= N; i++) {
        cout << Students[i].Name << '\n';
    }
#endif
    cout << "欢迎使用量化评分管理器 1.0!\n";
    cout << "输入 “完成” 以完成编辑\n";
    for (int i = 0; i < REASONSIZE; i++) {
        cout << "输入原因编号 " << i << " 表示" << Reason[i] << ",增加" << Score[i] << "分\n";
    }
    cout << "改分输入格式:【学生名】【原因编号】\n";
    string MODE;
    while (cin >> MODE) {
        //cin >> MODE;
        if (MODE == "完成") break;
        string Student = MODE;
        int Reason1;
        cin >> Reason1;
        int Id1 = Student2Id[Student];
        if (Id1 == 0) {
            cout << "班内没有此人,请重新输入!\n";
            continue;
        }else {
            cout << "编辑成功!\n";
        }
        Students[Id1].Edit(Reason1);
    }
    cout << "输入 ‘1’ 以导出,否则不导出\n";
    string Str;
    cin >> Str;
    if (Str == "1") {
        freopen(EXPORT, "w", stdout);
        // ofstream Excel("scores.csv");
        // cout.rdbuf(Excel.rdbuf());
        cout << ",当前分数,";
        for (const auto &j: Reason) {
            cout << j << ",";
        }
        cout << '\n';
        for (int i = 1; i <= N; i++) {
            cout << Students[i].Name << ',' << Students[i].ThisScore << ',';
            for (int j: Students[i].Times) {
                cout << Students[i].Times[j] << ',';
            }
            cout << '\n';
        }
    }
    // cout.rdbuf(Data.rdbuf());
    freopen(A, "w", stdout);
    cout << N << " 1\n";
    for (int i = 1; i <= N; i++) {
        cout << Students[i].Name << ' ' << Students[i].ThisScore << ' ';
        for (int j: Students[i].Times) {
            cout << j << ' ';
        }
        cout << '\n';
    }
    return 0;
}