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 显示两个unsuccessful(标签-pytorch|关键词-软件版本)
  • ¥15 串口通信传输字符的质量控制
  • ¥50 xslt如何让block撑满页面
  • ¥15 vs的显示无法启动IIS Express Web服务器,怎么解决?
  • ¥20 一个python博客项目的相关图例
  • ¥15 轮廓提取也提取不到,有没有别的方法,如何解决?
  • ¥50 Js和c++如何将含有图片的excel文件上传到后台服务器
  • ¥15 光电神经网络,FPGA
  • ¥20 通过防火墙出入站阻止游戏程序联网失效
  • ¥15 鼠标是可以在QT界面上移动的,但是热拔插鼠标无法移动了同时板子上是没问题的,如何解决?