c++学生通讯录管理系统
时间: 2023-12-29 09:05:36 浏览: 139
以下是一个简单的C++学生通讯录管理系统的示例:
```cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Student {
string name;
int age;
string phone;
};
void addStudent(vector<Student>& students) {
Student student;
cout << "请输入学生姓名:";
cin >> student.name;
cout << "请输入学生年龄:";
cin >> student.age;
cout << "请输入学生电话:";
cin >> student.phone;
students.push_back(student);
cout << "添加成功!" << endl;
}
void displayStudents(const vector<Student>& students) {
if (students.empty()) {
cout << "通讯录为空!" << endl;
return;
}
cout << "学生列表:" << endl;
for (const auto& student : students) {
cout << "姓名:" << student.name << ",年龄:" << student.age << ",电话:" << student.phone << endl;
}
}
int main() {
vector<Student> students;
int choice;
while (true) {
cout << "请选择操作:" << endl;
cout << "1. 添加学生" << endl;
cout << "2. 显示学生列表" << endl;
cout << "0. 退出" << endl;
cin >> choice;
switch (choice) {
case 1:
addStudent(students);
break;
case 2:
displayStudents(students);
break;
case 0:
cout << "程序已退出!" << endl;
return 0;
default:
cout << "无效的选择!" << endl;
break;
}
}
}
```
阅读全文