模块一:
系统使用TeamInfo类来存储每个队伍的信息。每个TeamInfo实例都包含以下字段:
• teamNumber:队伍编号,唯一标识。
• projectName:作品名称。
• category:赛事类别。
• teamMemberName:队员姓名。
• coachName:指导老师姓名。
• schoolName:学校名称。
#include
#include
#include
#include
class TeamInfo {
public:
std::string teamNumber;
std::string projectName;
std::string category;
std::string teamMemberName;
std::string coachName;
std::string schoolName;
TeamInfo(std::string num, std::string proj, std::string cat, std::string member, std::string coach, std::string school)
: teamNumber(num), projectName(proj), category(cat), teamMemberName(member), coachName(coach), schoolName(school) {}
};
std::vector teamDatabase;
void AddTeamInfo() {
std::string number, project, category, member, coach, school;
std::cout << "输入队伍编号: ";
std::getline(std::cin, number);
std::cout << "输入作品名称: ";
std::getline(std::cin, project);
std::cout << "输入赛事类别: ";
std::getline(std::cin, category);
std::cout << "输入队员姓名: ";
std::getline(std::cin, member);
std::cout << "输入指导老师姓名: ";
std::getline(std::cin, coach);
std::cout << "输入学校名称: ";
std::getline(std::cin, school);
teamDatabase.emplace_back(number, project, category, member, coach, school);
std::cout << "队伍信息已添加。\n";
}
void RemoveTeamInfo() {
std::string number;
std::cout << "输入要删除的队伍编号: ";
std::getline(std::cin, number);
auto it = std::remove_if(teamDatabase.begin(), teamDatabase.end(), [&](const TeamInfo& team) {
return team.teamNumber == number;
});
if (it != teamDatabase.end()) {
teamDatabase.erase(it, teamDatabase.end());
std::cout << "队伍信息已删除。\n";
}
else {
std::cout << "未找到队伍。\n";
}
}
void UpdateTeamInfo() {
std::string number;
std::cout << "输入要修改的队伍编号: ";
std::getline(std::cin, number);
for (auto& team : teamDatabase) {
if (team.teamNumber == number) {
std::cout << "输入新的作品名称: ";
std::getline(std::cin, team.projectName);
std::cout << "输入新的赛事类别: ";
std::getline(std::cin, team.category);
std::cout << "输入新的队员姓名: ";
std::getline(std::cin, team.teamMemberName);
std::cout << "输入新的指导老师姓名: ";
std::getline(std::cin, team.coachName);
std::cout << "输入新的学校名称: ";
std::getline(std::cin, team.schoolName);
std::cout << "队伍信息已更新。\n";
return;
}
}
std::cout << "未找到队伍。\n";
}
void DisplayTeamInfo() {
for (const auto& team : teamDatabase) {
std::cout << "队伍编号: " << team.teamNumber
<< ", 作品名称: " << team.projectName
<< ", 赛事类别: " << team.category
<< ", 队员姓名: " << team.teamMemberName
<< ", 指导老师姓名: " << team.coachName
<< ", 学校名称: " << team.schoolName << "\n";
}
}
int main() {
std::string command;
while (true) {
std::cout << "请输入命令 (add, remove, update, display, exit): ";
std::getline(std::cin, command);
if (command == "add") {
AddTeamInfo();
}
else if (command == "remove") {
RemoveTeamInfo();
}
else if (command == "update") {
UpdateTeamInfo();
}
else if (command == "display") {
DisplayTeamInfo();
}
else if (command == "exit") {
break;
}
else {
std::cout << "未知命令,请重新输入。\n";
}
// 清除缓冲区,为下一次输入准备
std::cin.clear();
std::cin.ignore(std::numeric_limits::max(), '\n');
}
return 0;
}
系统提供以下功能:
• 添加队伍信息(add):允许用户输入新队伍的所有信息,并将其添加到系统中。
• 删除队伍信息(remove):允许用户通过队伍编号删除现有队伍的信息。
• 更新队伍信息(update):允许用户通过队伍编号更新队伍的详细信息。
• 显示所有队伍信息(display):显示系统中存储的所有队伍信息。
• 退出程序(exit):允许用户退出程序。
模块二:
文件操作模块
void insertinformation()
{
ifstream ifs;
string buf;
Team a;
teamsall.clear();
root = nullptr;
ifs.open("F:\\team.txt", ios::in);
if (!ifs.is_open())
{
cout << "文件打开失败" << endl;
}
else
{
while (std::getline(ifs, buf))
{
buf.erase(remove(buf.begin(), buf.end(), '\t'), buf.end());
string bufs;
vector<string> items;
stringstream ss(buf);
while (getline(ss, bufs, '#'))
{
items.push_back(bufs);
}
if (items.size() == 6)
{
a.insertTeamID(items[0]);
a.insertworkname(items[1]);
a.insertschool(items[2]);
a.inserteventCate(items[3]);
a.insertparticipants(items[4]);
a.insertteachers(items[5]);
teamsall.push_back(a);
insertTreeNode(root, a);
}
}
}
ifs.close();
}
打开文件后,使用getline函数,逐行读取,然后在使用while循环,如果遇到#就停止,然后将数据压入到vector类型的items当中,然后如果items当中的函数如果有六个元素,那么元素就一个一个插入到a当中,然后将a插入到teamsall和二叉排序树当中
模块三:
导航系统
class Graph {
protected List<String> vertex;//存放顶点
protected int[][] edges;//存放边
protected boolean[] isVisited;//是否被访问
protected int numOfEdges;
int [][] accessible;
public Graph(int n) {
this.vertex = new ArrayList<>(n);
this.edges = new int[n][n];
this.isVisited = new boolean[n];
this.accessible=new int[10][10];
}
// 1. 获取节点个数
protected int getNumOfVertex();
// 2. 打印邻接矩阵
protected void printGraph();
// 3. 获取边的数目
protected int getNumOfEdges();
// 4. 获取某条边的权值
protected int getWeightOfEdges(int v1, int v2);
// 5. 添加节点
protected void addVertex(String v) ;
// 6. 添加边(双向)
protected void addEdge(int v1, int v2, int weight);
// 7.获取顶点索引对应的值
protected String getValueByIndex(int i);
}
现在打算的是采用Floyd算法,它的核心思想是动态规划,通过不断更新节点之间的距离,最终得到最短路径