新学籍管理系统C++做的.docx

上传人:b****7 文档编号:10477545 上传时间:2023-02-13 格式:DOCX 页数:63 大小:27.86KB
下载 相关 举报
新学籍管理系统C++做的.docx_第1页
第1页 / 共63页
新学籍管理系统C++做的.docx_第2页
第2页 / 共63页
新学籍管理系统C++做的.docx_第3页
第3页 / 共63页
新学籍管理系统C++做的.docx_第4页
第4页 / 共63页
新学籍管理系统C++做的.docx_第5页
第5页 / 共63页
点击查看更多>>
下载资源
资源描述

新学籍管理系统C++做的.docx

《新学籍管理系统C++做的.docx》由会员分享,可在线阅读,更多相关《新学籍管理系统C++做的.docx(63页珍藏版)》请在冰豆网上搜索。

新学籍管理系统C++做的.docx

新学籍管理系统C++做的

//文件“信息管理系统.cpp”

#include

#include

#include"common.h"

#include"信息录入.cpp"

#include"信息查询.cpp"

#include"信息排序.cpp"

#include"信息修改.cpp"

#include"信息删除.cpp"

usingnamespacestd;

intmain()

{

inta;

h1:

cout<<"—*—*—学生信息管理系统—*—*—"<

cout<<"1----学生基本信息录入2----学生信息查询"<

cout<<"3----学生信息排序4----学生信息修改"<

cout<<"5----学生信息删除0----退出"<

ifstreaminfile("record_n.txt",ios:

:

in);

infile>>record_n;//读取record_n,获知文件student.dat中保存有几个学生的数据

infile.close();

h2:

cout<<"已经记录有"<

";

cin>>a;

switch(a)

{

case0:

return0;break;

case1:

info_input();break;

case2:

info_inquire();break;

case3:

info_sort();break;

case4:

info_update();break;

case5:

info_delete();break;

default:

cout<<"Error!

"<

}

cout<

gotoh1;

return0;

}

//文件“信息修改.cpp”

#include

#include

#include

usingnamespacestd;

/*————————————信息修改函数——————————————*/

voidinfo_update()

{

inti,j,answer,num;

studentstud1[n],stud2[n];

cout<<"请输入要修改的学生学号(返回请输入0):

";

cin>>num;

if(num==0)gotoh0;

else

{

ifstreaminfile("student.dat",ios:

:

binary);

if(!

infile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

if(record_n==0)cout<<"Error!

\n没有记录"<

else

{

for(i=0;i

{

infile.read((char*)&stud1[i],sizeof(stud1[i]));

}

}

/*进行对比,找到相应学号*/

infile.close();

for(i=0;i

{

if(num==stud1[i].num)//判断,如果符合查询条件则输出到屏幕

{

cout<<"学号:

"<

"<

cout<<"性别:

"<

"<

cout<<"电话号码:

"<

"<

j=i;//记录要修改学号的序号

}

}

for(i=0;i

{

if(num==stud1[i].num)break;

}

if(i>=record_n)

{

cout<<"Error!

\n未找到该学号,";

gotoh0;

}

for(i=0;i

stud2[i]=stud1[i];

for(i=j+1;i

stud2[i]=stud1[i];

cout<<"请按照姓名、性别、出生年、月、电话号码、省份的顺序输入学生新信息(若要修改学号请删除该记录后重新录入新信息):

"<

/*将对应学号的信息和其他学号信息记录到stud2[],清空原文件后写入文件*/

stud2[j].num=stud1[j].num;

cin>>stud2[j].name>>stud2[j].sex>>stud2[j].birthday.year>>stud2[j].birthday.month>>stud2[j].phone>>stud2[j].address;

ha:

cout<<"是否确定修改该记录?

确定输入1,返回输入0"<

cin>>answer;

if(answer==0)gotoh0;

if(answer!

=0&&answer!

=1)

{

cout<<"Error!

"<

gotoha;

}

if(answer==1)

{

fstreamiofile("student.dat",ios:

:

out|ios:

:

binary);

if(!

iofile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

for(i=0;i

{

iofile.write((char*)&stud2[i],sizeof(stud2[i]));

}

iofile.close();

cout<<"该学生信息修改完毕!

"<

}

}

h0:

cout<

}

//文件“信息删除.cpp”

#include

#include

#include

usingnamespacestd;

/*————————————信息删除函数——————————————*/

voidinfo_delete()

{

inti,j,answer,num;

studentstud1[n],stud2[n];

cout<<"返回请输入0,删除全部学生信息请输入-1"<

cout<<"请输入要删除的学生学号:

";

cin>>num;

if(num==-1)

{

ofstreamoutfile("record_n.txt",ios:

:

out);

if(!

outfile)

{

cerr<<"Openfileerror!

"<

abort();

}

outfile<<0;//数据个数恢复为0

outfile.close();

fstreamiofile("student.dat",ios:

:

out|ios:

:

binary);

if(!

iofile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

iofile.close();

cout<<"学生信息已经全部删除"<

}

else

{

if(num==0)gotoh0;

else

{

ifstreaminfile("student.dat",ios:

:

binary);

if(!

infile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

if(record_n==0)cout<<"Error!

\n没有记录"<

else

{

for(i=0;i

{

infile.read((char*)&stud1[i],sizeof(stud1[i]));

}

}

infile.close();

/*进行对比,找到相应学号*/

for(i=0;i

{

if(num==stud1[i].num)//判断,如果符合查询条件则输出到屏幕

{

cout<<"学号:

"<

"<

cout<<"性别:

"<

"<

cout<<"电话号码:

"<

"<

j=i;//记录要删除学号的序号

}

}

for(i=0;i

{

if(num==stud1[i].num)break;

}

if(i>=record_n)

{

cout<<"Error!

\n未找到该学号,";

gotoh0;

}

ha:

cout<<"是否确定删除该记录?

确定输入1,返回输入0"<

cin>>answer;

if(answer==0)gotoh0;

if(answer!

=0&&answer!

=1)

{

cout<<"Error!

"<

gotoha;

}

if(answer==1)

{

/*将对应学号去掉后,剩余学生信息用stud2[]记录,清空原文件,再写入文件*/

for(i=0;i

stud2[i]=stud1[i];

for(i=j;i

stud2[i]=stud1[i+1];

ofstreamoutfile("record_n.txt",ios:

:

out);

if(!

outfile)

{

cerr<<"Openfileerror!

"<

abort();

}

outfile<

outfile.close();

fstreamiofile("student.dat",ios:

:

out|ios:

:

binary);

if(!

iofile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

for(i=0;i

{

iofile.write((char*)&stud2[i],sizeof(stud2[i]));

}

iofile.close();

cout<<"该学号已经删除"<

}

}

}

h0:

cout<

}

//文件“信息排序.cpp”

#include

#include

#include

usingnamespacestd;

/*————————————信息排序函数————————————*/

voidinfo_sort()

{

inti;

cout<

h3:

cout<<"请选择:

";

cin>>i;

switch(i)

{

case0:

gotoh7;

case1:

sort_num();break;

case2:

sort_day();break;

default:

cout<<"Error!

"<

}

h7:

cout<

}

/*—————按照学号排序函数—————*/

voidsort_num()

{

inti,j;

studentstud1[n],t;

ifstreaminfile("student.dat",ios:

:

binary);

if(!

infile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

if(record_n==0)cout<<"Error!

\n没有记录"<

else

{

for(i=0;i

{

infile.read((char*)&stud1[i],sizeof(stud1[i]));

}

}

for(i=0;i

{

for(j=0;j

{

if(stud1[j].num>stud1[j+1].num)

{

t=stud1[j];

stud1[j]=stud1[j+1];

stud1[j+1]=t;

}

}

}

infile.close();

/*将排序好的数据写入文件*/

ofstreamoutfile("student.dat",ios:

:

out|ios:

:

binary);

if(!

outfile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

for(i=0;i

{

outfile.write((char*)&stud1[i],sizeof(stud1[i]));

}

outfile.close();

cout<<"排序完成";

cout<

}

/*————按照出生年月排序函数————*/

voidsort_day()

{

inti,j;

studentstud1[n],t;

ifstreaminfile("student.dat",ios:

:

binary);

if(!

infile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

if(record_n==0)cout<<"Error!

\n没有记录"<

else

{

for(i=0;i

{

infile.read((char*)&stud1[i],sizeof(stud1[i]));

}

}

/*以下对学生的出生年月进行排序*/

for(i=0;i

{

for(j=0;j

{

if(stud1[j].birthday.year>stud1[j+1].birthday.year)

{

t=stud1[j];

stud1[j]=stud1[j+1];

stud1[j+1]=t;

}

}

}

for(i=0;i

{

for(j=0;j

{

if(stud1[j].birthday.year==stud1[j+1].birthday.year)

{

if(stud1[j].birthday.month>stud1[j+1].birthday.month)

{

t=stud1[j];

stud1[j]=stud1[j+1];

stud1[j+1]=t;

}

}

}

}

infile.close();

/*将排序好的数据写入文件*/

ofstreamoutfile("student.dat",ios:

:

out|ios:

:

binary);

if(!

outfile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

for(i=0;i

{

outfile.write((char*)&stud1[i],sizeof(stud1[i]));

}

outfile.close();

cout<

}

//文件“信息录入.cpp”

#include

#include

#include

usingnamespacestd;

/*——————信息录入函数——————*/

voidinfo_input()

{

inti=0,j;

studentstud1[n];

student*p,*p1;

p=stud+i;

p1=stud1+record_n;

ifstreaminfile("student.dat",ios:

:

binary);

if(record_n==0)cout<

else

{

if(!

infile)

{

cerr<<"Openfileerror!

"<

exit

(1);

}

for(i=0;i

{

infile.read((char*)&stud1[i],sizeof(stud1[i]));

}

infile.close();

cout<

}

cout<<"请按以下顺序输入学生信息:

学号、姓名、性别、出生年、月、电话号码、省份";

cout<

for(i=0;i

{

cout<<"请输入第"<

";

cin>>p->num;

p1->num=p->num;

if(p->num==0)break;

for(j=0;j

{

if(p->num==stud1[j].num)

{

cout<<"Error!

\n输入的学号与已有记录重复!

"<

gotohi;

}

}

cin>>p->name>>p->sex;

cin>>p->birthday.year>>p->birthday.month;

cin>>p->phone>>p->address;

ofstreamoutfile("student.dat",ios:

:

app|ios:

:

binary);

if(!

outfile)

{

cerr<<"Openfileerror!

"<

abort();

}

outfile.write((char*)&stud[i],sizeof(stud[i]));

outfile.close();

fstreamiofile("record_n.txt",ios:

:

out);

if(!

iofile)

{

cerr<<"Openfileerror!

"<

abort();

}

iofile<

iofile.close();

}

hi:

cout<

}

//文件“信息查询.cpp”

#include

#include

#include

usingnamespacestd;

/*——————————————信息查询函数————————————*/

voidinfo_inquire()

{

inti;

h6:

cout<

cout<<"4—输出全部学生信息,0—返回"<

h3:

cout<<"请选择:

";

cin>>i;

switch(i)

{

case0:

gotoh7;

case1:

acc_num();break;

case2:

acc_name();break;

case3:

acc_sex();break;

case4:

output_all();break;

default:

cout<<"Error!

"<

}

gotoh6;

h7:

cout<

}

/*————按照学号查询函数—————*/

voidacc_num()

{

inti;

intnum;

studentstud1[n];

ifstreaminfile("student.dat",ios:

:

binary);

if(!

infile)

{

cerr<<"Openfileerror!

"<

gotoh5;

}

h4:

cout<<"请输入要查询的学生的学号(返回请输入0):

"<

cin>>num;

if(num==0)

{

infile.close();

gotoh5;

}

for(i=0;i

{

infile.read((char*)&stud1[i],sizeof(stud1[i]));

}

infile.close();

for(i=0;i

{

if(num==stud1[i].num)//判断,如果符合查询条件则输出到屏幕

{

cout<<"学号:

"<

"<

cout<<"性别:

"<

"<

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 军事政治

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1