logo资料库

学生宿舍管理系统C++.doc

第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
资料共3页,全文预览结束
long int stu_num; long stu_num; //学号 // 班 级 ifstream file1; ofstream file3; char flag = 'y'; strcpy(class_name, c); class student { private: //姓名 student() { while( flag=='y' || flag=='Y') { cout<<"\t\t 6:显示全部学生信息\n"; // cout<<"\t\t 2:按学号查看学生信息!\n"; cout<<"\t\t 4:按姓名查看学生信息!\n"; char class_name[40]; stu_num=0; char stu_name[40]; char house_name[20]; return stu_num; } char * Gethousename(void) // 宿 舍 号 查 找 { #include #include #include #include namespace std; char stu_name[40]; stu_name[0] =0; 舍 public: house_name[0] =0; } student::student(long a, char * b,char *c,char *d) { } char * Getstuname(void) //姓名查找 { 查 找 { house_name; } char * Getclassname(void) // 按 班 级 查 找 { Setdata(long a, char *b,char *c,char *d) { using // 学 号 , 宿 舍 号 //班别 char house_name[20]; //宿 class_name[0] =0; Setdata(a , b, c, d); return stu_name ; } long Getstunum(void) //学号 return return class_name; } void strcpy(stu_name, b); strcpy(house_name, d); } void Show(void) { cout<<" 班 cout<<" 学 号 :"<>stu_num; cin.clear(); while (stu_num<100000 || stu_num>999999) cout << "你输入的学号不正确,请输入一个六位数的学号" << endl; rewind(stdin); file1.open("c:\\stu.dat",ios::in | ios::binary | cout << "学号:"; file1.read((char ios::beg);//按读方式打开文件 *)&s1,sizeof(student)); { if(s1.Getstunum()==stu_num) file1.clear(); file1.close(); cout << "学号重复,请重输入!" cout<<" 输 入 姓 名 : "; cin>>stu_name; << endl; cout<<"输入宿舍:"; cin>>house_name; cout<<"输入班级:"; cin>>class_name; s1.Setdata(stu_num,stu_name,class_name,house_name); file3.close(); cout<<" 请 输 入 学 生 的 学 号 :"; while (stu_num<100000 || stu_num>999999) cin.clear(); cout << "你输入的学号不正确,请输入一个六位数的学号" << endl; file1.open("c:\\stu.dat",ios::in | int n; if(n==sizeof(student)) s1.Show(); if case '2': // 按 学 号 查 找 file3.write((char*)&s1,sizeof(s1)); break; cin>>stu_num; rewind(stdin); cout << "学号:"; ios::binary | ios::beg);// 按 读 方 式 打 开 文 件 file1.read((char *)&s1,sizeof(student)); { flags=1; if(s1.Getstunum()==stu_num) cin >> stu_num; } } } //显示学生信息 file1.clear(); n=file1.gcount(); flags=1; cin>>choice; input: if (flags==1) goto input; while(!file1.eof()) { int n; cin >> stu_num; } switch(choice) flags=0; while(!file1.eof()) { 按 学 号 删 学 生 信 if(n==sizeof(student)) } } { file1.close(); { { { cin.clear(); } 8: char choice; stu_num = a; file3.clear(); } n=file1.gcount();
(flags==0) cout << "没有找学号为:"<< stu_num <<"的学生记录!" << endl; { case '3': // 按 宿 舍 号 查 找 flags=0; cout<<" 请 输 入 宿 舍 号:"; file1.open("c:\\stu.dat",ios::in | ios::binary | ios::beg);//按读方式打开文 int n; n=file1.gcount(); if(strcmp(s1.Gethousename(),house_name)==0) } cout << "没有找到宿舍 //按姓 cin>>stu_name; } if (flags==0) flags=0; cout<<" 请 输 入 学 生 姓 名 :"; case '4': break; } break; while(!file1.eof()) { flags=1; file1.close(); cin>>house_name; 件 file1.read((char *)&s1,sizeof(student)); if(n==sizeof(student)) { s1.Show(); file1.clear(); 为:"<< house_name <<"的学生记录!" << endl; 名 查 找 file1.open("c:\\stu.dat",ios::in while(!file1.eof()) *)&s1,sizeof(student)); if(n==sizeof(student)) s1.Show(); ios::binary { } | | ios::beg);// 按 读 方 式 打 开 文 件 int n; { } if(strcmp(s1. Getstuname(),stu_name)==0) flags=1; file1.close(); <<" 的 学 生 记 录 !" << endl; cout<<" 请 输 入 班 级 名 称 :"; ios::binary | ios::beg);// 按 读 方 式 打 开 文 件 int n; n=file1.gcount(); Getclassname(),class_name)==0) file1.read((char n=file1.gcount(); { file1.clear(); cout << "没有找到姓名为:"<< stu_name case '5': break; // 按 班 级 查 找 file1.open("c:\\stu.dat",ios::in | { file1.read((char *)&s1,sizeof(student)); if(strcmp(s1. } if cout << " 没 有 找 到 该 班 级 为:"<< class_name <<" 的 学 生 记 录!" << endl; if (flags==0) flags=0; cin>>class_name; if(n==sizeof(student)) { flags=1; file1.close(); while(!file1.eof()) file1.clear(); s1.Show(); } { } } (flags==0) flags=0; file1.open("c:\\stu.dat",ios::in | ios::binary);//按读方式打开文件 break; case '6': // 显 示 全 部 学 生 信 息 } { // int n; flags=0; flags=0; break; // file1.clear(); if(n==sizeof(student)) cout << " 学 号 :"; rewind(stdin); // // cout << "数据库没有记录!" << endl; cout<<" 请 输 入 要 修 改 学 生 的 学 号:"; while (stu_num<100000 || stu_num>999999) // n=file1.gcount(); flags=1; if (flags==0) // 修 改 学 生 信 息 按 学 号 // cin>>stu_num; // // endl; file1.open("c:\\stu.dat",ios::in | while(!file1.eof()) // { // n=file1.gcount(); // if(n==sizeof(student)) // // cin>>stu_name; // "; cin>>house_name; file3.write((char*)&s1,sizeof(s1)); // // cout << "没有此学生记录,不能进行修改!" << endl; // case '8': default: flag = 'n'; while(!file1.eof()) file1.read((char *)&s1,sizeof(student)); s1.Show(); file1.close(); case '7': // cin.clear(); cout << "你输入的学号不正确,请输入一个六位数的学号" << // ios::beg);// 按 读 方 式 打 开 文 件 // // if(s1.Getstunum()==stu_num) cout<<"输入姓名:"; cout<<"输入宿舍: // } { // break; // } cout file1.read((char *)&s1,sizeof(student)); { // s1.Setdata(stu_num,stu_name,class_name,house_name); file3.open("c:\\stu.dat",ios::out|ios::binary); // // ios::binary | // cout<<"输入班级:"; cin>>class_name; // // break; // break; //删除学生信息按学号 cin >> stu_num; if (flags==0) // file3.close(); // file1.close(); file1.clear(); flags=1; // } // } int n; } // { // } // { // // // // } { }
<< "谢谢您的使用!" << endl; }
分享到:
收藏