C++课程设计《学生信息管理系统》代码word文档良心出品.docx
- 文档编号:26266759
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:16
- 大小:16.79KB
C++课程设计《学生信息管理系统》代码word文档良心出品.docx
《C++课程设计《学生信息管理系统》代码word文档良心出品.docx》由会员分享,可在线阅读,更多相关《C++课程设计《学生信息管理系统》代码word文档良心出品.docx(16页珍藏版)》请在冰豆网上搜索。
C++课程设计《学生信息管理系统》代码word文档良心出品
#include
#include
#include
#include
usingnamespacestd;
#defineM200//可以存信息总量
intN=0;//学生总量
classstudent
{
public:
student();
voidset();//初始化信息,第一次对信息的录入
voidadd();//添加学生信息
voiddel();//删除某学生信息
voidchange();//修改某学生信息
voidsearch();//查询某学生信息
voiddisplay();//显示全部学生信息
private:
staticintnum;
stringname,sex,age,birthday,address,tel,Email;
};
intstudent:
:
num=1000;
student:
:
student(){}
///初始化文件
voidstudent:
:
set()
{
inti;
stringsetname,setsex,setage,setbirthday,setaddress,settel,setEmail;
ofstreamoutfile;
outfile.open("f1.txt",ios:
:
out);//----打开文件----
if(!
outfile)
{
cerr<<"openerror"< exit (1); } //----依次录入相应个数的学生信息---- for(i=0;i { cout<<"当姓名输入为'0'时,停止输入! ! ! "< cout<<"请输入姓名: "< cin>>setname; name=setname; if(setname=="0")break; if(setname! ="0") { N++; num++; outfile< outfile< cout<<"请输入性别: "< cin>>setsex; sex=setsex; outfile< cout<<"请输入年龄: "< cin>>setage; age=setage; outfile< cout<<"请输入出生日期: "< cin>>setbirthday; birthday=setbirthday; outfile< cout<<"请输入家庭住址: "< cin>>setaddress; address=setaddress; outfile< cout<<"请输入电话: "< cin>>settel; tel=settel; outfile< cout<<"请输入电子邮箱: "< cin>>setEmail; Email=setEmail; outfile< } } outfile.close();//----关闭文件---- } ///添加文件 voidstudent: : add() { stringaddname,addsex,addage,addbirthday,addaddress,addtel,addEmail; //----以追加的方式录入信息,直接将信息追加到以前文件的末尾---- ofstreamoutfile("f1.txt",ios: : app); if(! outfile) { cerr<<"openerror"< exit (1); } N=N+1; //----依次输入相应的数据,并且追加到之前的文件中去---- cout<<"请输入您要添加的数据"< num++; outfile< cout<<"请输入姓名: "< cin>>addname; outfile< cout<<"请输入性别: "< cin>>addsex; outfile< cout<<"请输入年龄: "< cin>>addage; outfile< cout<<"请输入出生日期: "< cin>>addbirthday; outfile< cout<<"请输入家庭住址: "< cin>>addaddress; outfile< cout<<"请输入电话: "< cin>>addtel; outfile< cout<<"请输入电子邮件: "< cin>>addEmail; outfile< outfile.close(); cout<<"已添加成功! "< } ///删除文件 voidstudent: : del() { intk,i; intnum[M]; stringname[M],sex[M],age[M],birthday[M],address[M],tel[M],Email[M]; ifstreaminfile("f1.txt",ios: : in); if(! infile) { cerr<<"openerror"< exit (1); } for(i=0;i { cout<<""; infile>>num[i]; cout< infile>>name[i]; cout< infile>>sex[i]; cout< infile>>age[i]; cout< infile>>birthday[i]; cout< infile>>address[i]; cout< infile>>tel[i]; cout< infile>>Email[i]; cout< } cout<<"您想删除第几个学生信息? "< cin>>k; k=k-1; infile.close(); ofstreamoutfile("f1.txt",ios: : out); if(! outfile) { cerr<<"openerror"< exit (1);//退出程序 } //----将数组存取的信息输出到文件中去---- for(i=0;i { if(i! =k) { outfile< outfile< outfile< outfile< outfile< outfile< outfile< outfile< } } outfile.close(); N=N-1; cout<<"已删除成功! "< } ///修改文件 voidstudent: : change() { inti,k; intnum[M]; stringname[M],sex[M],age[M],birthday[M],address[M],tel[M],Email[M]; ifstreaminfile("f1.txt",ios: : in); if(! infile) { cerr<<"openerror"< exit (1); } for(i=0;i { cout<<""; infile>>num[i]; cout< infile>>name[i]; cout< infile>>sex[i]; cout< infile>>age[i]; cout< infile>>birthday[i]; cout< infile>>address[i]; cout< infile>>tel[i]; cout< infile>>Email[i]; cout< } infile.close(); ofstreamoutfile("f1.txt",ios: : out); if(! outfile) { cerr<<"openerror"< exit (1); } cout<<"您想修改第几个学生信息? "< cin>>k; k=k-1; cout<<"请输入新的数据: "< cout<<"请输入姓名: "< cin>>name[k]; cout<<"请输入性别: "< cin>>sex[k]; cout<<"请输入年龄: "< cin>>age[k]; cout<<"请输入出生日期: "< cin>>birthday[k]; cout<<"请输入家庭住址: "< cin>>address[k]; cout<<"请输入电话: "< cin>>tel[k]; cout<<"请输入电子邮箱: "< cin>>Email[k]; for(i=0;i { outfile< outfile< outfile< outfile< outfile< outfile< outfile< outfile< } outfile.close(); cout<<"已修改成功! "< } ///查询文件 voidstudent: : search() { inti,n,w=0,num[M],a[M];charch; stringsearchname,name[M],sex[M],age[M],birthday[M],address[M],tel[M],Email[M],b[M][7]; cout<<"a.按学号查找b.按姓名查找"< ifstreaminfile("f1.txt",ios: : in); if(! infile) { cerr<<"openerror"< exit (1); } for(i=0;i { infile>>num[i];a[i]=num[i]; infile>>name[i];b[i][0]=name[i]; infile>>sex[i];b[i][1]=sex[i]; infile>>age[i];b[i][2]=age[i]; infile>>birthday[i];b[i][3]=age[i]; infile>>address[i];b[i][4]=age[i]; infile>>tel[i];b[i][5]=address[i]; infile>>Email[i];b[i][6]=age[i]; } cout<<"请输入a或者b! "< cin>>ch; if(ch=='a') { cout<<"请输入学号! "< cin>>n; for(i=0;i if(a[i]==n) { w=1; cout<<"学号姓名性别年龄出生日期家庭住址电话邮箱"< cout<<""; cout< cout< cout< cout< cout< cout< cout< cout< } if(w==0) cout<<"无此人信息! "< } elseif(ch=='b') { cout<<"请输入姓名! "< cin>>searchname; for(i=0;i if(name[i]==searchname) { w=1; cout<<"学号姓名性别年龄出生日期家庭住址电话邮箱"< cout< cout< cout< cout< cout< cout< cout< cout< } if(w==0) cout<<"无此人信息! "< } elsecout<<"没有此选项! "< } ///显示文件 voidstudent: : display() { intk,num; stringname,sex,age,birthday,address,tel,Email; ifstreaminfile("f1.txt",ios: : in); if(! infile) { cerr<<"0openerror"< exit (1); } cout<<"学号姓名性别年龄出生日期家庭住址电话邮箱"< for(k=0;k { cout<<""; infile>>num; cout< infile>>name; cout< infile>>sex; cout< infile>>age; cout< infile>>birthday; cout<