#includeusing namespace std; struct Person { string _name; string _gender; int _age; double _score; string _Phone; string _address; }; struct personInformation { int _size; struct Person personArray[10]; }; void addPerson(personInformation* personinformation) { string name, gender, Phone, address; int age = 0; double score=0; if (personinformation->_size == 10) { cout << "人数已经满了,不能添加了" << endl; system("pauses"); system("cls"); return; } else { cout << "请输入姓名:" << endl; cin >> name; personinformation->personArray[personinformation->_size]._name = name; cout << "请输入性别:" << endl; while (1) { cin >> gender; if (gender == "男" || gender == "女") { break; } cout << "请重新输入你的性别:" << endl; } personinformation->personArray[personinformation->_size]._gender = gender; cout << "请输入年龄:" << endl; cin >> age; personinformation->personArray[personinformation->_size]._age = age; cout << "请输入分数:" << endl; cin >> score; personinformation->personArray[personinformation->_size]._score = score; cout << "请输入电话:" << endl; cin >> Phone; personinformation->personArray[personinformation->_size]._Phone = Phone; cout << "请输入家庭地址:" << endl; cin >> address; personinformation->personArray[personinformation->_size]._address = address; personinformation->_size++; cout << "恭喜你登记成功..." << endl; system("pause"); system("cls"); } } // void showMenu() { cout << "-------------------------------n"; cout << " *****1、添加学生信息 *****" << endl; cout << " *****2、显示学生信息 *****" << endl; cout << " *****3、删除学生信息 *****" << endl; cout << " *****4、查找学生信息 *****" << endl; cout << " *****5、修改学生信息 *****" << endl; cout << " *****6、清空学生信息 *****" << endl; cout << " *****0、退出学生系统 *****" << endl; cout << "-------------------------------nn"; } void showInformation(personInformation* personinformation) { if (personinformation->_size == 0) { cout << "你还没有添加任何的学生,可以先去添加一个学生后再去查看哦..." << endl; } else { for (int i = 0; i < personinformation->_size; i++) { cout << "姓名:" << personinformation->personArray[i]._name << "t"; cout << "性别:" << personinformation->personArray[i]._gender << "t"; cout << "年龄:" << personinformation->personArray[i]._age << "t"; cout << "分数:" << personinformation->personArray[i]._score << "t"; cout << "电话:" << personinformation->personArray[i]._Phone << "t"; cout << "地址:" << personinformation->personArray[i]._address << endl; } } system("pause"); system("cls"); } int isExist(personInformation* personinformation, string name) { for (int i = 0; i < personinformation->_size; i++) { if (personinformation->personArray[i]._name == name) { return i; } } return -1; } void deleteInformation(personInformation* personinformation) { string name; cout << "请输入你想要删除的名字:" << endl; cin >> name; int res = isExist(personinformation, name); if (res == -1) { cout << "没有找到这一个人..." << endl; } else { for (int i = 0; i < personinformation->_size; i++) { personinformation->personArray[i] = personinformation->personArray[i + 1]; } personinformation->_size--; cout << "删除成功..." << endl; } system("pause"); system("cls"); } void foundInformation(personInformation* personinformation) { string name; cout << "请输入你想要查找的学生:" << endl; cin >> name; int res = isExist(personinformation, name); if (res != -1) { cout << "姓名:" << personinformation->personArray[res]._name << "t"; cout << "性别:" << personinformation->personArray[res]._gender << "t"; cout << "年龄:" << personinformation->personArray[res]._age << "t"; cout << "年龄:" << personinformation->personArray[res]._score << "t"; cout << "电话:" << personinformation->personArray[res]._Phone << "t"; cout << "地址:" << personinformation->personArray[res]._address << endl; } else { cout << "查无此人,请添加后再一次查看吧..." << endl; } system("pause"); system("cls"); } void changeInformation(personInformation* personinformation) { string name, gender, Phone, address; int age; double score = 0; cout << "请输入你想要改变学生信息的姓名:" << endl; cin >> name; int res = isExist(personinformation, name); string name2; if (res != -1) { cout << "请根据下面的要求进行更改:" << endl; cout << "请输入姓名:" << endl; cin >> name2; personinformation->personArray[res]._name = name2; cout << "请输入性别:" << endl; while (1) { cin >> gender; if (gender == "男" || gender == "女") { break; } cout << "请重新输入你的性别:" << endl; } personinformation->personArray[res]._gender = gender; cout << "请输入年龄:" << endl; cin >> age; personinformation->personArray[res]._age = age; cout << "请输入分数:" << endl; cin >> score; personinformation->personArray[res]._score = score; cout << "请输入电话:" << endl; cin >> Phone; personinformation->personArray[res]._Phone = Phone; cout << "请输入家庭地址:" << endl; cin >> address; personinformation->personArray[res]._address = address; cout << "恭喜你已经再次成功修改了学生" << name << "的个人信息" << endl; } else { cout << "暂未找到这个人的信息..." << endl; } system("pause"); system("cls"); } void clearInformation(personInformation* personinformation) { if (personinformation->_size == 0) { cout << "你当前还没有任何的学生信息..." << endl; system("pause"); system("cls"); return; } else { string chance; cout << "你确定要清空所有的学生的个人信息吗?y/n" << endl; while (true) { cin >> chance; if (chance == "y" || chance == "n") { break; } } if (chance == "y") { personinformation->_size = 0; cout << "你已经没有任何人的个人信息了..." << endl; } } system("pause"); system("cls"); } int main() { personInformation personinformation; personinformation._size = 0; int select = 0; while (1) { showMenu(); cout << "请在0-6中进行选择:" << endl; cin >> select; switch (select) { case 1:// addPerson(&personinformation); break; case 2:// showInformation(&personinformation); break; case 3:// deleteInformation(&personinformation); break; case 4:// foundInformation(&personinformation); break; case 5:// changeInformation(&personinformation); break; case 6:// clearInformation(&personinformation); break; case 0:// cout << "欢迎下次使用" << endl; system("pause"); system("cls"); break; } } system("pause"); return 0; }



