#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;
}
else
cout << "查无此人!" << 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;
}
else
cout << "查无此人!" << 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";
else
cout << "性别:女" << "\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";
else
cout << "性别:女" << "\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;
}
else
cout << "查无此人!" << 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;
}
|