C++ 数据管理系统示例:学生信息管理
#include
\nstruct Student {\n string name;\n int age;\n string major;\n};
\nvector
\nvoid addStudent() {\n Student student;\n cout << 'Enter student's name: ';\n cin >> student.name;\n cout << 'Enter student's age: ';\n cin >> student.age;\n cout << 'Enter student's major: ';\n cin >> student.major;\n studentList.push_back(student);\n cout << 'Student added successfully!' << endl;\n}\n\nvoid displayStudents() {\n cout << 'List of students:' << endl;\n for (int i = 0; i < studentList.size(); i++) {\n cout << 'Name: ' << studentList[i].name << endl;\n cout << 'Age: ' << studentList[i].age << endl;\n cout << 'Major: ' << studentList[i].major << endl;\n cout << endl;\n }\n}\n\nint main() {\n int choice;\n while (true) {\n cout << '1. Add student' << endl;\n cout << '2. Display students' << endl;\n cout << '3. Quit' << endl;\n cout << 'Enter your choice: ';\n cin >> choice;\n\n switch (choice) {\n case 1:\n addStudent();\n break;\n case 2:\n displayStudents();\n break;\n case 3:\n return 0;\n default:\n cout << 'Invalid choice. Please try again.' << endl;\n break;\n }\n }\n}\n\n这个简单的数据管理系统允许用户添加学生的姓名、年龄和专业,并显示已添加学生的列表。\n\n您可以根据自己的需求修改和扩展这个代码。
原文地址: https://www.cveoy.top/t/topic/pRLR 著作权归作者所有。请勿转载和采集!