C++学生管理系统Word文件下载.docx
《C++学生管理系统Word文件下载.docx》由会员分享,可在线阅读,更多相关《C++学生管理系统Word文件下载.docx(17页珍藏版)》请在冰点文库上搜索。
voidstudent:
:
entering()
stringSID[M],SName,SSex,SAddress,SPhone,SDormitory;
intSAge;
ofstreamoutfile;
outfile.open("
student.txt"
);
if(!
outfile)
{
cerr<
<
"
文件打开失败"
<
endl;
system("
pause"
exit
(1);
}
outfile<
ID"
;
"
Name"
Age"
Sex"
Address"
Phone"
Dormitory"
for(inti=1;
i<
M;
i++)
cout<
请输入学号(按0返回)"
cin>
>
SID[i];
for(intj=i-1;
j>
=0;
j--)
{
if(SID[i]==SID[j])
{
cout<
学号重复"
请重新输入学号(按0返回)"
cin>
}
}
ID=SID[i];
if(ID=="
0"
)break;
if(ID!
="
)
outfile<
ID<
cout<
请输入姓名"
cin>
SName;
Name=SName;
Name<
请输入年龄"
SAge;
Age=SAge;
Age<
请输入性别"
SSex;
Sex=SSex;
Sex<
请输入家庭住址"
SAddress;
Address=SAddress;
Address<
请输入联系电话"
SPhone;
Phone=SPhone;
Phone<
请输入寝室号"
SDormitory;
Dormitory=SDormitory;
Dormitory<
N++;
outfile.close();
ifstreaminfile;
infile.open("
infile)
strings;
//vector<
while(getline(infile,s))
svec.push_back(s);
infile.close();
}
show()
vector<
svec1;
svec1.push_back(s);
for(vector<
iteratoriter=svec1.begin();
iter!
=svec1.end();
iter++)
*iter<
search()
intselect,i=0,pos=0,pos1=0,j=1;
stringstr[M],id,name;
iteratoriter=svec.begin();
iter!
=svec.end();
iter++)
str[i]=*iter;
i++;
cout<
1、按学号查询"
endl;
2、按姓名查找"
cin>
select;
switch(select)
case1:
cout<
请输入学号"
id;
pos=id.size();
for(j=1;
j<
=N;
j++)
if(id==str[j].substr(0,5))
str[j]<
break;
if(j>
N)
查找失败"
break;
case2:
name;
pos1=name.size();
for(intk=1;
k<
i;
k++)
boolflag=false;
if(name==str[k].substr(9,pos1))
flag=true;
str[k]<
continue;
else
if(flag==true)
cout<
del()
stringname[M],sex[M],address[M],phone[M],dormitory[M],id[M];
intage[M],j=0,count;
chara[M];
ios:
in);
infile)
openerror"
while(infile.get(a[j]))
if(a[j]=='
\n'
j++;
a[j]='
\0'
a<
i<
=N;
infile>
id[i];
第"
i<
个"
id[i]<
setw(4);
name[i];
name[i]<
setw(4);
age[i];
age[i]<
sex[i];
sex[i]<
address[i];
address[i]<
phone[i];
phone[i]<
dormitory[i];
请输入您想删除学生的序号"
count;
for(intk=1;
k<
if(k!
=count)
id[k]<
name[k]<
age[k]<
sex[k]<
address[k]<
phone[k]<
dormitory[k]<
N=N-1;
已删除成功!
count()
intage[M],boy=0,girl=0,j=0;
ios:
for(inti=0;
N;
if(sex[i]=="
男"
boy++;
else
girl++;
学生总数有"
boy+girl<
人"
其中"
男生有:
boy<
女生有:
girl<
change()
intk=0,j=0;
intage[M];
stringname[M],sex[M],phone[M],address[M],dormitory[M],id[M];
if(N==0)
没有学生信息可修改"
else
ifstreaminfile("
if(!
cerr<
exit
(1);
while(infile.get(a[j]))
if(a[j]=='
j++;
a[j]='
for(inti=1;
infile>
id[i]<
infile.close();
你想修改第几个数据?
k;
请输入新的数据:
请输入学号:
id[k];
请输入姓名:
name[k];
请输入年龄:
age[k];
请输入性别:
sex[k];
请输入家庭地址:
address[k];
请输入电话号:
phone[k];
请输入宿舍号:
dormitory[k];
ofstreamoutfile;
outfile.open("
system("
outfile<
for(intp=1;
p<
p++)
id[p]<
name[p]<
age[p]<
sex[p]<
address[p]<
phone[p]<
dormitory[p]<
outfile.close();
已修改成功!
菜单函数体
intmenu(){
intchoice;
do{
\t****************************\n"
\t*学生基本信息管理系统*\n"
\t*==========================*\n"
\t*1、录入学生信息*\n"
\t*2、显示学生信息*\n"
\t*3、查询学生信息*\n"
\t*4、统计学生信息*\n"
\t*5、删除学生信息*\n"
\t*6、修改学生信息*\n"
\t*0、退出管理系统*\n"
\n\t请选择:
choice;
}while(choice<
0||choice>
7);
returnchoice;
主函数
intN=0;
externintmenu();
intmain()
studenta;
intan;
an=menu();
switch(an){
case1:
a.entering();
break;
case2:
a.show();
case3:
a.search();
case4:
a.count();
case5:
a.del();
case6:
a.change();
case0:
default:
选择错误。
\n"
}while(an);
return0;
system("