2201_75828410 2023-12-10 23:55 采纳率: 0%
浏览 15
已结题

有没有哪位厉害的人可以用C#可视化呀

要求如下,一个简单的学生课程系统。
我把代码发给你,根据代码用C#可视化就行。没学过C#,但现在需要用这个写,完全不会,临时学已经来不及了。

img

代码如下:


```c#
#include <iostream>
#include <string>
#include <vector>
#include <limits>
using namespace std;

class Student {
public:
    Student(string id, string name, string sex)
        : id_(id), name_(name), sex_(sex) {}

    string GetId() const { return id_; }
    string GetName() const { return name_; }
    string GetSex() const { return sex_; }
private:
    string id_; // 学生学号
    string name_; // 学生姓名
    string sex_; // 学生性别
};

class CourseScore {
public:
    CourseScore(string courseName, float score)
        : courseName_(courseName), score_(score) {}

    string GetCourseName() const { return courseName_; }
    float GetScore() const { return score_; }
private:
    string courseName_; // 课程名称
    float score_; // 成绩
};

class StudentCourseScore {
public:
    StudentCourseScore(Student student)
        : student_(student) {}

    void AddCourseScore(CourseScore courseScore) {
        courseScores_.push_back(courseScore);
    }

    Student GetStudent() const { return student_; }
    vector<CourseScore> GetCourseScores() const { return courseScores_; }
private:
    Student student_; // 学生信息
    vector<CourseScore> courseScores_; // 课程成绩信息
};

void ByNameQuery(const vector<StudentCourseScore>& students) {
    string targetName;
    cout << "请输入要查询的学生姓名:";
    cin >> targetName;

    bool found = false;
    for (const auto& studentCourseScore : students) {
        Student student = studentCourseScore.GetStudent();
        if (student.GetName() == targetName) {
            found = true;

            cout << "学号:" << student.GetId() << ",姓名:" << student.GetName() << ",性别:" << student.GetSex() << endl;
            cout << "课程成绩信息:" << endl;
            for (const auto& courseScore : studentCourseScore.GetCourseScores()) {
                cout << "科目名称:" << courseScore.GetCourseName() << ",分数:" << courseScore.GetScore() << endl;
            }
            break;
        }
    }

    if (!found) {
        cout << "找不到指定的学生信息。" << endl;
    }
}

void ByIdQuery(const vector<StudentCourseScore>& students) {
    string targetId;
    cout << "请输入要查询的学生学号:";
    cin >> targetId;

    bool found = false;
    for (const auto& studentCourseScore : students) {
        Student student = studentCourseScore.GetStudent();
        if (student.GetId() == targetId) {
            found = true;

            cout << "学号:" << student.GetId() << ",姓名:" << student.GetName() << ",性别:" << student.GetSex() << endl;
            cout << "课程成绩信息:" << endl;
            for (const auto& courseScore : studentCourseScore.GetCourseScores()) {
                cout << "科目名称:" << courseScore.GetCourseName() << ",分数:" << courseScore.GetScore() << endl;
            }
            break;
        }
    }

    if (!found) {
        cout << "找不到指定的学生信息。" << endl;
    }
}

void ByCourseQuery(const vector<StudentCourseScore>& students) {
    string targetCourse;
    cout << "请输入要查询的科目名称:";
    cin >> targetCourse;

    bool found = false;
    float maxScore = numeric_limits<float>::min();
    float minScore = numeric_limits<float>::max();
    string maxStudentName, minStudentName;

    for (const auto& studentCourseScore : students) {
        Student student = studentCourseScore.GetStudent();
        for (const auto& courseScore : studentCourseScore.GetCourseScores()) {
            if (courseScore.GetCourseName() == targetCourse) {
                found = true;
                if (courseScore.GetScore() > maxScore) {
                    maxScore = courseScore.GetScore();
                    maxStudentName = student.GetName();
                }
                if (courseScore.GetScore() < minScore) {
                    minScore = courseScore.GetScore();
                    minStudentName = student.GetName();
                }
            }
        }
    }

    if (found) {
        cout << "科目名称:" << targetCourse << ",最高分学生:" << maxStudentName << ",分数:" << maxScore << endl;
        cout << "科目名称:" << targetCourse << ",最低分学生:" << minStudentName << ",分数:" << minScore << endl;
    }
    else {
        cout << "找不到指定的科目信息。" << endl;
    }
}

int main() {
    int n;

    cout<<"信息录入"<<endl
        << "请输入学生数目:";
    cin >> n;

    vector<StudentCourseScore> students;
    for (int i = 0; i < n; ++i) {
        string id, name, sex;
        cout << "请输入第 " << i + 1 << " 个学生的学号、姓名和性别(格式:学号 姓名 性别):";
        cin >> id >> name >> sex;

        Student student(id, name, sex);

        int courseNum;
        cout << "请输入课程数目:";
        cin >> courseNum;

        StudentCourseScore studentCourseScore(student);

        for (int j = 0; j < courseNum; ++j) {
            string courseName;
            float score;
            cout << "请输入第 " << j + 1 << " 门课程名称和分数(格式:课程名称 分数):";
            cin >> courseName >> score;

            CourseScore courseScore(courseName, score);
            studentCourseScore.AddCourseScore(courseScore);
        }

        students.push_back(studentCourseScore);
    }

    int choice;
    bool found = false; // 声明并初始化 found 变量
    string targetName = ""; // 声明并初始化 targetName 变量

    do {
        cout << "----------------------------------------------------------------------" << endl;
        cout << "请选择查询方式:" << endl;
        cout << "1. 通过姓名查询学生成绩" << endl;
        cout << "2. 通过学号查询学生成绩" << endl;
        cout << "3. 输出指定科目分数最高和最低的学生课程成绩信息" << endl;
        cout << "4. 输出指定学生的科目分数最高和最低分" << endl;
        cout << "5. 退出程序" << endl;
        cout << "----------------------------------------------------------------------" << endl;
        cin >> choice;

        switch (choice) {
        case 1:
            ByNameQuery(students);
            break;
        case 2:
            ByIdQuery(students);
            break;
        case 3:
            ByCourseQuery(students);
            break;
        case 4:
            // Add code for query by student
            cout << "请输入要查询的学生姓名:";
            cin >> targetName;

            found = false; // 重置 found 变量

            for (const auto& studentCourseScore : students) {
                Student student = studentCourseScore.GetStudent();
                if (student.GetName() == targetName) {
                    found = true;

                    cout << "学号:" << student.GetId() << ",姓名:" << student.GetName() << ",性别:" << student.GetSex() << endl;
                    cout << "科目分数最高:" << endl;
                    float maxScore = numeric_limits<float>::min();
                    string maxCourseName;
                    for (const auto& courseScore : studentCourseScore.GetCourseScores()) {
                        if (courseScore.GetScore() > maxScore) {
                            maxScore = courseScore.GetScore();
                            maxCourseName = courseScore.GetCourseName();
                        }
                    }
                    cout << "科目名称:" << maxCourseName << ",分数:" << maxScore << endl;

                    cout << "科目分数最低:" << endl;
                    float minScore = numeric_limits<float>::max();
                    string minCourseName;
                    for (const auto& courseScore : studentCourseScore.GetCourseScores()) {
                        if (courseScore.GetScore() < minScore) {
                            minScore = courseScore.GetScore();
                            minCourseName = courseScore.GetCourseName();
                        }
                    }
                    cout << "科目名称:" << minCourseName << ",分数:" << minScore << endl;
                    break;
                }
            }

            if (!found) {
                cout << "找不到指定的学生信息。" << endl;
            }
            break;
        case 5:
            cout << "退出程序。" << endl;
            break;
        default:
            cout << "输入无效的选项。" << endl;
            break;
        }
    } while (choice != 5);

    return 0;
}

```

  • 写回答

18条回答 默认 最新

  • threenewbee 2023-12-11 00:18
    关注
    获得0.75元问题酬金

    无非就是winforms拖拖控件,很简单的。

    评论

报告相同问题?

问题事件

  • 系统已结题 12月18日
  • 修改了问题 12月11日
  • 创建了问题 12月10日

悬赏问题

  • ¥15 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错