C++实现顺序存储结构的科技竞赛志愿者名册管理程序,功能强大超实用!
```cpp #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; struct Volunteer { string id; string name; string phone; int duration; }; vector<Volunteer> roster; void addVolunteer() { int n; cout << "Enter the number of volunteers to add: "; cin >> n; for (int i = 0; i < n; i++) { Volunteer v; cout << "Enter volunteer's ID: "; cin >> v.id; cout << "Enter volunteer's name: "; cin >> v.name; cout << "Enter volunteer's phone number: "; cin >> v.phone; v.duration = 0; roster.push_back(v); } cout << "Volunteers added successfully." << endl; } void insertVolunteer() { int pos; Volunteer v; cout << "Enter the position to insert the volunteer: "; cin >> pos; cout << "Enter volunteer's ID: "; cin >> v.id; cout << "Enter volunteer's name: "; cin >> v.name; cout << "Enter volunteer's phone number: "; cin >> v.phone; v.duration = 0; roster.insert(roster.begin() + pos, v); cout << "Volunteer inserted successfully." << endl; } void modifyVolunteer() { string searchKey; cout << "Enter volunteer's ID or name to search: "; cin >> searchKey; for (Volunteer& v : roster) { if (v.id == searchKey || v.name == searchKey) { cout << "Enter new ID: "; cin >> v.id; cout << "Enter new name: "; cin >> v.name; cout << "Enter new phone number: "; cin >> v.phone; cout << "Volunteer information modified successfully." << endl; return; } } cout << "Volunteer not found!" << endl; } void deleteVolunteer() { string searchKey; cout << "Enter volunteer's ID to delete: "; cin >> searchKey; for (auto it = roster.begin(); it != roster.end(); ++it) { if (it->id == searchKey) { it = roster.erase(it); cout << "Volunteer deleted successfully." << endl; return; } } cout << "Volunteer not found!" << endl; } void printRoster() { for (const Volunteer& v : roster) { cout << "ID: " << v.id << " | Name: " << v.name << " | Phone: " << v.phone << " | Duration: " << v.duration << endl; } cout << "Total number of volunteers: " << roster.size() << endl; } void sortByDuration() { sort(roster.begin(), roster.end(), [](const Volunteer &a, const Volunteer &b) { return a.duration > b.duration; }); cout << "Volunteers sorted by duration:" << endl; printRoster(); } int main() { // Initialize some volunteers Volunteer v1 = {"001", "Alice", "123-456-7890", 10}; Volunteer v2 = {"002", "Bob", "321-654-0987", 5}; Volunteer v3 = {"003", "Charlie", "456-789-0123", 8}; roster = {v1, v2, v3}; int choice; do { cout << "\n1. Add Volunteer\n2. Insert Volunteer\n3. Modify Volunteer\n4. Delete Volunteer\n5. Print Roster\n6. Sort by Duration\n7. Exit\n"; cout << "Enter your choice: "; cin >> choice; switch (choice) { case 1: addVolunteer(); break; case 2: insertVolunteer(); break; case 3: modifyVolunteer(); break; case 4: deleteVolunteer(); break; case 5: printRoster(); break; case 6: sortByDuration(); break; case 7: cout << "Exiting program..." << endl; break; default: cout << "Invalid choice. Please try again." << endl; } } while (choice != 7); return 0; } ``` ######[AI写代码神器 | 2584点数解答 | 2024-12-16 11:13:13]
- Java实现有序集合合并与交集算法(顺序表+单链表)(百度文心 | 1247点数解答 | 2026-03-25 10:35:22)28
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)380
- 基于SpringBoot + Vue的个人健康管理系统:全方位可行性分析与改进建议(字节豆包 | 726点数解答 | 2024-12-25 01:40:15)215
- 数据结构:揭示实体固有关系,助力信息管理与开发(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
- Java 实现将 List<Map<String, Integer>> 中 Map 的 Key 重新组装到新 List:代码解析与注意事项(字节豆包 | 587点数解答 | 2026-01-12 12:52:02)50
- 51 单片机:定时器 0 实现 8 个 LED 循环点亮,附代码及优化建议(字节豆包 | 1193点数解答 | 2024-12-27 15:10:29)350
- 旅游特效网页设计:要求、示例与优化建议大揭秘(字节豆包 | 990点数解答 | 2024-12-23 08:13:09)394
- 旅游主题特效网页:设计指南、代码示例与改进建议(字节豆包 | 966点数解答 | 2024-12-26 15:25:16)202
- 70分特效网页制作全攻略:从主题设计到特效实现与代码优化(阿里通义 | 342点数解答 | 2024-12-26 15:33:00)238
- 手把手教你打造主题突出的特效网页:从框架搭建到优化建议(字节豆包 | 898点数解答 | 2024-12-27 09:47:42)200