200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > C++背景实现 学生管理系统(添加 显示 删除 修改)

C++背景实现 学生管理系统(添加 显示 删除 修改)

时间:2022-11-27 12:44:40

相关推荐

C++背景实现 学生管理系统(添加 显示 删除 修改)

#include<iostream>using namespace std;#include<string>#define MAX 1000//学生信息的结构体struct Student{//学号string S_sno;//姓名string S_name;//性别int S_sex;//年龄int S_age;//家庭住址string S_address;//联系方式string S_phone;};//学生管理库的结构体struct StudentNum{Student arr[MAX];int size;};//00 主界面void MainMap(){cout << "**************************" << endl;cout << "*****01、增加学生信息*****" << endl;cout << "*****02、删除学生信息*****" << endl;cout << "*****03、修改学生信息*****" << endl;cout << "*****04、显示学生信息*****" << endl;cout << "*****05、查找学生信息*****" << endl;cout << "*****00、退出学生系统*****" << endl;cout << "**************************" << endl;}//01 增加学生信息void AddStudent(StudentNum *stu){if (stu->size == MAX){cout << "学生信息库已满,无法添加!" << endl;}else{cout << "请输入学生学号:" << endl;cin >> stu->arr[stu->size].S_sno;cout << "请输入学生姓名:" << endl;cin >> stu->arr[stu->size].S_name;cout << "请输入学生性别:" << endl;cout << "1---男" << endl;cout << "2---女" << endl;cin >> stu->arr[stu->size].S_sex;while (1){if (stu->arr[stu->size].S_sex == 1 || stu->arr[stu->size].S_sex == 2)break;else{cout << "输入错误,请重新输入!" << endl;cin >> stu->arr[stu->size].S_sex;}}cout << "请输入学生年龄:" << endl;cin >> stu->arr[stu->size].S_age;cout << "请输入学生家庭住址:" << endl;cin >> stu->arr[stu->size].S_address;cout << "请输入学生联系方式:" << endl;cin >> stu->arr[stu->size].S_phone;}stu->size++;cout << "输入成功!" << endl;system("pause");system("cls");}//02 删除学生信息 按学号删除学生void DeleteStudent(StudentNum*stu){string sno;cout << "请输入删除学生的学号:" << endl;cin >> sno;int temp = 0;if (stu->size == 0)//判断stu里面有无数据cout << "删除失败!" << endl;for (int i = 0; i < stu->size; i++){if (stu->arr[i].S_sno == sno){temp = i;}elsecout << "查无此人!" << endl;}if (temp != stu->size - 1)//判断temp是不是最后一个值{for (int i = temp; temp < stu->size; i++){stu->arr[i] = stu->arr[i + 1];}}stu->size--;system("pause");system("cls");}//03 修改学生信息 按学号修改学生void AlterStudent(StudentNum* stu){string sno;cin >> sno;int temp = 0;cout << "请输入要修改的学生学号:" << endl;for (int i = 0; i < stu->size; i++){if (stu->arr[i].S_sno == sno){temp = i;}elsecout << "查无此人!" << endl;}cout << "请输入要修改的信息:" << endl;cout << "1、学号" << endl;cout << "2、姓名" << endl;cout << "3、性别" << endl;cout << "4、年龄" << endl;cout << "5、家庭住址" << endl;cout<<"6、联系方式" << endl;int n;//输入的选项cin >> n;switch (n){case 1:cin >> stu->arr[temp].S_sno;break;case 2:cin >> stu->arr[temp].S_name;break;case 3:cin >> stu->arr[temp].S_age;break;case 4:cin >> stu->arr[temp].S_age;break;case 5:cin >> stu->arr[temp].S_address;break;case 6:cin >> stu->arr[temp].S_phone;break;}}//04 显示学生信息 void ShowStudent(StudentNum* stu){if (stu->size == 0)cout << "无学生信息!" << endl;else{for (int i = 0; i < stu->size; i++){cout << "学号:" << stu->arr[i].S_sno << "\t"<< "姓名:" << stu->arr[i].S_name << "\t";if (stu->arr[i].S_sex == 1)cout << "性别:男" << "\t";elsecout << "性别:女" << "\t";cout << "性别:" << stu->arr[i].S_sex << "\t"<< "年龄:" << stu->arr[i].S_age << "\t"<< "家庭住址:" << stu->arr[i].S_address << "\t"<< "联系方式:" << stu->arr[i].S_phone << endl;}}system("pause");system("cls");}//05 查找学生信息 按学号void FindStudent(StudentNum* stu){cout << "请输入学生学号:" << endl;string sno;for (int i = 0; i < stu->size; i++){if (stu->arr[i].S_sno == sno){cout << "学号:" << stu->arr[i].S_sno << "\t"<< "姓名:" << stu->arr[i].S_name << "\t";if (stu->arr[i].S_sex == 1)cout << "性别:男" << "\t";elsecout << "性别:女" << "\t";cout << "性别:" << stu->arr[i].S_sex << "\t"<< "年龄:" << stu->arr[i].S_age << "\t"<< "家庭住址:" << stu->arr[i].S_address << "\t"<< "联系方式:" << stu->arr[i].S_phone << endl;}elsecout << "查无此人!" << endl;}system("pause");system("cls");}int main(){StudentNum a;a.size = 0;//初始化个数while (1){MainMap();int n;//选项cin >> n;switch (n){case 01:AddStudent(&a);break;case 02:DeleteStudent(&a);break;case 03:AlterStudent(&a);break;case 04:ShowStudent(&a);break;case 05:FindStudent(&a);break;case 00:cout << "欢迎再次使用!" << endl;return 0;break;}}system("pause");return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。