校友信息管理系统c++
时间: 2023-10-18 19:14:12 浏览: 150
C++课程设计校友管理系统源代码
5星 · 资源好评率100%
校友信息管理系统是一个比较常见的管理系统,用 C++ 实现也比较方便。下面是一个简单的校友信息管理系统的实现,包括添加、删除、查询和修改校友信息。
```c++
#include <iostream>
#include <string>
using namespace std;
const int MAXSIZE = 100; // 最大记录数
// 校友信息结构体
struct Alumni {
string name; // 姓名
string gender; // 性别
int age; // 年龄
string major; // 专业
string company; // 工作单位
};
// 校友信息管理类
class AlumniManagement {
public:
// 添加一条记录
void addRecord() {
if (count >= MAXSIZE) {
cout << "记录已满,无法添加!" << endl;
return;
}
Alumni alumni;
cout << "请输入姓名:";
cin >> alumni.name;
cout << "请输入性别:";
cin >> alumni.gender;
cout << "请输入年龄:";
cin >> alumni.age;
cout << "请输入专业:";
cin >> alumni.major;
cout << "请输入工作单位:";
cin >> alumni.company;
records[count++] = alumni;
cout << "添加成功!" << endl;
}
// 删除一条记录
void deleteRecord() {
if (count == 0) {
cout << "记录为空,无法删除!" << endl;
return;
}
string name;
cout << "请输入要删除的校友姓名:";
cin >> name;
for (int i = 0; i < count; i++) {
if (records[i].name == name) {
for (int j = i; j < count - 1; j++) {
records[j] = records[j+1];
}
count--;
cout << "删除成功!" << endl;
return;
}
}
cout << "未找到该校友记录!" << endl;
}
// 查询一条记录
void queryRecord() {
if (count == 0) {
cout << "记录为空,无法查询!" << endl;
return;
}
string name;
cout << "请输入要查询的校友姓名:";
cin >> name;
for (int i = 0; i < count; i++) {
if (records[i].name == name) {
cout << "姓名:" << records[i].name << endl;
cout << "性别:" << records[i].gender << endl;
cout << "年龄:" << records[i].age << endl;
cout << "专业:" << records[i].major << endl;
cout << "工作单位:" << records[i].company << endl;
return;
}
}
cout << "未找到该校友记录!" << endl;
}
// 修改一条记录
void modifyRecord() {
if (count == 0) {
cout << "记录为空,无法修改!" << endl;
return;
}
string name;
cout << "请输入要修改的校友姓名:";
cin >> name;
for (int i = 0; i < count; i++) {
if (records[i].name == name) {
cout << "请输入新的信息(不输入则不修改):" << endl;
cout << "姓名:";
cin >> records[i].name;
cout << "性别:";
cin >> records[i].gender;
cout << "年龄:";
cin >> records[i].age;
cout << "专业:";
cin >> records[i].major;
cout << "工作单位:";
cin >> records[i].company;
cout << "修改成功!" << endl;
return;
}
}
cout << "未找到该校友记录!" << endl;
}
private:
Alumni records[MAXSIZE]; // 校友信息记录
int count = 0; // 当前记录数
};
int main() {
AlumniManagement management;
int choice;
while (true) {
cout << "1.添加记录" << endl;
cout << "2.删除记录" << endl;
cout << "3.查询记录" << endl;
cout << "4.修改记录" << endl;
cout << "5.退出程序" << endl;
cout << "请选择操作:";
cin >> choice;
switch (choice) {
case 1:
management.addRecord();
break;
case 2:
management.deleteRecord();
break;
case 3:
management.queryRecord();
break;
case 4:
management.modifyRecord();
break;
case 5:
return 0;
default:
cout << "无效操作,请重新选择!" << endl;
}
cout << endl;
}
}
```
以上是一个简单的校友信息管理系统的实现,你可以根据自己的需求进行修改和扩展。
阅读全文