数据结构课程设计预习——中国大学生计算机设计大赛省级赛事管理系统

本文描述了一款省级赛事管理系统的开发,涉及数据结构(如二叉搜索树)的应用,用于存储和管理赛事信息,包括读取和写入文件,以及实现关键功能如决赛模拟、地图导航、数据查询和算法分析。设计了合理的菜单交互,并强调代码规范和程序健壮性测试。
摘要由CSDN通过智能技术生成

课程设计内容

中国大学生计算机设计大赛省级赛事管理系统

  • 课程设计目的
  1. 熟练掌握线性表、栈、队列、串、数组、树和图等基本数据结构的逻辑特性和存储表示方法;熟练掌握各种基本数据结构的基本算法和其应用;熟练掌握问题分析、数据结构设计、程序设计的基本技能和技术。
  2. 能够综合运用数据结构与算法和相关的数学等理论知识对复杂工程中的算法问题进行抽象、分析和建模;能够依据工程实际问题的需求合理组织数据、并在计算机中有效地存储数据;能够针对复杂工程中的算法问题,设计出比较合理的解决方案,利用具体的编程语言实现解决方案,并具有一定的创新思维能力。
  3. 具有良好的工程素养和职业素养,诚信守法,能够坚持职业操守和道德规范;具有精益求精的工匠精神、创新精神和探索未知终身学习的意识;具有科技报国的社会责任感、使命感和爱国主义情操。

任务描述

设计一款赛事管理系统,实现赛务相关的数据管理及信息服务,该系统能够为省级赛事管理解决以下问题:

  1. 赛事信息管理

(2)决赛现场模拟

(3)决赛地图导览

任务要求:

  1. 请根据任务描述的问题,设计合理的菜单,菜单交互设计要合理,便于用户根据提示使用系统的所有功能。
  2. 赛事数据要求从文件(txt或excel)读入,修改后的信息能存入文件。

    3)第三个任务赛地目的地查询,需输出目的地(建筑物)名称、代号、简介等信息;最短路径的输出需包含途经地及最短路径值;并分析主要算法的时间复杂度

   4)请自行设计测试数据。使用全部合法数据,整体非法数据,局部非法数据对程序测试,以保证程序的健壮性。

    5)编码时请注意规范代码结构,重要的变量,函数要有清晰的注释;注重代码的效率和可重用性,实现低耦合、高内聚,不要将各种功能混在一个方法中编写。

【实现步骤提示】

  1)分析任务,进行功能设计,菜单设计;

2)定义数据结构,建议按照抽象数据类型的定义、表示和实现来描述,用类C语言(伪代码)来描述数据的存储表示和相应操作的具体实现过程。

3)设计合适的算法来实现其功能,并绘制函数调用关系图

部分代码

//使用C++实现赛事信息管理的示例,包括从文件中读取参赛队伍信息、添加参赛队伍、更新初赛成绩、查询参赛队伍信息和计算平均查找长度等功能。代码中使用二叉排序树来存储参赛队伍信息,并实现了基于二叉排序树的查找和插入操作。
// 参赛队伍类
class Team {
private:
    string teamName;
    string projectName;
    string school;
    string category;
    int prelimScore;

public:
    Team(const string& teamName, const string& projectName, const string& school, const string& category) {
        this->teamName = teamName;
        this->projectName = projectName;
        this->school = school;
        this->category = category;
        prelimScore = 0;
    }

    string getTeamName() const {
        return teamName;
    }

    string getProjectName() const {
        return projectName;
    }

    string getSchool() const {
        return school;
    }

    string getCategory() const {
        return category;
    }

    int getPrelimScore() const {
        return prelimScore;
    }

    void setPrelimScore(int score) {
        prelimScore = score;
    }
};

// 二叉排序树节点类
class TreeNode {
public:
    int key;
    Team team;
    TreeNode* left;
    TreeNode* right;

    TreeNode(int key, const Team& team) {
        this->key = key;
        this->team = team;
        left = nullptr;
        right = nullptr;
    }
};

// 二叉排序树类
class BinarySearchTree {
private:
    TreeNode* root;
    int nodeCount;
    int totalDepth;

    void insert(TreeNode*& node, int key, const Team& team, int depth) {
        if (node == nullptr) {
            node = new TreeNode(key, team);
            nodeCount++;
            totalDepth += depth;
        } else if (key < node->key) {
            insert(node->left, key, team, depth + 1);
        } else if (key > node->key) {
            insert(node->right, key, team, depth + 1);
        }
    }

    TreeNode* search(TreeNode* node, int key) const {
        if (node == nullptr || node->key == key) {
            return node;
        } else if (key < node->key) {
            return search(node->left, key);
        } else {
            return search(node->right, key);
        }
    }

public:
    BinarySearchTree() {
        root = nullptr;
        nodeCount = 0;
        totalDepth = 0;
    }

    void insert(int key, const Team& team) {
        insert(root, key, team, 1);
    }

    TreeNode* search(int key) const {
        return search(root, key);
    }

    int getNodeCount() const {
        return nodeCount;
    }

    double getAverageSearchLength() const {
        return (double)totalDepth / nodeCount;
    }
};

// 省级赛事管理系统类
class ManagementSystem {
private:
    BinarySearchTree teams;  // 使用二叉排序树存储参赛队伍信息

public:
    void loadTeamsFromFile(const string& filename) {
        ifstream file(filename);
        if (!file) {
            cout << "Failed to open file: " << filename << endl;
            return;
        }

        string line;
        while (getline(file, line)) {
            string teamName, projectName, school, category;
            stringstream ss(line);
            getline(ss, teamName, ',');
            getline(ss, projectName, ',');
            getline(ss, school, ',');
            getline(ss, category, ',');

            Team team(teamName, projectName, school, category);
            int key = stoi(teamName.substr(5));
            teams.insert(key, team);
        }

        file.close();
    }

    void addTeam(const string& teamName, const string& projectName, const string& school, const string& category) {
        Team team(teamName, projectName, school, category);
        int key = stoi(teamName.substr(5));
        teams.insert(key, team);
    }

    void updatePrelimScore(int teamId, int score) {
        TreeNode* node = teams.search(teamId);
        if (node != nullptr) {
            node->team.setPrelimScore(score);
        }
    }

    void displayTeamInfo(int teamId) const {
        TreeNode* node = teams.search(teamId);
        if (node != nullptr) {
            const Team& team = node->team;
            cout << "Team ID: " << teamId << endl;
            cout << "Team Name: " << team.getTeamName() << endl;
            cout << "Project Name: " << team.getProjectName() << endl;
            cout << "School: " << team.getSchool() << endl;
            cout << "Category: " << team.getCategory() << endl;
            cout << "Prelim Score: " << team.getPrelimScore() << endl;
        }
    }

    void displayAllTeams() const {
        cout << "All Teams:\n";
        cout << "-------------------\n";
        for (int i = 1; i <= teams.getNodeCount(); i++) {
            TreeNode* node = teams.search(i);
            if (node != nullptr) {
                const Team& team = node->team;
                cout << "Team ID: " << i << endl;
                cout << "Team Name: " << team.getTeamName() << endl;
                cout << "Project Name: " << team.getProjectName() << endl;
                cout << "School: " << team.getSchool() << endl;
                cout << "Category: " << team.getCategory() << endl;
                cout << "Prelim Score: " << team.getPrelimScore() << endl;
                cout << endl;
            }
        }
    }

    void displayCategoryInfo(const string& category) const {
        cout << "Teams in " << category << " Category:\n";
        cout << "-------------------\n";
        for (int i = 1; i <= teams.getNodeCount(); i++) {
            TreeNode* node = teams.search(i);
            if (node != nullptr) {
                const Team& team = node->team;
                if (team.getCategory() == category) {
                    cout << "Team ID: " << i << endl;
                    cout << "Team Name: " << team.getTeamName() << endl;
                    cout << "Project Name: " << team.getProjectName() << endl;
                    cout << "School: " << team.getSchool() << endl;
                    cout << "Prelim Score: " << team.getPrelimScore() << endl;
                    cout << endl;
                }
            }
        }
    }

    void calculateASL() const {
        double asl = teams.getAverageSearchLength();
        cout << "Average Search Length: " << asl << endl;
    }
};

int main() {
    ManagementSystem system;

    // 加载参赛队伍信息
    system.loadTeamsFromFile("team.txt");

    // 添加参赛队伍
    system.addTeam("Team100", "Project100", "School100", "CategoryA");
    system.addTeam("Team101", "Project101", "School101", "CategoryB");

    // 更新参赛队伍的初赛成绩
    system.updatePrelimScore(1, 80);
    system.updatePrelimScore(2, 75);

    // 查询参赛队伍的信息
    int teamId;
    cout << "Enter Team ID: ";
    cin >> teamId;
    TreeNode* node = system.search(teamId);
    if (node != nullptr) {
        const Team& team = node->team;
        cout << "Team Name: " << team.getTeamName() << endl;
        cout << "Project Name: " << team.getProjectName() << endl;
        cout << "School: " << team.getSchool() << endl;
        cout << "Category: " << team.getCategory() << endl;
        cout << "Prelim Score: " << team.getPrelimScore() << endl;
    } else {
        cout << "Team not found.\n";
    }

    // 显示全部参赛队伍的信息
    system.displayAllTeams();

    // 显示某个赛事类别的参赛队伍信息
    system.displayCategoryInfo("CategoryA");

    // 计算平均查找长度
    system.calculateASL();

    return 0;
}
//使用Team类表示参赛队伍,包含队伍名称、参赛作品名称、学校、赛事类别和初赛成绩等信息。使用TreeNode类表示二叉排序树的节点,包含参赛队伍信息和节点键值。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值