数据结构课设

项目1.1:计算机设计大赛赛事统计

1.问题分析及任务定义

【问题描述】

参加计算机设计大赛的n个学校编号为1~n,赛事分成m个项目,项目的编号为1~m.设计一款赛事管理系统,实现赛务相关的数据管理及信息服务.

【基本要求】

(1)能够管理各参赛队的基本信息;包括增加、删除、修改参赛队伍的信息。

(2)从team.txt中读取参赛队伍的基本信息,实现基于二叉排序树的查找。
(3)能够提供按参赛学校查询参赛团队。

【设计要求】

1)赛事数据要求存入文件(txt或excel)并能读入查询;

3)输入数据形式和范围:赛事相关数据可从键盘输入,或自文件导入。

4)界面要求:交互设计要合理,每个功能可以设计菜单,用户根据提示,完成相关功能的要求。

2.数据结构的选择和概要设计

【逻辑设计】

抽象数据类型的定义、表示和实现:

 定义数据类:

一、
       //单链表结点定义
struct Team {
    string teamId;                 // 参赛队编号,
    string projectName;             // 参赛作品名称,
    string school;                // 参赛学校,
    string category;            // 赛事类别,
    string participants;        // 参赛者,
    string coach;                // 指导老师
    struct Team* next;            // 指针域
};

class team_class{
public:
    team_class()
    {
        head = new Team;
        head->next = NULL;
    }
    void menu(); // 主菜单
    void Show();//显示创建参赛队伍信息
    void AddTeam();//增加参赛队伍信息
    void DeleteTeam(string);//删除参赛队伍信息
    void ModifyTeam(); // 修改参赛队伍信息
    void callFinalRooms(); // 叫号系统
private:
    struct Team* head;
};

二、

// 二叉树结构定义
struct BSTNode {
    Team data;
    BSTNode* left;
    BSTNode* right;
};

查询方法:

        1、按学号在二叉树中实现查找,成功则输出其赛队信息,且输出成功查找的ASL(平均查找长度)及其公式;

        2、按参赛学校查找所有该学校参加的队伍,并输出所有该学校的参赛队伍的参赛信息。

【物理设计】

       单链表:

        struct Team{(包含参赛信息)struct Team* next;   // 指针域};

        struct team_class{}

        二叉树:

         struct BSTNode{

            Team data;
            BSTNode* left;
            BSTNode* right;

};

实现增删改操作。

项目1.2:决赛叫号系统

1.问题分析以及任务定义

【问题描述】

为省赛现场设计一个决赛叫号系统。

【任务定义】

(1)所有参赛队按赛事组织文件中的赛事类别分到9个决赛室,决赛室按顺序叫号,被叫号参赛队进场,比赛结束后,下一参赛队才能进赛场。

(2)请模拟决赛叫号系统,演示省赛现场各决赛室的参赛队进场情况。(模拟时,要能直观展示叫号顺序与进场秩序一致)

2.数据结构的选择和概要设计

【逻辑设计】

// 插入节点到二叉排序树中
void Insert(BSTNode*& root, Team x) {
    if (!root) {
        root = new BSTNode{ x, nullptr, nullptr };
        return;
    }
    if (x.teamId < root->data.teamId) { // 左小右大
        Insert(root->left, x);
    }
    else {
        Insert(root->right, x);
    }
}

// 叫号系统************************************************************************************************

void team_class::callFinalRooms(){}

【物理设计】

在callFinalRooms()函数中定义:
    vector<string> category_names;  // 将所有赛事类别装入该容器
    vector<string> all_category; // 将项目按照赛事类别依次放入改容器
    string category_na;

项目3:校园导游咨询 

1.问题分析以及任务定义

【问题描述】

赛事系统为参赛者提供赛地的校园导游程序,为参赛者提供各种路径导航的查询服务。

【基本要求】

(1)赛事系统为参赛者提供赛地的校园导游程序,为参赛者提供各种路径导航的查询服务。

(2)可为参赛者提供校园地图中任意目标地相关信息的查询.

(3)提供任意两个目标地的导航查询,即查询任意两个目的地之间的一条最短路径。

【设计要求】

赛地目的地查询,需提供目的地名称、代号、简介、两地之间路径长度等信息。

2.数据结构的选择和概要设计

【逻辑设计】

     定义景点类,类中存放景点名称(string)、代号(int)、简介(string)等信息. 来访者若需查询景点信息,则选择查询功能并输入要查询的景点,程序即展示该景点的相关信息;

     定义边类,存放路径长度(int).来访者若需查询路径信息,则选择查询功能并输入要查询的两个景点的路径,程序即展示一条最短路径。

     校园平面为无向图,图中的每个结点代表校园内的一个景点,该结构体中包含该景点的详细信息。String类型的景点名称,int类型的景点代号,String类型的景点简介等。

【物理设计】

// 结点的结构体--代表实际中的景点
typedef struct {
    int Num;//景点的编号
    string name;       //校园景点名
    string info;    //校园景点的描述信息
}VextexType;

// 邻接矩阵的数据类型 
typedef struct {
    int AdjMatrix[MAXVEX][MAXVEX]; //用二维数组来存放邻接矩阵 
    VextexType vex[MAXVEX];    //存放顶点信息
    int vexnum;        //顶点数 
    int arcnum;     //边数 
}MGraph;

利用Floyd算法(弗洛伊德算法)求最短路径:

        两个准备的二维数组:
        int PathMatirx[MAXVEX][MAXVEX];//记录对应点的最小路径的前驱点,例如p(1,3) = 2 说明顶点1到顶点3的最小路径要经过2;
        int ShortPath[MAXVEX][MAXVEX];//记录顶点间的最小路径值。

完整代码:

#include <iostream>
#include <string>
#include <fstream>
#include<vector>
#include<cstdlib> 
#include "stdio.h"
#include <sstream> // istringstream函数
#include<queue>
#include <iomanip>    //setw
#include<set>
#include <Windows.h>

using namespace std;

#define MAXVEX 13     //最大顶点个数 
#define INFINITY 3333//图的矩阵中A(i,i)记为0,若没有通路,记为INFINITY = 3333
#define NONE 99999
int PathMatirx[MAXVEX][MAXVEX];
int ShortPath[MAXVEX][MAXVEX];
int bianhao[MAXVEX];

//单链表结点定义
struct Team {
    string teamId;                 // 参赛队编号,
    string projectName;             // 参赛作品名称,
    string school;                // 参赛学校,
    string category;            // 赛事类别,
    string participants;        // 参赛者,
    string coach;                // 指导老师
    struct Team* next;            // 指针域
};

class team_class{
public:
    team_class()
    {
        head = new Team;
        head->next = NULL;
    }
    void menu(); // 主菜单
    void AddTeam();//增加参赛队伍信息
    void DeleteTeam(string);//删除参赛队伍信息
    void ModifyTeam(); // 修改参赛队伍信息
    void callFinalRooms(); // 叫号系统
private:
    struct Team* head;
};

// 二叉树结构定义
struct BSTNode {
    Team data;
    BSTNode* left;
    BSTNode* right;
};

BSTNode* root = nullptr;
vector<Team> teams;

// 结点的结构体--代表实际中的景点
typedef struct {
    int Num;//景点的编号
    string name;       //校园景点名
    string info;    //校园景点的描述信息
}VextexType;

// 邻接矩阵的数据类型 
typedef struct {
    int AdjMatrix[MAXVEX][MAXVEX]; //用二维数组来存放邻接矩阵 
    VextexType vex[MAXVEX];    //存放顶点信息
    int vexnum;        //顶点数 
    int arcnum;     //边数 
}MGraph;

// 主菜单
void team_class::menu() { 
    cout << "\t\t\t\t-----------------------------------------" << endl;
    cout << "\t\t\t\t|            主菜单                     " << endl;
    cout << "\t\t\t\t| 【1】增添参赛队伍的信息                 " << endl;
    cout << "\t\t\t\t| 【2】删除参赛队伍的信息               " << endl;
    cout << "\t\t\t\t| 【3】修改参赛队伍的信息               " << endl;
    cout << "\t\t\t\t| 【4】按参赛队编号进行二叉树查询         " << endl;
    cout << "\t\t\t\t| 【5】按参赛学校查询参赛团队           " << endl;
    cout << "\t\t\t\t| 【6】叫号系统                          " << endl;
    cout << "\t\t\t\t| 【7】导航系统                         " << endl;
    cout << "\t\t\t\t| 【0】退出参赛队伍基本信息管理软件     " << endl;
    cout << "\t\t\t\t----------------------------------------" << endl;
    cout << "\t\t\t\t请输入您的选择:" << endl << "\t\t\t\t";

// 增删改操作

void team_class::AddTeam() { //增加参赛队信息
    ofstream o;                   // 创建文件输出流对象,用于写入文件
    o.open("team.txt", ios::app); //  ios::app  append 往后加
    o << '\n';                    // 换行,很重要

    int Number; //添加参赛队伍编号
    cout << "请输入参赛队伍编号:" << endl;
    cin >> Number;
    o << Number;
    o << "\t#\t";

    string Production; //添加参赛作品名称
    cout << "请输入参赛作品名称:" << endl;
    cin >> Production;
    o << Production;
    o << "\t#\t";

    string Campus; //添加参赛学校
    cout << "请输入参赛学校:" << endl;
    cin >> Campus;
    o << Campus;
    o << "\t#\t";

    string Category; //添加参赛类别
    cout << "请输入参赛类别:" << endl;
    cin >> Category;
    o << Category;
    o << "\t#\t";

    string StudentName; //添加参赛学生姓名
    cout << "请输入参赛学生姓名:" << endl;
    cin >> StudentName;
    o << StudentName;
    o << "\t#\t";

    string TeacherName; //添加指导老师姓名
    cout << "请输入指导老师姓名:" << endl;
    cin >> TeacherName;
    o << TeacherName;
    o.close(); //关闭文件
    getchar();
}

void team_class::DeleteTeam(string id) {
    ifstream in("team.txt"); // 以读方式打开文件
    string data = ""; // 保存文件内容
    string line, tmp;
    while (getline(in, line)) {
        istringstream is(line);
        is >> tmp;
        if (tmp == id)
            ; // 不进行任何操作
        else
            data += (line + "\n");
    }
    in.close();
    ofstream os("team.txt"); // 以写方式打开文件,会删掉文件中的所有内容
    os << data; // 写入文件
    cout << "删除成功!" << endl;
    os.close();
}

void team_class::ModifyTeam()
{
    string num;
    cout << "请输入要编辑的参赛队编号:";
    cin >> num;
    ifstream ifs;
    ofstream oof;
    string num1, name, school, cate, person, coach;
    ifs.open("team3.txt", ios::binary | ios::out | ios::in);
    oof.open("tmp.txt", ios::binary | ios::out);//采用这两个后缀是能够在打开tmp.txt这个文件时直接清空文件中的数据而不需要进行另外操作
    while (ifs >> num1 && ifs >> name && ifs >> school && ifs >> cate && ifs >> person && ifs >> coach)
    {
        if (num1 == num)
        {
            cout << "请输入新的编号:";
            cin >> num1;
            cout << "请输入新的项目名称:";
            cin >> name;
            cout << "请输入新的参赛学校:";
            cin >> school;
            cout << "请输入新的参赛类别:";
            cin >> cate;
            cout << "请输入新的参赛者:";
            cin >> person;
            cout << "请输入新的指导老师:";
            cin >> coach;
        }
        oof << num1 <<" " << name << " " << school <<" " << cate <<" " << person <<" " << coach << endl;
    }
    ifs.close();
    oof.close();
    ofstream ofs;
    ifstream iof;
    ofs.open("team3.txt", ios::binary | ios::out);
    iof.open("tmp.txt", ios::binary | ios::out | ios::in);
    while (iof >> num1 >> name >> school >> cate >> person >> coach)
    {
        ofs << num1 << " " << name << " " << school << " " << cate << " " << person << " " << coach << endl;
    }
    ofs.close();
    iof.close();
}

string trans_str(const std::string& str) {
    size_t start = str.find_first_not_of("\t\n\r");
    size_t end = str.find_last_not_of("\t\n\r");
    if (start == std::string::npos || end == std::string::npos)
        return "";
    return str.substr(start, end - start + 1);
}

// 插入节点到二叉排序树中
void Insert(BSTNode*& root, Team x) {
    if (!root) {
        root = new BSTNode{ x, nullptr, nullptr };
        return;
    }
    if (x.teamId < root->data.teamId) { // 左小右大
        Insert(root->left, x);
    }
    else {
        Insert(root->right, x);
    }
}

// 查找节点在二叉排序树中的信息,并输出该参赛队伍的全部信息
bool SearchTree(BSTNode* root,string number) {
    if (!root)
        return false;
    if (number == root->data.teamId) {
        cout << "参赛队编号:" << root->data.teamId << endl;
        cout << "参赛作品名称:" << root->data.projectName << endl;
        cout << "参赛学校:" << root->data.school << endl;
        cout << "赛事类别:" << root->data.category << endl;
        cout << "参赛者:" << root->data.participants << endl;
        cout << "指导老师:" << root->data.coach << endl;
        return true;
    }
    else if (number < root->data.teamId)
        return SearchTree(root->left, number);
    else
        return SearchTree(root->right, number);
}

// 查找结点
int GetKLevelNodeCount(BSTNode* root, int K)
{

    if (root == NULL)
    {
        return 0;
    }

    if (K == 1)
    {    // 隐含的前提是, root != NULL
        return 1;
    }

    return GetKLevelNodeCount(root->left, K - 1)
        + GetKLevelNodeCount(root->right, K - 1);


}

//计算二叉树的高度(深度)
int Height(BSTNode* root)
{
    if (root == NULL)
        return 0;
    else
    {
        int HL = Height(root->left);
        int HR = Height(root->right);
        return HL > HR ? (HL + 1) : (HR + 1);
    }
}

int SearchTree2(BSTNode* root, string schoolname, int level) {
    if (!root)
        return -1;
    if (schoolname == root->data.school) {
        cout << "参赛队编号:" << root->data.teamId << endl;
        cout << "参赛作品名称:" << root->data.projectName << endl;
        cout << "参赛学校:" << root->data.school << endl;
        cout << "赛事类别:" << root->data.category << endl;
        cout << "参赛者:" << root->data.participants << endl;
        cout << "指导老师:" << root->data.coach << endl;
        return level;
    }
    else if (schoolname < root->data.school)
        return SearchTree2(root->left, schoolname, level + 1);
    else
        return SearchTree2(root->right, schoolname, level + 1);
}

void Teams_TXT() {
    ifstream txt("team.txt");
    if (!txt) {
        cout << "无法打开文件!!!!!!!!" << endl;
        return;
    }
    // 清空二叉树
    teams.clear();
    root = nullptr;

    string length;
    while (getline(txt, length)) {
        stringstream ss(length); // 将字符串转换为数字
        Team team1;
        string temp;
        vector<string> temps;
        while (getline(ss, temp, '#')) {
            temp = trans_str(temp);
            temps.push_back(temp);
        }
        if (temps.size() == 6) {
            team1.teamId = temps[0];
            team1.projectName = temps[1];
            team1.school = temps[2];
            team1.category = temps[3];
            team1.participants = temps[4];
            team1.coach = temps[5];
            teams.push_back(team1);
            Insert(root, team1);
        }
    }
    txt.close();
}

void erchashu_chazhao() {
    string num;
    float Asl = 0;
    cout << "请输入要查找的参赛队编号:";
    cin >> num;

    int level = Height(root); // 层数
    if (SearchTree(root, num)==false) {
        cout << "查找失败!" << endl;
    }
    else {
        cout << "平均查找长度ASL:(";
        for (int i = 1; i <=level; i++) {
            Asl += i * GetKLevelNodeCount(root, i);
            cout  << i << "*" << GetKLevelNodeCount(root, i);
            if(i!=level)
                cout << "+";
        }
        
        cout <<")"<< "/398" << "=";
        Asl /= 398;
        cout << Asl << endl;
    }
}

// 按参赛学校查找参赛队伍************************************************************************************
// 排序
bool cmp(Team n1, Team n2)
{
    return n1.teamId < n2.teamId;
}
void get_teams_by_school() {
    string school_name;
    vector<Team> a;// 学校
    cout << "请输入所要查找的学校名称:" << endl;
    cin >> school_name;

    for (const auto& team : teams) {
        if (team.school == school_name) {
            a.push_back(team);
        }
    }

    sort(a.begin(), a.end(), cmp); // 排序

    if (!a.empty()) {
        cout << "参赛学校:" << school_name << endl;
        cout << "参赛队编号\t参赛作品名称\t\t参赛类别\t\t参赛者\t\t指导教师" << endl;
        for (const auto& team : a) {
            cout << team.teamId << '\t';
            cout <<team.projectName << '\t';
            cout  << team.category << '\t';
            cout  << team.participants << '\t'<<'\t';
            cout << team.coach << endl; 
            cout<< endl;
        }
    }
    else {
        cout << "查找失败!!!!!!!!!"<<endl;
    }
}

// 叫号系统************************************************************************************************

void team_class::callFinalRooms() {
    vector<string> category_names;
    vector<string> all_category;
    string category_na;

    for (const auto& team : teams) {
        if (team.category == " Web应用与开发" || team.category == "管理信息系统" || team.category == "移动应用开发(非游戏类)"
            || team.category == "算法设计与应用" || team.category == "移动应用开发" || team.category == "信创软件应用与开发"
            || team.category == "区块链应用与开发") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end()) {
                all_category.push_back("软件应用与开发类");
            }
        }
        else if (team.category == " 计算机基础与应用类课程微课" || team.category == "中、小学数学或自然科学课程微课"
            || team.category == "汉语言文学(限于唐诗宋词)微课"
            || team.category == "虚拟实验平台") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end()) {
                all_category.push_back("微课与教学辅助类");
            }
        }
        else if (team.category == "城市管理" || team.category == "医药卫生" || team.category == "运动健身" || team.category == "数字生活"
            || team.category == "行业应用"
            || team.category == "物联网专项") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end()) {
                all_category.push_back("物联网应用类");
            }

        }
        else if (team.category == "大数据实践" || team.category == "大数据主题") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end()) {
                all_category.push_back("大数据应用类");
            }

        }
        else if (team.category == "人工智能实践赛" || team.category == "人工智能挑战赛") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end()) {
                all_category.push_back("人工智能应用类");

            }

        }
        else if (team.category == "信息图形设计" || team.category == "动态信息影像(MG 动画)" || team.category == "交互信息设计" || team.category == "数据可视化") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end()) {
                all_category.push_back("信息可视化设计类");

            }

        }
        else if (team.category == "平面设计" || team.category == "产品设计" || team.category == "环境设计") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end())
            {
                all_category.push_back("数媒静态设计类");
            }

        }
        else if (team.category == "新媒体漫画" || team.category == "动画" || team.category == "纪录片" || team.category == "微电影" || team.category == "数字短片") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end())
            {
                all_category.push_back("数媒动漫与短片类");
            }

        }
        else if (team.category == "游戏设计" || team.category == "交互媒体设计" || team.category == "虚拟现实VR与增强现实AR") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end())
            {
                all_category.push_back("数媒游戏与交互设计类");
            }

        }
        else if (team.category == "音乐") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end())
            {
                all_category.push_back("计算机音乐创作");
            }

        }
        else if (team.category == "软件应用与开发" || team.category == "微课与教学辅助" || team.category == "物联网应用" || team.category == "大数据应用"
            || team.category == "人工智能应用" || team.category == "" || team.category == "数据可视化") {
            if (find(all_category.begin(), all_category.end(), team.category) == all_category.end())
            {
                all_category.push_back("国际生“学汉语、写汉字”");
            }
        }
    }
    set<string>s(all_category.begin(), all_category.end()); // 对all_category去重
    all_category.assign(s.begin(), s.end());
    int i = 1;

    for (const auto& all_categorys : all_category) {
        Sleep(500);
        cout <<"有请下一支队伍!!!!"<< endl;
        cout << "第"<<i<<"个决赛室出场:" << endl;
        cout << "------------------------------------------------------------------------------------------------------------" << endl;
        for (const auto& team : teams) {
            if (find(category_names.begin(), category_names.end(), team.category) == category_names.end()) {
                category_names.push_back(team.category);
            }
            switch (i) {
            case 1:
                if (team.category == "大数据实践" || team.category == "大数据主题") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;                
            case 2:
                if (team.category == "人工智能实践赛" || team.category == "人工智能挑战赛") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;
            case 3:
                if (team.category == " Web应用与开发" || team.category == "管理信息系统" || team.category == "移动应用开发(非游戏类)"
                    || team.category == "算法设计与应用" || team.category == "移动应用开发" || team.category == "信创软件应用与开发"
                    || team.category == "区块链应用与开发") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;
            case 4:
                if (team.category == "新媒体漫画" || team.category == "动画" || team.category == "纪录片"
                    || team.category == "微电影" || team.category == "数字短片") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;
            case 5:
                if (team.category == "平面设计" || team.category == "产品设计" || team.category == "环境设计") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;
            case 6:
                if (team.category == "游戏设计" || team.category == "交互媒体设计" || team.category == "虚拟现实VR与增强现实AR") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;
                if (team.category == "信息图形设计" || team.category == "动态信息影像(MG 动画)" || team.category == "交互信息设计" || team.category == "数据可视化") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;
            case 7:
                if (team.category == " 计算机基础与应用类课程微课" || team.category == "中、小学数学或自然科学课程微课"
                    || team.category == "汉语言文学(限于唐诗宋词)微课"
                    || team.category == "虚拟实验平台") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;
            case 8:
                if (team.category == "城市管理" || team.category == "医药卫生" || team.category == "运动健身" || team.category == "数字生活"
                    || team.category == "行业应用"
                    || team.category == "物联网专项") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;
            case 9:
                if (team.category == "软件应用与开发" || team.category == "微课与教学辅助" || team.category == "物联网应用" || team.category == "大数据应用"
                    || team.category == "人工智能应用" || team.category == "" || team.category == "数据可视化") {
                    cout << team.teamId << '\t' << team.projectName << endl;
                }
                break;            
            default:
                cout <<"叫号结束!!!!!!!!!!!"<< endl;
                break;
            }
        }
        i++;
        cout << endl;
    }
    }

// 导航系统************************************************************************************************
void InitGraph(MGraph& G) {
    int i = 0, j = 0;
    G.vexnum = 13;
    G.arcnum = 19;
    for (int i = 0; i < 13; i++) {
        G.vex[i].Num = i + 1;//第1号景点到第13号景点
    }
    G.vex[0].name = "经管学院楼";
    G.vex[0].info = "江科大著名豪华学院楼";
    G.vex[1].name = "计算机学院楼";
    G.vex[1].info = "有很多需要用到的计算机实验室";
    G.vex[2].name = "图书馆";
    G.vex[2].info = "学习的地方";
    G.vex[3].name = "文理大楼";
    G.vex[3].info = "江科大地标建筑";
    G.vex[4].name = "东苑食堂";
    G.vex[4].info = "菜肴很多,三楼有小龙虾";
    G.vex[5].name = "明德楼";
    G.vex[5].info = "很适合自习,靠经操场,学累了可以去放松一下";
    G.vex[6].name = "西操场";
    G.vex[6].info = "锻炼身体的好地方";
    G.vex[7].name = "文体中心";
    G.vex[7].info = "有羽毛球场,篮球场,乒乓球场等等,在这里可以尽情释放自己,挥洒汗水";
    G.vex[8].name = "东操场";
    G.vex[8].info = "适合傍晚散步,看夕阳,野营等等";
    G.vex[9].name = "笃学楼";
    G.vex[9].info = "楼如其名,笃学明德,经世致用";
    G.vex[10].name = "53栋学生宿舍";
    G.vex[10].info = "学生晚上休息睡觉的地方";
    G.vex[11].name = "后勤服务楼";
    G.vex[11].info = "如果你生活有不便,请来这里";
    G.vex[12].name = "好又多超市";
    G.vex[12].info = "有很多新鲜水果和零食";

    //注意无向图是对称的
    for (int i = 0; i < 13; i++) {
        for (int j = 0; j < 13; j++) {
            G.AdjMatrix[i][j] = INFINITY;
            G.AdjMatrix[0][1] = G.AdjMatrix[1][0] = 12;
            G.AdjMatrix[0][2] = G.AdjMatrix[2][0] = 18;
            G.AdjMatrix[1][3] = G.AdjMatrix[3][1] = 4;
            G.AdjMatrix[1][9] = G.AdjMatrix[9][1] = 11;
            G.AdjMatrix[2][9] = G.AdjMatrix[9][2] = 12;
            G.AdjMatrix[2][4] = G.AdjMatrix[4][2] = 10;
            G.AdjMatrix[3][5] = G.AdjMatrix[5][3] = 6;
            G.AdjMatrix[3][9] = G.AdjMatrix[9][3] = 14;
            G.AdjMatrix[4][9] = G.AdjMatrix[9][4] = 9;
            G.AdjMatrix[4][8] = G.AdjMatrix[8][4] = 9;
            G.AdjMatrix[5][6] = G.AdjMatrix[6][5] = 3;
            G.AdjMatrix[5][10] = G.AdjMatrix[10][5] = 12;
            G.AdjMatrix[6][10] = G.AdjMatrix[10][6] = 13;
            G.AdjMatrix[6][7] = G.AdjMatrix[7][6] = 6;
            G.AdjMatrix[6][12] = G.AdjMatrix[12][6] = 7;
            G.AdjMatrix[7][9] = G.AdjMatrix[9][7] = 13;
            G.AdjMatrix[7][12] = G.AdjMatrix[12][7] = 22;
            G.AdjMatrix[8][9] = G.AdjMatrix[9][8] = 8;
            G.AdjMatrix[10][11] = G.AdjMatrix[11][10] = 13;
            G.AdjMatrix[10][12] = G.AdjMatrix[12][10] = 6;
            G.AdjMatrix[11][12] = G.AdjMatrix[12][11] = 20;
        }
    }
    for (int i = 0; i < 13; i++) {
        bianhao[i] = i + 1;
    }
}

void MapDisplay() {
    system("江科大地图.jpg");
}

//起始页 
void start() {
    system("cls");//清屏
    int i;
    for (i = 0; i < 5; i++)
        cout << endl;
    cout << "         *********************************************" << endl;
    cout << "         **                                         **" << endl;
    cout << "         **      欢迎使用江苏科技大学导游系统       **" << endl;
    cout << "         **                                         **" << endl;
    cout << "         *********************************************" << endl;
    for (i = 0; i < 5; i++)
        cout << endl;
    cout << "按回车键继续......";
    getchar();
    system("pause");
}
void Menu() {
    start();
    system("cls");//清屏
    cout << endl;
    cout << "|----------------------------欢迎来到江苏科技大学-------------------------------\n";
    cout << "|---------------------------校园导游系统功能菜单图------------------------------\n";
    cout << "|*******************************************************************************\n";
    cout << "|      1.显示江苏科技大学景点平面图\t\t2.校园景点一览                     \n";
    cout << "|      3.显示任意两个景点间的最短路径\t\t0.退出                    \n";
    cout << "|*******************************************************************************\n";
    cout << endl;
}

void PrintAllInfo(MGraph& G) {
    cout.setf(ios::left, ios::adjustfield);
    cout << setw(10) << "编号" << setw(15) << "名称" << "简介" << endl;
    for (int i = 0; i < G.vexnum; i++) {
        cout << setw(10) << G.vex[i].Num << setw(15) << G.vex[i].name << G.vex[i].info << endl;
    }
}

/*
Floyd算法(弗洛伊德算法)求最短路径:
两个准备的二维数组:
int PathMatirx[MAXVEX][MAXVEX];//记录对应点的最小路径的前驱点,例如p(1,3) = 2 说明顶点1到顶点3的最小路径要经过2
int ShortPath[MAXVEX][MAXVEX];//记录顶点间的最小路径值
*/
void Floyd(MGraph& G) {
    // 对Floyd的两个数组进行初始化
    for (int i = 0; i < G.vexnum; i++) {
        for (int j = 0; j < G.vexnum; j++) {
            PathMatirx[i][j] = j;
            ShortPath[i][j] = G.AdjMatrix[i][j];
        }
    }
    for (int k = 0; k < G.vexnum; k++) {
        for (int v = 0; v < G.vexnum; v++) {
            for (int w = 0; w < G.vexnum; w++) {
                if (ShortPath[v][w] > ShortPath[v][k] + ShortPath[k][w]) {
                    //更新最短路径
                    ShortPath[v][w] = ShortPath[v][k] + ShortPath[k][w];
                    //更新路径中介节点
                    PathMatirx[v][w] = PathMatirx[v][k];
                }
            }
        }
    }
}

void ShortestPathOfAnyTwo(MGraph& G) {
    int start, end, k;
    bool flag1 = false;
    bool flag2 = false;
    cout << "请您输入要查询最短路径的两个不同的景点的编号!" << endl;
    cout << "请您输入起点景点的编号:";
    cin >> start;
    cout << "请您输入终点景点的编号:";
    cin >> end;
    if (start == end) {
        cout << "对不起!您所输入的两个景点的编号一样,请重新输入" << endl;
    }
    for (int i = 0; i < G.vexnum; i++) {
        if (start == G.vex[i].Num) {
            flag1 = true;
        }
        if (end == G.vex[i].Num) {
            flag2 = true;
        }
    }
    if (!(flag1 == true && flag2 == true)) {
        cout << "您输入的两个景点中有不存在的情况,请重新输入" << endl;
    }
    cout << "从景点 " << G.vex[start - 1].name << " 到景点 " << G.vex[end - 1].name << "的最短路径长度为:" << ShortPath[start][end] << endl;
    cout << "具体路径为:" << endl;
    k = PathMatirx[start][end];
    cout << start << "--->";
    while (k != end) {
        cout << k << "--->";
        k = PathMatirx[k][end];
    }
    cout << end << endl;
}

void navigation() {
    cout << "欢迎来到江苏科技大学长山校区" << endl;
    MGraph G;
    InitGraph(G);//初始化
    bool flag = true;
    Menu();//用户看到菜单
    while (flag) {
        cout << "请输入您的选择:" << endl;
        int choice;
        cin >> choice;
        cout << endl;
        switch (choice) {
        case 1:
            MapDisplay();
            break;
        case 2:
            PrintAllInfo(G);
            break;
        case 3:
            Floyd(G);
            ShortestPathOfAnyTwo(G);
            break;
        case 0:
            cout << "感谢您的使用,再见" << endl;
            flag = false;
            break;
        default:
            cout << "您的输入有误,请重新输入" << endl;
        };
    }
    system("pause");
}

int main() {
    team_class team1;
    Teams_TXT();

    int i;
    string id;
    bool quit = false;
    while (!quit) {
        team1.menu();
        cin >> i;
        switch (i) {
            case 1:
                team1.AddTeam();
                break;
            case 2:
                cout << "请输入要删除的编号:" << endl;
                cin >> id;
                team1.DeleteTeam(id);
                break;
            case 3:
                team1.ModifyTeam();
                break;
            case 4:
                erchashu_chazhao();
                break;
            case 5: 
                get_teams_by_school();
                break;
            case 6:
                team1.callFinalRooms();    
                break;
            case 7:
                navigation();
                break;
            case 0:
                quit = true;
                cout << "成功退出数据统计.cpp!!!!!!!!" << endl;
                break;
            default:
                cout << "您输入的指令有误!!!!!!!!" << endl;
                break;
        }
    }
    return 0;
}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值