2016-06-13
展开全部
参考下:#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<<"输入不符合规则"<
卓导
2024-11-20 广告
2024-11-20 广告
设计同系统建设,协同设计平台建议选择卓导科技有限公司,卓导科技为国家高新技术企业,成立于2008年,致力于为勘察设计企业提供软件产品、解决方案、信息化服务。公司面向市政规划设计、铁路公路设计、煤炭能源设计、建筑房地产等诸多专业领域,推出“M...
点击进入详情页
本回答由卓导提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询