参考下:#include#include#include#defineSTU_NUM10#defineSTU_NAME_LEN20#defineSTU_NO_LEN10#defineSTU_SEX_LEN6usingnamespacestd;classStudent{public:voidinitStuInfo();//初始化学生信息voidaddStuInfo();//添加学生信息voidmodifyStyInfo();//更改学生信息voidsearchStuInfo();//查询学生信息voiddeleteStuInfo();//删除学生信息voidprintStuInfo();//打印学生信息private:charsno[STU_NO_LEN];charstuName[STU_NAME_LEN];charsex[STU_SEX_LEN];intage;};voidStudent::initStuInfo(){ofstreamoutfile;outfile.open("stuInfo",ios::trunc);if(!outfile){cout>sno;cout>stuName;cout>sex;cout>age;outfileinputName;while(!infile.eof()){infile>>sno>>stuName>>sex>>age;if(infile.fail()){break;}if(strcmp(inputName,stuName)==0){coutinputName;ifstreaminfile;infile.open("stuInfo",ios::in);if(!infile){cout>sno>>stuName>>sex>>age;if(infile.fail()){break;}if(strcmp(inputName,stuName)==0){break;}else{strcpy(stNo[count],sno);strcpy(stName[count],stuName);strcpy(stSex[count],sex);stAge[count]=age;}count++;}infile.close();ifstreaminfile2;infile2.open("stuInfo",ios::in);if(!infile2){cout>sno>>stuName>>sex>>age;if(infile2.fail()){break;}if(curCount==count){curCount++;continue;}if(curCount>count){strcpy(stNo[curCount-1],sno);strcpy(stName[curCount-1],stuName);strcpy(stSex[curCount-1],sex);stAge[curCount-1]=age;}curCount++;}infile2.close();initStuInfo();//初始化//重新写入文件ofstreamoutfile;outfile.open("stuInfo",ios::app);if(!outfile){cout>inputName;ifstreaminfile;infile.open("stuInfo",ios::in);if(!infile){cout>sno>>stuName>>sex>>age;if(infile.fail()){break;}count++;if(strcmp(inputName,stuName)==0){cout>stNo[count-1];cout>stName[count-1];cout>stSex[count-1];cout>stAge[count-1];break;}else{strcpy(stNo[count-1],sno);strcpy(stName[count-1],stuName);strcpy(stSex[count-1],sex);stAge[count-1]=age;}}infile.close();ifstreaminfile2;infile2.open("stuInfo",ios::in);if(!infile2){cout>sno>>stuName>>sex>>age;if(infile2.fail()){break;}curCount++;if(curCount>count){strcpy(stNo[curCount-1],sno);strcpy(stName[curCount-1],stuName);strcpy(stSex[curCount-1],sex);stAge[curCount-1]=age;}}infile2.close();initStuInfo();//初始化//重新写入文件ofstreamoutfile;outfile.open("stuInfo",ios::app);if(!outfile){cout>sno>>stuName>>sex>>age;if(infile.fail()){break;}coutnum;switch(num){case1:stu.initStuInfo();break;case2:stu.addStuInfo();break;case3:stu.modifyStyInfo();break;case4:stu.deleteStuInfo();break;case5:stu.searchStuInfo();break;case6:stu.printStuInfo();break;default:cout<<"输入不符合规则"<
温馨提示:答案为网友推荐,仅供参考