同学录源代码.docx

上传人:b****9 文档编号:26344633 上传时间:2023-06-17 格式:DOCX 页数:16 大小:16.65KB
下载 相关 举报
同学录源代码.docx_第1页
第1页 / 共16页
同学录源代码.docx_第2页
第2页 / 共16页
同学录源代码.docx_第3页
第3页 / 共16页
同学录源代码.docx_第4页
第4页 / 共16页
同学录源代码.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

同学录源代码.docx

《同学录源代码.docx》由会员分享,可在线阅读,更多相关《同学录源代码.docx(16页珍藏版)》请在冰豆网上搜索。

同学录源代码.docx

同学录源代码

Landh.h

>-----------------------------------------------------------------------------------------------------------------<

classstudent{

public:

charName[20];

intNum;

charSex[2];

intAge;

charTele[20];

charEmail[30];

student();

student(char[],int,char[],int,char[],char[]);

voidadd();

voidset(char[],int,char[],int,char[],char[]);

};

voidreset(int,int);

voiddele(int,int);

boolpass();

voidshowall();

voidfound(char[],int);

voidexit();

voidfanh();

voidsetpass();

Hanshu.cpp

>---------------------------------------------------------------------------------------------------------------<

#include

#include

#include

#include"landh.h"

usingnamespacestd;

//学生函数

student:

:

student(){

Name[0]='\0';

Num='\0';

Sex[0]='\0';

Age='\0';

Tele[0]='\0';

Email[0]='\0';

}

student:

:

student(charname[],intno,charsex[],intage,chartele[],charemail[]){

strcpy(Name,name);

Num=num;

strcpy(Sex,sex);

Age=age;

strcpy(Tele,tele);

strcpy(Email,email);

}

//添加函数

voidstudent:

:

add(){

ofstreamout("student.txt",ios_base:

:

in|ios_base:

:

app);

out<

out.close();

}

voidstudent:

:

set(charname[],intno,charsex[],intage,chartele[],charemail[]){

strcpy(Name,name);

No=no;

strcpy(Sex,sex);

Age=age;

strcpy(Tele,tele);

strcpy(Email,email);

}

//显示函数

voidshowall(){

charname[20];

intnum;

charsex[2];

intage;

chartele[20];

charemail[30];

cout<<"姓名"<<'\t'<<"编号"<<'\t'<<"性别"<<'\t'<<"年龄"<<'\t'<<"电话"<<"\t"<<"邮箱"<

ifstreamifile;

ifile.open("student.txt");

while

(1){

ifile>>name>>no>>sex>>age>>tele>>email;

if(ifile.eof()!

=0)break;

cout<

}

ifile.close();

}

//查询函数

voidfound(charname[],intcount){

inti,c=0;//c用于判断是否存在

studenta[1000];

ifstreamin("student.txt");

for(i=0;i<=count;i++)

{

in>>a[i].Name>>a[i].No>>a[i].Sex>>a[i].Age>>a[i].Tele>>a[i].Email;

}

in.close();

for(i=0;i<=count;i++)

{

if(strcmp(a[i].Name,name)==0)

{

cout<<"姓名"<<'\t'<<"编号"<<'\t'<<"性别"<<'\t'<<"年龄"<<'\t'<<"电话"<<"\t"<<"邮箱"<

cout<

c++;

}

}

if(c==0)

{

cout<<"查无此人"<

}

}

//删除函数

voiddele(intnum,intcount){

inti,t,c=0,q;//q用于判断是否删除

studenta[1000];

ifstreamin("student.txt");

for(i=0;i

{

in>>a[i].Name>>a[i].No>>a[i].Sex>>a[i].Age>>a[i].Tele>>a[i].Email;

}

in.close();

for(i=0;i

{

if(a[i].Num==num)

{

c++;

cout<

cout<<"姓名"<<'\t'<<"编号"<<'\t'<<"性别"<<'\t'<<"年龄"<<'\t'<<"电话"<<"\t"<<"邮箱"<

cout<

cout<<"1.确认。

2.取消。

";

cin>>q;

if(q==1)

{

ofstreamout("student.txt");

for(t=0;t

{

out<

}

for(t=i+1;t

{

out<

}

out.close();

cout<<"已删除。

"<

count--;

ofstreamoutc("count.dat",ios_base:

:

in|ios_base:

:

out|ios_base:

:

trunc);

outc<

outc.close();

}

}

}

if(c==0)

{

cout<<"无此人"<

}

}

//修改函数

voidreset(intno,intcount){

inti,t,c=0;

studenta[1000];

charname[20];

charsex[20];

intage;

chartele[20];

charemail[30];

ifstreamin("student.txt");

for(i=0;i

{

in>>a[i].Name>>a[i].No>>a[i].Sex>>a[i].Age>>a[i].Tele>>a[i].Email;

}

in.close();

for(i=0;i

if(a[i].Num==num)

{

c=1;

while

(1){

cout<<"请选择修改项:

1.姓名。

"<

cout<<"2.性别。

"<

cout<<"3.年龄。

"<

cout<<"4.电话。

"<

cout<<"5.邮箱。

"<

cout<<"6.结束。

"<

cin>>t;

if(t==1)

{

cout<<"姓名:

"<

";

cin>>name;

strcpy(a[i].Name,name);

}

if(t==2)

{

cout<<"性别:

"<

";

cin>>sex;

strcpy(a[i].Sex,sex);

}

if(t==3)

{

cout<<"年龄:

"<

";

cin>>age;

a[i].Age=age;

}

if(t==4)

{

cout<<"电话:

"<

";

cin>>tele;

strcpy(a[i].Tele,tele);

}

if(t==5)

{

cout<<"邮箱:

"<

";

cin>>email;

strcpy(a[i].Email,email);

}

if(t==6)break;

}

cout<<"已修改。

"<

cout<<"姓名"<<'\t'<<"编号"<<'\t'<<"性别"<<'\t'<<"年龄"<<'\t'<<"电话"<<"\t"<<"邮箱"<

cout<

}

}

if(c==0){

cout<<"查无此人"<

}

ofstreamout("student.txt");

for(t=0;t

out<

}

out.close();

}

//退出函数

voidexit(){

cout<<"按任意键退出程序!

"<

exit(0);

}

//密码函数

boolpass(){

charpw[20],ps[20],pw2[20];

boolt1=1,t2=1;

ifstreamin("pass.dat",ios_base:

:

in);

in>>ps;

in.close();

cout<<"请输入密码:

";

cin>>pw;

for(inti=0;i<20;i++)

{

if(ps[i]!

=pw[i])

{

t1=0;break;

}

}

if(t1==1)return1;

else{

cout<<"密码错误,请重新输入:

";

cin>>pw2;

for(inti=0;i<20;i++){

if(ps[i]!

=pw2[i]){

t2=0;break;

}

}

if(t2==1){return1;}

else{return0;}

}

}

//密码修改函数

voidsetpass(){

charnewps[20];

cout<<"请输入新密码(限20个字符):

";

cin>>newps;

ofstreamout("pass.dat",ios_base:

:

in|ios_base:

:

out|ios_base:

:

trunc);

out<

out.close();

}

Main.cpp

>------------------------------------------------------------------------------------------------------------------<

#include

#include

#include

#include"landh.h"

usingnamespacestd;

voidmain(){

charname[20];

intnum,xz,count,number;

charsex[2];

intage;

chartele[20];

charemail[30];

cout<

cout<<"------------------------------------------"<

cout<<"**"<

cout<<"XXX的同学录"<

cout<<"**"<

cout<<"------------------------------------------"<

boolpd;

pd=pass();

if(pd==0){exit();}

system("pause");

system("cls");

ifstreamin("number.dat",ios_base:

:

in);

in>>number;

in.close();

ifstreaminc("count.dat",ios_base:

:

in);

inc>>count;

inc.close();

while

(1){

cout<<"请选择操作:

1.添加。

"<

cout<<"2.修改。

"<

cout<<"3.查找。

"<

cout<<"4.删除。

"<

cout<<"5.显示。

"<

cout<<"6.修改密码。

"<

cout<<"7.退出。

"<

cout<<"-------------------------------------------------------------------------------"<

cin>>xz;

if(xz==1){

studenta;

count++;

ofstreamoutc("count.dat",ios_base:

:

in|ios_base:

:

out|ios_base:

:

trunc);

outc<

outc.close();

number++;

ofstreamout("number.dat",ios_base:

:

in|ios_base:

:

out|ios_base:

:

trunc);

out<

out.close();

cout<<"-------------------------------------------------------------------------------"<

cout<

cout<<"请输入姓名:

";cin>>name;

cout<<"请输入性别:

";cin>>sex;

cout<<"请输入年龄:

";cin>>age;

cout<<"请输入电话:

";cin>>tele;

cout<<"请输入邮件:

";cin>>email;

a.set(name,number,sex,age,tele,email);

a.add();

cout<<"已添加。

"<

cout<<"姓名"<<'\t'<<"编号"<<'\t'<<"性别"<<'\t'<<"年龄"<<'\t'<<"电话"<<"\t"<<"邮箱"<

cout<

cout<<"-------------------------------------------------------------------------------"<

cout<

system("pause");

system("cls");

}

if(xz==2){

cout<<"-------------------------------------------------------------------------------"<

cout<

cout<<"请输入要修改的编号:

";

cin>>no;

reset(no,count);

cout<<"-------------------------------------------------------------------------------"<

cout<

system("pause");

system("cls");

}

if(xz==3){

cout<<"-------------------------------------------------------------------------------"<

cout<

cout<<"请输入要查找的姓名:

";cin>>name;

found(name,count);

cout<<"-------------------------------------------------------------------------------"<

cout<

system("pause");

system("cls");

}

if(xz==4){

cout<<"-------------------------------------------------------------------------------"<

cout<

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

";cin>>no;

dele(no,count);

cout<<"-------------------------------------------------------------------------------"<

cout<

system("pause");

system("cls");

}

if(xz==5){

showall();

cout<<"-------------------------------------------------------------------------------"<

}

if(xz==6){

cout<<"-------------------------------------------------------------------------------"<

setpass();

cout<<"已修改。

"<

system("pause");

system("cls");

}

if(xz==7){

exit();

}

}

}

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

当前位置:首页 > 高等教育 > 其它

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

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