先这样,之后改
#include<iostream>
#include<string>
#define MAX 1000
using namespace std;
struct Student
{
string name;
int sex;
int id;
string phone;
string addr;
int score[6];
};
struct StudentBook
{
struct Student studentarray[MAX];
int size;
};
void addStudent(StudentBook* abs)
{
if (abs->size == MAX)
{
cout << "内容已满" << endl;
return;
}
else
{
string name;
cout << "input name" << endl;
cin >> name;
abs->studentarray[abs->size].name = name;
cout << "input sex" << endl;
cout << "1 --- man " << " 2 --- woman" << endl;
int s_sex = 0;
cin >> s_sex;
while (true)
{
if (s_sex == 1 || s_sex == 2)
{
abs->studentarray[abs->size].sex = s_sex;
break;
}
else
{
cout << "error " << " please input 1 or 2" << endl;
}
}
cout << "input id " << endl;
int s_id = 0;
cin >> s_id;
abs->studentarray[abs->size].id = s_id;
cout << "input phone" << endl;
string s_phone;
cin >> s_phone;
abs->studentarray[abs->size].phone = s_phone;
cout << "input address" << endl;
string s_add;
cin >> s_add;
abs->studentarray[abs->size].addr = s_add;
cout << "input 6 subjects score " << endl;
int s_score[6];
for (int i = 0; i < 6; i++)
{
cout << "input "<< i+1 <<" subjects score:" << endl;
cin >> s_score[i];
abs->studentarray[abs->size].score[i] = s_score[i];
}
abs->size++;
cout << "恭喜添加成功" << endl;
system("pause");
system("cls");
}
}
void showStudent(StudentBook* abs)
{
if (abs->size == 0)
{
cout << "当前无人" << endl;
}
else
{
for (int i = 0; i < abs->size; i++)
{
cout << "name: " << abs->studentarray[i].name << "\t";
cout << "sex: " << (abs->studentarray[i].sex == 1 ? "男" : "女") << "\t";
cout << "id: " << abs->studentarray[i].id << "\t";
cout << "phone: " << abs->studentarray[i].phone << "\t";
cout << "address: " << abs->studentarray[i].addr << "\t";
for (int j = 0; j < 6; j++)
{
cout << "score No."<<j+1 <<" subject :"<< abs->studentarray[i].score[j] << "\t";
}
cout <<""<<endl;
}
}
system("pause");
system("cls");
}
int isExist(StudentBook* abs, string s_name)
{
for (int i = 0; i < abs->size; i++)
{
if (abs->studentarray[i].name == s_name)
{
return i;
}
}
return -1;
}
void deleteStudent(StudentBook* abs)
{
cout << "input delete student:" << endl;
string s_name;
cin >> s_name;
int ret = isExist(abs, s_name);
if (ret != -1)
{
for (int i = ret; i < abs->size; i++)
{
abs->studentarray[i] = abs->studentarray[i + 1];
}
abs->size--;
cout << "删除成功" << endl;
}
else
{
cout << "查无此人" << endl;
}
system("pause");
system("cls");
}
void findStudent(StudentBook* abs)
{
string s_name;
cout << "input find name :" << endl;
cin >> s_name;
int i = isExist(abs, s_name);
if (i !=-1)
{
cout << "name: " << abs->studentarray[i].name << "\t";
cout << "sex: " << (abs->studentarray[i].sex == 1 ? "男" : "女") << "\t";
cout << "id: " << abs->studentarray[i].id << "\t";
cout << "phone: " << abs->studentarray[i].phone << "\t";
cout << "address:" << abs->studentarray[i].addr << "\t";
for (int j = 0; j < 6; j++)
{
cout << "score No." << j + 1 << " subject :" << abs->studentarray[i].score[j] << "\t";
}
cout << "" << endl;
}
else
{
cout << "查无此人" << endl;
}
system("pause");
system("cls");
}
void modifyStudent(StudentBook* abs)
{
string s_name;
cout << "input modify name :" << endl;
cin >> s_name;
int i = isExist(abs, s_name);
if (i != -1)
{
string name;
cout << "input name" << endl;
cin >> name;
abs->studentarray[i].name = name;
cout << "input sex" << endl;
cout << "1 --- man " << " 2 --- woman" << endl;
int s_sex = 0;
cin >> s_sex;
while (true)
{
if (s_sex == 1 || s_sex == 2)
{
abs->studentarray[i].sex = s_sex;
break;
}
else
{
cout << "error " << " please input 1 or 2 " << endl;
}
}
cout << "input id " << endl;
int s_id = 0;
cin >> s_id;
abs->studentarray[i].id = s_id;
cout << "input phone " << endl;
string s_phone;
cin >> s_phone;
abs->studentarray[i].phone = s_phone;
cout << "input address " << endl;
string s_add;
cin >> s_add;
abs->studentarray[i].addr = s_add;
int s_score[6];
for (int j = 0; j < 6; j++)
{
cout << "input " << i + 1 << " subjects score:" << endl;
cin >> s_score[j];
abs->studentarray[i].score[j] = s_score[j];
}
cout << "" << endl;
cout << "恭喜添加成功" << endl;
}
else
{
cout << "查无此人" << endl;
}
system("pause");
system("cls");
}
void cleanStudent(StudentBook* abs)
{
abs->size = 0;
cout << "链表清空" << endl;
system("pause");
system("cls");
}
void showMenu()
{
cout << "1.添加学生" << endl;
cout << "2.显示学生" << endl;
cout << "3.删除学生" << endl;
cout << "4.查找学生" << endl;
cout << "5.修改学生" << endl;
cout << "6.清空学生" << endl;
cout << "0.退出系统" << endl;
}
int main()
{
StudentBook abs;
int select = 0;
abs.size = 0;
while (true)
{
showMenu();
cin >> select;
switch (select)
{
case 1:
addStudent(&abs);
break;
case 2:
showStudent(&abs);
break;
case 3:
deleteStudent(&abs);
break;
case 4:
findStudent(&abs);
break;
case 5:
modifyStudent(&abs);
break;
case 6:
cleanStudent(&abs);
break;
case 0:
cout << "欢迎下次使用" << endl;
system("pause");
return 0;
break;
default:
cout << "error" << endl;
system("pause");
system("cls");
break;
}
}
}