C++实现顺序存储结构的科技竞赛志愿者名册管理程序,功能丰富超实用!
```cpp #include <iostream> #include <string> using namespace std; // 定义志愿者结构体 struct Volunteer { string id; string name; string phone; int hours; }; // 定义志愿者名册管理类 class Registry { private: Volunteer volunteers[100]; int numVolunteers; public: Registry() { numVolunteers = 0; } void addVolunteer() { int n; cout << "请输入要添加的志愿者人数:"; cin >> n; for (int i = 0; i < n; i++) { cout << "请输入第" << i + 1 << "个志愿者的编号:"; cin >> volunteers[numVolunteers].id; cout << "请输入第" << i + 1 << "个志愿者的姓名:"; cin >> volunteers[numVolunteers].name; cout << "请输入第" << i + 1 << "个志愿者的电话号码:"; cin >> volunteers[numVolunteers].phone; volunteers[numVolunteers].hours = 0; numVolunteers++; } } void insertVolunteer(int pos) { if (pos < 0 || pos > numVolunteers) { cout << "插入位置无效!" << endl; return; } cout << "请输入要插入的志愿者的编号:"; cin >> volunteers[numVolunteers].id; cout << "请输入要插入的志愿者的姓名:"; cin >> volunteers[numVolunteers].name; cout << "请输入要插入的志愿者的电话号码:"; cin >> volunteers[numVolunteers].phone; volunteers[numVolunteers].hours = 0; numVolunteers++; } void findVolunteer(string key) { for (int i = 0; i < numVolunteers; i++) { if (volunteers[i].id == key || volunteers[i].name == key) { cout << "编号:" << volunteers[i].id << " 姓名:" << volunteers[i].name << " 电话号码:" << volunteers[i].phone << " 志愿时长:" << volunteers[i].hours << endl; return; } } cout << "未找到匹配志愿者!" << endl; } void deleteVolunteer(string key) { for (int i = 0; i < numVolunteers; i++) { if (volunteers[i].id == key) { for (int j = i; j < numVolunteers - 1; j++) { volunteers[j] = volunteers[j + 1]; } numVolunteers--; cout << "删除成功!" << endl; return; } } cout << "未找到匹配志愿者!" << endl; } void printVolunteers() { for (int i = 0; i < numVolunteers; i++) { cout << "编号:" << volunteers[i].id << " 姓名:" << volunteers[i].name << " 电话号码:" << volunteers[i].phone << " 志愿时长:" << volunteers[i].hours << endl; } cout << "总人数:" << numVolunteers << endl; } void sortVolunteers() { for (int i = 0; i < numVolunteers - 1; i++) { for (int j = 0; j < numVolunteers - i - 1; j++) { if (volunteers[j].hours > volunteers[j + 1].hours) { Volunteer temp = volunteers[j]; volunteers[j] = volunteers[j + 1]; volunteers[j + 1] = temp; } } } } }; int main() { Registry registry; // 初始化部分数据 Volunteer v1 = {"001", "Alice", "*0", 10}; Volunteer v2 = {"002", "Bob", "9876543210", 5}; Volunteer v3 = {"003", "Cathy", "1357924680", 8}; registry.addVolunteer(v1); registry.addVolunteer(v2); registry.addVolunteer(v3); int choice; string key; int pos; do { cout << "==========志愿者名册管理系统==========" << endl; cout << "1. 添加志愿者信息" << endl; cout << "2. 在指定位置插入志愿者信息" << endl; cout << "3. 修改志愿者信息" << endl; cout << "4. 根据编号或姓名查找志愿者信息" << endl; cout << "5. 删除特定编号的志愿者" << endl; cout << "6. 输出所有志愿者信息" << endl; cout << "7. 根据志愿服务时长排序" << endl; cout << "8. 退出" << endl; cout << "请选择功能:"; cin >> choice; switch (choice) { case 1: registry.addVolunteer(); break; case 2: cout << "请输入插入位置:"; cin >> pos; registry.insertVolunteer(pos); break; case 3: cout << "请输入要查找的志愿者的编号或姓名:"; cin >> key; registry.findVolunteer(key); break; case 4: cout << "请输入要删除的志愿者的编号:"; cin >> key; registry.deleteVolunteer(key); break; case 5: registry.printVolunteers(); break; case 6: registry.sortVolunteers(); cout << "排序成功!" << endl; break; case 7: break; case 8: cout << "感谢使用!" << endl; break; default: cout << "请输入有效的菜单选项!" << endl; } } while (choice != 8); return 0; } ``` ######[AI写代码神器 | 3423点数解答 | 2024-12-16 11:12:08]
- Python 实现简易密码设置系统:多种功能交互与安全要点揭秘(字节豆包 | 286点数解答 | 2025-03-28 10:43:21)386
- C语言实现多功能密码设置系统:含代码及安全注意要点(字节豆包 | 414点数解答 | 2025-03-28 10:43:55)372
- C 语言实现:超简单密码设置系统,含代码与注意要点!(字节豆包 | 519点数解答 | 2025-03-28 12:42:02)410
- C语言实现密码管理系统:含功能代码与安全注意事项(字节豆包 | 409点数解答 | 2025-04-05 18:09:56)356
- C语言实现多功能密码系统:初始化、确认、设置、显示、重置与退出(字节豆包 | 454点数解答 | 2025-04-05 18:48:42)358
- C语言实现密码管理系统:含初始化、确认、设置、显示、重置及退出功能(字节豆包 | 413点数解答 | 2025-04-06 15:37:16)304
- C 语言实现密码管理系统:含初始化、确认、设置、显示、重置及退出功能(字节豆包 | 403点数解答 | 2025-04-06 15:37:54)315
- Java实现有序集合合并与交集算法(顺序表+单链表)(百度文心 | 1247点数解答 | 2026-03-25 10:35:22)28
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)380
- 数据结构:揭示实体固有关系,助力信息管理与开发(GPT | 178点数解答 | 2024-10-20 14:06:34)209
- 重新定义字母大小关系:让 “L 队” 字典序小于 “某 E” 的代码实现与分析(字节豆包 | 595点数解答 | 2025-12-03 19:44:59)83
- 深入解析格雷码生成算法:递归求解与代码实现(DeepSeek | 443点数解答 | 2026-01-05 12:21:49)73