#include #include void student::entering() { string SID[M], SName, SSex, SAddress, SPhone, SDormitory; int SAge; ofstream outfile; outfile.open(\"student.txt\"); if (!outfile) { cerr << \"文件打开失败\" << endl; system(\"pause\"); exit(1); string ID; string Name; int Age; string Sex; string Address; string Phone; string Dormitory; void entering(); void show(); void search(); void del(); void count(); void change(); } outfile << \"ID\" << \" \"; outfile <<\"Name\" <<\" \"; outfile << \"Age\" <<\" \"; outfile << \"Sex\" <<\" \"; outfile << \"Address\" <<\" \"; outfile << \"Phone\" <<\" \"; outfile << \"Dormitory\" << endl; for (int i = 1; i < M; i++) { cout << \"请输入学号(按0返回)\" << endl; cin >> SID[i]; for (int j = i-1; j >= 0; j--) { } ID = SID[i]; if (ID == \"0\")break; if (ID != \"0\") { outfile << ID << \" \"; cout << \"请输入姓名\" << endl; cin >> SName; Name = SName; outfile << Name << \" \"; cout << \"请输入年龄\" << endl; cin >> SAge; Age = SAge; outfile << Age << \" \"; cout << \"请输入性别\" << endl; cin >> SSex; Sex = SSex; outfile << Sex << \" \"; cout << \"请输入家庭住址\" << endl; cin >> SAddress; Address = SAddress; outfile << Address << \" \"; cout << \"请输入联系电话\" << endl; cin >> SPhone; if (SID[i] == SID[j]) { } cout << \"学号重复\" << endl; cout << \"请重新输入学号(按0返回)\" << endl; cin >> SID[i]; } } } Phone = SPhone; outfile << Phone << \" \"; cout << \"请输入寝室号\" << endl; cin >> SDormitory; Dormitory = SDormitory; outfile << Dormitory << endl; N++; outfile.close(); ifstream infile; infile.open(\"student.txt\"); if (!infile) { } string s; //vector svec.push_back(s); infile.close(); cerr << \"文件打开失败\" << endl; system(\"pause\"); exit(1); void student::show() { } ifstream infile; infile.open(\"student.txt\"); if (!infile) { } string s; vector svec1.push_back(s); infile.close(); for (vector cout <<*iter << endl; cerr << \"文件打开失败\" << endl; system(\"pause\"); exit(1); void student::search() { int select, i = 0,pos=0,pos1=0,j=1; string str[M], id, name; for (vector cout << \"1、按学号查询\" < case 1:cout << \"请输入学号\" << endl; cin >> id; for ( j = 1; j <= N; j++) { } if (j > N) cout << \"查找失败\" << endl; break; cin >> name; for (int k = 1; k < i; k++) { bool flag = false; if (name == str[k].substr(9, pos1)) { } else { if (flag == true) cout << \"查找失败\" << endl; flag = true; cout << str[k] << endl; continue; if (id == str[j].substr(0, 5)) { } cout << str[j] << endl; break; pos = id.size(); str[i] = *iter; i++; case 2:cout << \"请输入姓名\" << endl; pos1 = name.size(); } } } } void student::del() { string name[M], sex[M], address[M], phone[M], dormitory[M], id[M]; int age[M], j = 0,count; char a[M]; ifstream infile; infile.open(\"student.txt\",ios::in); if (!infile) { cerr << \" open error\" << endl; exit(1); } while (infile.get(a[j])) { if (a[j] == '\\n')break; j++; } a[j] = '\\0'; cout << a << endl; for (int i = 1; i<=N; i++) { infile >> id[i]; cout << \"第\"<> name[i]; cout << name[i] << setw(4); infile >> age[i]; cout << age[i] << setw(4); infile >> sex[i]; cout << sex[i] << setw(4); infile >> address[i]; cout << address[i] << setw(4); infile >> phone[i]; cout << phone[i] << setw(4); infile >> dormitory[i]; cout << dormitory[i]; cout << endl; } infile.close(); cout << \"请输入您想删除学生的序号\" << endl; cin >> count; ; } ofstream outfile; outfile.open(\"student.txt\"); if (!outfile) { } outfile << \"ID\" << \" \"; outfile << \"Name\" << \" \"; outfile << \"Age\" << \" \"; outfile << \"Sex\" << \" \"; outfile << \"Address\" << \" \"; outfile << \"Phone\" << \" \"; outfile << \"Dormitory\" << endl; for (int k = 1; k<=N; k++) { } outfile.close(); N = N - 1; cout << \"已删除成功!\" << endl; if (k!= count) { } outfile << id[k] << \" \"; outfile << name[k] << \" \"; outfile << age[k] << \" \"; outfile << sex[k] << \" \"; outfile << address[k] << \" \"; outfile << phone[k] << \" \"; outfile << dormitory[k] << endl; cerr << \"文件打开失败\" << endl; system(\"pause\"); exit(1); void student::count() { string name[M], sex[M], address[M], phone[M], dormitory[M], id[M]; int age[M], boy = 0, girl = 0, j = 0; char a[M]; ifstream infile; infile.open(\"student.txt\", ios::in); if (!infile) { } cerr << \" open error\" << endl; exit(1); } while (infile.get(a[j])) { } a[j] = '\\0'; for (int i = 0; i < N; i++) { } cout << \"学生总数有\" << boy + girl << \"人\" << endl; cout << \"其中\"; cout << \"男生有:\" << boy << \"个\"< boy++; else girl++; infile >> address[i]; infile >> phone[i]; infile >> dormitory[i]; if (a[j] == '\\n')break; j++; void student::change() { char a[M]; int k=0,j=0; int age[M]; string name[M], sex[M], phone[M], address[M], dormitory[M], id[M]; if (N == 0) { } else { ifstream infile(\"student.txt\"); if (!infile) { } while (infile.get(a[j])) cerr << \" open error\" << endl; exit(1); cout << \"没有学生信息可修改\" << endl; { } a[j] = '\\0'; cout << a << endl; for (int i = 1; i <= N; i++) { } infile.close(); cout << \"你想修改第几个数据? \" << endl; cin >> k; cout << \"请输入新的数据:\" << endl; cout << \"请输入学号:\" << endl; cin >> id[k]; cout << \"请输入姓名:\" << endl; cin >> name[k]; cout << \"请输入年龄:\" << endl; cin >> age[k]; cout << \"请输入性别:\" << endl; cin >> sex[k]; cout << \"请输入家庭地址:\" << endl; cin >> address[k]; cout << \"请输入电话号:\" << endl; cin >> phone[k]; cout << \"请输入宿舍号:\" << endl; cin >> dormitory[k]; ofstream outfile; outfile.open(\"student.txt\"); infile >> id[i]; cout << \"第\" << i << \"个\" << \" \"; cout << id[i] << setw(4); infile >> name[i]; cout << name[i] << setw(4); infile >> age[i]; cout << age[i] << setw(4); infile >> sex[i]; cout << sex[i] << setw(4); infile >> address[i]; cout << address[i] << setw(4); infile >> phone[i]; cout << phone[i] << setw(4); infile >> dormitory[i]; cout << dormitory[i]; cout << endl; if (a[j] == '\\n')break; j++; } } if (!outfile) { } outfile << \"ID\" << \" \"; outfile << \"Name\" << \" \"; outfile << \"Age\" << \" \"; outfile << \"Sex\" << \" \"; outfile << \"Address\" << \" \"; outfile << \"Phone\" << \" \"; outfile << \"Dormitory\" << endl; for (int p = 1; p <= N; p++) { } outfile.close(); cout << \" 已修改成功! \" << endl; outfile << id[p] << \" \"; outfile << name[p] << \" \"; outfile << age[p] << \" \"; outfile << sex[p] << \" \"; outfile << address[p] << \" \"; outfile << phone[p] << \" \"; outfile << dormitory[p] << endl; cerr << \"文件打开失败\" << endl; system(\"pause\"); exit(1); 菜单函数体 #include int choice; do { cout << \"\****************************\\n\"; cout << \"\* 学生基本信息管理系统 *\\n\"; cout << \"\*==========================*\\n\"; cout << \"\* 1、录入学生信息 *\\n\"; cout << \"\* 2、显示学生信息 *\\n\"; cout << \"\* 3、查询学生信息 *\\n\"; cout << \"\* 4、统计学生信息 *\\n\"; cout << \"\* 5、删除学生信息 *\\n\"; cout << \"\* 6、修改学生信息 *\\n\"; cout << \"\* 0、退出管理系统 *\\n\"; cout << \"\****************************\\n\"; } cout << \"\\n\请选择:\"; cin >> choice; } while (choice < 0 || choice > 7); return choice; 主函数 #include extern int menu(); int main() { } system(\"pause\"); student a; int an; do { an = menu(); switch (an) { case 1: a.entering(); break; case 2: a.show(); break; case 3: a.search(); break; case 4: a.count(); break; case 5: a.del(); break; case 6: a.change(); break; case 0: break; default: cout << \"选择错误。\\n\"; break; } } while (an); return 0; 因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- haog.cn 版权所有 赣ICP备2024042798号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务