用C++编程实现一个系统,可以添加信息,包括姓名,学号,年级,学院,联系电话
时间: 2024-06-14 10:06:17 浏览: 7
以下是用C++编程实现一个系统,可以添加信息,包括姓名,学号,年级,学院,联系电话的示例代码:
```cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Student {
string name;
string studentID;
string grade;
string college;
string phoneNumber;
};
int main() {
vector<Student> students;
while (true) {
cout << "请选择操作:" << endl;
cout << "1. 添加学生信息" << endl;
cout << "2. 显示所有学生信息" << endl;
cout << "3. 退出程序" << endl;
int choice;
cin >> choice;
if (choice == 1) {
Student student;
cout << "请输入学生姓名:";
cin >> student.name;
cout << "请输入学生学号:";
cin >> student.studentID;
cout << "请输入学生年级:";
cin >> student.grade;
cout << "请输入学生学院:";
cin >> student.college;
cout << "请输入学生联系电话:";
cin >> student.phoneNumber;
students.push_back(student);
cout << "学生信息添加成功!" << endl;
} else if (choice == 2) {
if (students.empty()) {
cout << "暂无学生信息!" << endl;
} else {
cout << "所有学生信息如下:" << endl;
for (const auto& student : students) {
cout << "姓名:" << student.name << endl;
cout << "学号:" << student.studentID << endl;
cout << "年级:" << student.grade << endl;
cout << "学院:" << student.college << endl;
cout << "联系电话:" << student.phoneNumber << endl;
cout << "--" << endl;
}
}
} else if (choice == 3) {
break;
} else {
cout << "无效的选择,请重新输入!" << endl;
}
}
return 0;
}
```
相关推荐
![text/x-c++](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)