《同学录源代码》由会员分享,可在线阅读,更多相关《同学录源代码(10页珍藏版)》请在金锄头文库上搜索。
1、Landh.h-#include#include#include#include landh.husing namespace std;/学生函数student:student()Name0=0; Num=0;Sex0=0; Age=0;Tele0=0; Email0=0;student:student(char name,int no,char sex,int age,char tele,char email)strcpy(Name,name); Num=num;strcpy(Sex,sex); Age=age;strcpy(Tele,tele); strcpy(Email,email);/
2、添加函数void student:add()ofstream out(student.txt,ios_base:in|ios_base:app);out NametNotSextAgetTeletEmailendl;out.close();void student:set(char name,int no,char sex,int age,char tele,char email)strcpy(Name,name); No=no;strcpy(Sex,sex); Age=age;strcpy(Tele,tele); strcpy(Email,email);/显示函数void showall()
3、char name20;int num;char sex2;int age;char tele20;char email30;cout姓名t编号t性别t年龄t电话 t邮箱namenosexageteleemail;if(ifile.eof()!=0) break;coutnametnotsextagetteletemailendl; ifile.close();/查询函数void found(char name,int count)int i,c=0; /c用于判断是否存在student a1000; ifstream in(student.txt);for(i=0;iai.Nameai.No
4、ai.Sexai.Ageai.Teleai.Email; in.close();for (i=0;i=count;i+) if (strcmp(ai.Name,name)=0) cout姓名t编号t性别t年龄t电话 t邮箱endl; coutai.Nametai.Notai.Sextai.Agetai.Teletai.Emailendl; c+; if(c=0) cout查无此人endl; /删除函数void dele(int num,int count)int i,t,c=0,q; /q用于判断是否删除student a1000; ifstream in(student.txt);for(i
5、=0;iai.Nameai.Noai.Sexai.Ageai.Teleai.Email; in.close();for (i=0;icount;i+) if (ai.Num=num)c+;coutendl;cout姓名t编号t性别t年龄t电话 t邮箱endl; coutai.Nametai.Notai.Sextai.Agetai.Teletai.Emailendl;coutq;if(q=1)ofstream out(student.txt); for(t=0;ti;t+)out at.Nametat.Notat.Sextat.Agetat.Teletat.Emailendl; for(t=i+
6、1;tcount;t+) out at.Nametat.Notat.Sextat.Agetat.Teletat.Emailendl; out.close(); cout已删除。endl;count-; ofstream outc(count.dat,ios_base:in|ios_base:out|ios_base:trunc); outccount; outc.close(); if(c=0)cout无此人endl;/修改函数void reset(int no,int count)int i,t,c=0;student a1000;char name20;char sex20;int age
7、;char tele20;char email30; ifstream in(student.txt);for(i=0;iai.Nameai.Noai.Sexai.Ageai.Teleai.Email; in.close();for (i=0;icount;i+)if (ai.Num=num)c=1;while(1)cout请选择修改项:1.姓名。endl; cout 2.性别。endl; cout 3.年龄。endl; cout 4.电话。endl; cout 5.邮箱。endl;cout 6.结束。t; if(t=1)cout姓名:ai.Nametname; strcpy(ai.Name,name); if(t=2) cout性别:ai.Sextsex; strcpy(ai.Sex,sex); if(t=3) cout年龄:ai.Agetage; ai.Age=age; if(t=4) cout电话:ai.Telettele; strcpy(ai.Tele,tele); if(t=5) c