#include #include#include#includeusing namespace std;const long o = 1000;class person {public: friend void addperson(person zhu[]); friend void showperson(person zhu[]); friend void delperson(person zhu[]); friend void findperson(person zhu[]); friend void modperson(person zhu[]); friend void clean(person zhu[]); friend void paixuroom(person zhu[]); friend void wscj(person zhu[]); friend void paixuwscj(person zhu[]); friend void write(person zhu[],int n); friend int read(person zhu[]); string name_; bool sex_; int age_; string number_; int room_; int wscj_;}zhu[o];void addperson(person zhu[]) { int nowall = 0; cout << "请输入姓名" << endl; cin >> zhu[nowall].name_; cout << "请输入性别" << endl; cout << "1男0女" << endl; cin >> zhu[nowall].sex_ ; cout << "请输入年龄" << endl; cin >> zhu[nowall].age_ ; cout << "请输入电话号码" << endl; cin >> zhu[nowall].number_ ; cout << "请输入门牌号(三位数)" << endl; cin >> zhu[nowall].room_ ; zhu[nowall].wscj_ = 100; write(zhu, nowall); nowall++; cout << "卫生成绩默认为100" << endl; cout << "添加成功" << endl; system("pause"); system("cls");}void showperson(person zhu[]) { int nowall = read(zhu); if (nowall == 0) cout << "还未录入学生信息!" << endl; else { for (int i = 0; i < nowall; ++i) { cout << "姓名 " << setw(5)<<zhu[i].name_ << '\t'; cout << "年龄 " << setw(3) << zhu[i].age_<< '\t'; cout << "电话号码 " << setw(13) << zhu[i].number_<< '\t'; cout << "性别 " << setw(3) << (zhu[i].sex_ ?"男":"女") << '\t'; cout << "门牌号 " << setw(5) << zhu[i].room_ << '\t'; cout << "卫生成绩 " << setw(5) << zhu[i].wscj_<<endl; } }cout << "总学生人数为:"<<nowall << endl; system("pause"); system("cls");}int chazhao(person zhu[],string name){ int nowall = read(zhu); for (int i = 0; i < nowall; ++i) { if (zhu[i].name_ == name) { return i; } } return -1;}void delperson(person zhu[]){ int nowall = read(zhu); if (nowall == 0) cout << "还未录入学生信息!" << endl; else cout << "请输入被删除学生的姓名" << endl; string name; cin >> name; int ret=chazhao(zhu, name); if (ret != -1) { for (int i = ret; i < nowall; ++i) zhu[i] = zhu[i + 1]; --nowall; cout << "删除成功" << endl; } else cout << "查无此人" << endl; system("pause"); system("cls");}void findperson(person zhu[]){ int nowall = read(zhu); if (nowall == 0) cout << "还未录入学生信息!" << endl; else cout <<"请输入要查找学生的姓名"<< endl; string name; cin >> name; int ret = chazhao(zhu, name); if (ret != -1) { cout << "姓名 " << setw(5) << zhu[ret].name_ << '\t'; cout << "年龄 " << setw(3) << zhu[ret].age_ << '\t'; cout << "电话号码 " << setw(13) << zhu[ret].number_ << '\t'; cout << "性别 " << setw(3) << (zhu[ret].sex_ ? "男" : "女") << '\t'; cout << "门牌号 " << setw(5) << zhu[ret].room_ << '\t'; cout << "卫生成绩 " << setw(5) << zhu[ret].wscj_ << endl; } else cout << "查无此人" << endl; system("pause"); system("cls");}void modperson(person zhu[]) { int nowall = read(zhu); if (nowall == 0) cout << "还未录入学生信息!" << endl; else cout << "请输入要修改学生的姓名" << endl; string name; cin >> name; int ret = chazhao(zhu, name); if (ret != -1) { char name[10]; cout << "请输入姓名" << endl; cin >> name; zhu[ret].name_ = name; cout << "请输入性别" << endl; cout << "1男0女" << endl; bool sex; cin >> sex; zhu[ret].sex_ = sex; cout << "请输入年龄" << endl; int age; cin >> age; zhu[ret].age_ = age; cout << "请输入电话号码" << endl; char* number = new char[12]; cin >> number; zhu[ret].number_ = number; cout << "请输入门牌号(三位数)" << endl; int room; cin >> room; zhu[ret].room_ = room; cout << "修改成功!" << endl; } else cout << "查无此人" << endl; system("pause"); system("cls");}void clean(person zhu[]){ int nowall = read(zhu); if (nowall == 0) cout << "还未录入学生信息!" << endl; else cout << "确定要清空所有学生信息吗?" << endl; cout << "确定输入 1 取消输入 0" << endl; bool s; cin >> s; if (s != 0) { nowall = 0; cout << "清空成功!" << endl; } system("pause"); system("cls");}void wscj(person zhu[]){ int nowall = read(zhu); cout << "请输入要修改卫生分数的门牌号" << endl; int n, m; cin >> n; for (int i = 0; i < nowall; ++i) { if (zhu[i].room_ == n) { cout << "请输入要修改多少卫生分数" << endl; cin >> m; break; }else cout << "未找到此宿舍!" << endl; } for (int i = 0; i < nowall; ++i) { if (zhu[i].room_ == n) { zhu[i].wscj_ += m; cout << "修改成功!" << endl; continue; } } system("pause"); system("cls");}void paixuroom(person zhu[]){ int nowall = read(zhu); if (nowall == 0) cout << "还未录入学生信息!" << endl; else cout << "按房间号由低到高排序" << endl; int n; string s; bool x; for (int j = 0; j < nowall-1; ++j) { for (int i = 0; i < nowall-j-1; ++i) { if (zhu[i].room_ > zhu[i + 1].room_) { n = zhu[i + 1].age_; zhu[i + 1].age_ = zhu[i].age_; zhu[i].age_ = n; n = zhu[i + 1].room_; zhu[i + 1].room_ = zhu[i].room_; zhu[i].room_ = n; n = zhu[i + 1].wscj_; zhu[i + 1].wscj_ = zhu[i].wscj_; zhu[i].wscj_ = n; s = zhu[i + 1].name_; zhu[i + 1].name_ = zhu[i].name_; zhu[i].name_ = s; s = zhu[i + 1].number_; zhu[i + 1].number_ = zhu[i].number_; zhu[i].number_ = s; x = zhu[i + 1].sex_; zhu[i + 1].sex_ = zhu[i].sex_; zhu[i].sex_ = x; } } } for (int i = 0; i < nowall; ++i) { cout << "姓名 " << setw(5) << zhu[i].name_ << '\t'; cout << "年龄 " << setw(3) << zhu[i].age_ << '\t'; cout << "电话号码 " << setw(13) << zhu[i].number_ << '\t'; cout << "性别 " << setw(3) << (zhu[i].sex_ ? "男" : "女") << '\t'; cout << "门牌号 " << setw(5) << zhu[i].room_ << '\t'; cout << "卫生成绩 " << setw(5) << zhu[i].wscj_ << endl; } cout << "排序成功!" << endl; system("pause"); system("cls");}void paixuwscj(person zhu[]){ int nowall = read(zhu); if (nowall == 0) cout << "还未录入学生信息!" << endl; else cout << "按卫生成绩由高到低排序" << endl; int n; string s; bool x; for (int j = 0; j < nowall - 1; ++j) { for (int i = 0; i < nowall - j - 1; ++i) { if (zhu[i].room_ < zhu[i + 1].room_) { n = zhu[i + 1].age_; zhu[i + 1].age_ = zhu[i].age_; zhu[i].age_ = n; n = zhu[i + 1].room_; zhu[i + 1].room_ = zhu[i].room_; zhu[i].room_ = n; n = zhu[i + 1].wscj_; zhu[i + 1].wscj_ = zhu[i].wscj_; zhu[i].wscj_ = n; s = zhu[i + 1].name_; zhu[i + 1].name_ = zhu[i].name_; zhu[i].name_ = s; s = zhu[i + 1].number_; zhu[i + 1].number_ = zhu[i].number_; zhu[i].number_ = s; x = zhu[i + 1].sex_; zhu[i + 1].sex_ = zhu[i].sex_; zhu[i].sex_ = x; } } } for (int i = 0; i < nowall; ++i) { cout << "姓名 " << setw(5) << zhu[i].name_ << '\t'; cout << "年龄 " << setw(3) << zhu[i].age_ << '\t'; cout << "电话号码 " << setw(13) << zhu[i].number_ << '\t'; cout << "性别 " << setw(3) << (zhu[i].sex_ ? "男" : "女") << '\t'; cout << "门牌号 " << setw(5) << zhu[i].room_ << '\t'; cout << "卫生成绩 " << setw(5) << zhu[i].wscj_ << endl; } cout << "排序成功!" << endl; system("pause"); system("cls");}void write(person zhu[],int n) { ofstream dobe; dobe.open("..\date.txt", ios::out|ios::binary); if (!dobe) { cout << "无法打开文件!" << endl; abort(); } int nowall = n; dobe << nowall << endl << endl; for (int i = 0; i < nowall; ++i) { dobe <<" " << zhu[i].name_ << " " << " " << zhu[i].age_ <<" " <<" " << zhu[i].number_ << " " << " " <<zhu[i].sex_ << " " << " " << zhu[i].room_ << " " << " " << zhu[i].wscj_ << endl; } dobe.close();}int read(person zhu[]) { ifstream f; f.open("..\date.txt", ios::in | ios::binary); if (!f) { cout << "无法打开文件!" << endl; abort(); } int c; f.seekg(0); f >> c; for (int i = 0; i < c; ++i) { f >> zhu[i].name_ >> zhu[i].age_ >> zhu[i].number_ >> zhu[i].sex_ >> zhu[i].room_ >> zhu[i].wscj_ ; } f.close(); return c;}int main(){ person zhu; int nowall = read(&zhu); int opt; while (true) { cout << endl; cout << "淮阴工学院学生宿舍信息管理系统" << endl; cout << " =========================="<<endl; cout << " *** 1.录入学生信息 ***" << endl; cout << " *** 2.修改学生信息 ***" << endl; cout << " *** 3.删除学生信息 ***" << endl; cout << " *** 4.学生信息查询 ***" << endl; cout << " *** 5.显示所有学生信息 ***" << endl; cout << " *** 6.按卫生成绩排序 ***" << endl; cout << " *** 7.清空学生信息 ***" << endl; cout << " *** 8.修改卫生成绩 ***" << endl; cout << " *** 9.按房间号排序 ***" << endl; cout << " *** 0.退出系统 ***" << endl; cout << " ==========================" << endl; cout << endl; cout << " 请选择(1-9,0:退出):"; cin >> opt; switch (opt) { case 1: addperson(&zhu); write(&zhu, nowall); break; case 2: modperson(& zhu); write(&zhu,nowall); break; case 3: delperson(&zhu); write(&zhu, nowall); break; case 4: findperson( & zhu); break; case 5: showperson(&zhu); break; case 6: paixuwscj(&zhu); break; case 7: clean(&zhu); write(&zhu, nowall); break; case 8: wscj(&zhu); write(&zhu, nowall); break; case 9: paixuroom(&zhu); break; case 0: exit(0); default: cout << "输入选项不正确!请重新输入!" << endl; system("pause"); system("cls"); break; } }}
题主发的代码风格真是不拘小杰啊
或许是格式问题,把代码格式化一下吧