用C++编写学生通讯录管理系统

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

# include & ltstring.h & gt

#定义格式“%s\t\t%s\t\t%s\t%d\t%s\n”

int count = 0;

结构地址

{

char Name[21];

int Age

char Sex[6];

char class num[11];

char phon num[12];

};

int enter face();

int Add(通讯录[]);

int Modify(通讯录[]);

int Delent(通讯录[]);

int Insert(通讯录[]);

int Find(通讯录[]);

int Show(通讯录[]);

int FindName(通讯录[]);

int FindClassNum(通讯簿[]);

int DelName(通讯录[]);

int DelClassNum(通讯簿[]);

int FindPhonNum(通讯录[]);

int Readtxt(通讯录[]);

int Writetxt(通讯录[]);

int Search(通讯录[],char str1[],int n);

int FSearch(通讯录[],char str2[],int n);

int Taxis(通讯录[]);

int Exit();

////////////////////////////////////////////////////////////////////

void main()

{

通讯录[100];

int选择;

char or = ' m

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ n ");

printf(" \ \ \ \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" n ");

printf(" \ n ");

printf(!!!欢迎使用班级通讯录系统!!!\ n ");

printf(" \ n ");

printf(!!!按任意键进入系统!!!\ n ");

printf(" \ n ");

printf(!!!管理员:* * * * *!!!\ n ");

printf(" \ n ");

printf("//////////////////////////////////////////////////\ n ");

系统(“暂停”);

系统(“cls”);

Readtxt(书);

while(or=='m ')

{

choice = enter face();

开关(选择)

{

案例1:添加(书);

打破;

案例二:修改(书);

打破;

案例三:德伦特(书);

打破;

案例四:插页(书);

打破;

案例五:找(书);

打破;

案例六:秀(书);

打破;

案例7:Exit();

打破;

默认值:printf(!idspninfopath)。!!输入错误!!!\ n ");

exit();

打破;

}

}

}

int Enterface()

{

int choice = 0;

printf(" * * * * * * * * * * * * * * * * * \ n ");

Printf(" 1。add \ n ");

Printf(" 2。修改\ n ");

Printf(" 3。删除\ n ");

Printf(" 4。insert \ n ");

Printf(" 5。查找\ n ");

Printf(" 6。display \ n ");

Printf(" 7。退出\ n ");

printf(" * * * * * * * * * * * * * * * * * \ n ");

Printf("请输入您的选择:");

scanf("%d ",& amp选择);

回归选择;

}

int Add(通讯录[])

{

char or = ' Y

while('Y'==or)

{

Printf("请输入您的姓名:");

scanf("%s ",& amp书[数]。姓名);

flag1:

Printf("请输入电话号码:");

scanf("%s ",& amp书[数]。phon num);

for(int I = 0;我& lt数数;i++)

{

if(strcmp(book[count])。PhonNum,书[i]。PhonNum)==0)

{

printf(!!!该号码已经存在!!!\ n ");

goto flag 1;

}

}

标志2:

Printf("请输入你的学号:");

scanf("%s ",& amp书[数]。class num);

for(I = 0;我& lt数数;i++)

{

if(strcmp(book[count])。ClassNum,book[i]。ClassNum)==0)

{

printf(!!!学号已经存在!!!\ n ");

转到flag2

}

}

Printf("请输入年龄:");

scanf("%d ",& amp书[数]。年龄);

Printf("请输入性别:");

scanf("%s ",& amp书[数]。性);

getchar();

count++;

Printf("是否继续添加(' y '添加,其他键返回主界面):");

scanf("%c ",& amp或者);

if('Y '!=或)

{

系统(“cls”);

打破;

}

}

出租车(书);

Writetxt(书);

//printf(" sdfsdfsdf \ n ");

返回0;

}

int修改(地址簿[])

{

char str[11];

int flag = 0;

int ksd = 0;

Printf("去年输入的学号:");

scanf("%s ",& ampstr);

for(int I = 0;我& lt数数;i++)

{

if(strcmp(str,book[i])。ClassNum)==0)

{

如果(ksd==0)

{

printf(" Name \ t phone \ t \ t \ t学生ID \ tSex \ tAge \ n ");

ksd = 1;

}

printf("%8s\t%8s\t%s\t%s\t%d\n ",book[i]。名,书[我]。峰数,

书[我]。ClassNum,book[i]。性,书[我]。年龄);

//str[flag _ num++]= I;

flag = 1;

//I-;

打破;

}

}

如果(标志==0)

{

printf(!!!没有这样的记录!!!\ n ");

返回0;

}

Printf("请输入您的姓名:");

scanf("%s ",& amp书[我]。姓名);

标志0:

Printf("请输入电话号码:");

scanf("%s ",& amp书[我]。phon num);

for(int j = 0;j & lt数数;j++)

{

如果(j==i)

继续;

if(strcmp(书[i])。PhonNum,书[j]。PhonNum)==0)

{

printf(!!!该号码已经存在!!!\ n ");

转到flag0

}

}

标志3:

Printf("请输入你的学号:");

scanf("%s ",& amp书[我]。class num);

for(j = 0;j & lt数数;j++)

{

如果(j==i)

继续;

if(strcmp(书[i])。ClassNum,book[j]。ClassNum)==0)

{

printf(!!!学号已经存在!!!\ n ");

转到flag3

}

}

Printf("请输入年龄:");

scanf("%d ",& amp书[我]。年龄);

Printf("请输入性别:");

scanf("%s ",& amp书[我]。性);

getchar();

Printf("修改!\ n ");

Writetxt(书);

系统(“暂停”);

//printf(" modify \ n ");

返回0;

}

int Delent(地址簿[])

{

//printf(" delent \ n ");

int choice = 0;

printf(" = = = = = = = = = = = = = = = = = \ n ");

Printf(" 1。按名称删除\ n ");

Printf(" 2。按学号删除\ n ");

printf(" = = = = = = = = = = = = = = = = = \ n ");

scanf("%d ",& amp选择);

开关(选择)

{

案例1: DelName(书);

打破;

案例二:DelClassNum(书);

打破;

默认值:

打破;

}

返回0;

}

int Insert(通讯簿[])

{

添加(书);

//printf(" insert \ n ");

返回0;

}

int Find(通讯簿[])

{

int choice = 0;

printf(" = = = = = = = = = = = = = = = = = \ n ");

Printf(" 1。按姓名搜索\ n ");

Printf(" 2。按学号搜索\ n ");

Printf(" 3。电话查找\ n ");

printf(" = = = = = = = = = = = = = = = = = \ n ");

scanf("%d ",& amp选择);

开关(选择)

{

案例1:find name(book);

打破;

案例二:FindClassNum(书);

打破;

案例三:FindPhonNum(书);

打破;

默认值:

打破;

}

//printf(" find \ n ");

返回0;

}

int FindName(地址簿[])

{

char aname[30];

Printf("请输入要查找的名称:");

scanf("%s ",& ampaname);

FSearch(book,aname,3);

返回0;

}

int FindClassNum(通讯簿[])

{

char anum[20];

Printf("请输入你要找的学号:");

scanf("%s ",& ampanum);

FSearch(book,anum,2);

返回0;

}

int FindPhonNum(地址簿[])

{

char aphonnum〔20〕;

Printf("请输入你要找的学号:");

scanf("%s ",& amp失音);

FSearch(book,aphonnum,1);

返回0;

}

int Show(通讯簿[])

{

int或= 0;

if(count==0)

{

printf(!!!没有记录!!!\ n ");

系统(“暂停”);

系统(“cls”);

}

其他

{

printf(" Name \ t phone \ t \ t \ t学生ID \ tSex \ tAge \ n ");

for(int I = 0;我& lt数数;i++)

printf("%8s\t%8s\t%s\t%s\t%d\n ",book[i]。名,书[我]。峰数,

书[我]。ClassNum,book[i]。性,书[我]。年龄);

系统(“暂停”);

}

Printf("排序?\n-=1。排序=-= 2。返回主界面=-\ n ");

scanf("%d ",& amp或者);

if(1 = =或)

出租车(书);

返回0;

}

int DelName(通讯簿[])

{

char aname[20];

Printf("请输入要删除的名称:");

scanf("%s ",& ampaname);

搜索(book,aname,2);

返回0;

}

int DelClassNum(通讯簿[])

{

char anum[20];

Printf("请输入要删除的学号:");

scanf("%s ",& ampanum);

搜索(book,anum,1);

返回0;

}

int Readtxt(地址簿[])

{

FILE * FP 1;

FP 1 = fopen(" photo numbers . txt "," r ");

if(fp1 == NULL)

{

printf("错!\ n ");

系统(“暂停”);

}

而(!feof(fp1))

{

如果(!fscanf(fp1," %s\t\t%s\t\t%s\t%d\t%s ",book[count]。名,书[数]。峰数,

书[数]。ClassNum & amp;书[数]。年龄,书[数]。性))

Printf("读取错误!");

count++;

}

count-;

fclose(FP 1);

返回0;

}

int Writetxt(通讯簿[])

{

FILE * fp

fp=fopen("photonumbers.txt "," w ");

for(int I = 0;我& lt数数;i++)

{

fprintf(fp,FORMAT,book[i])。名,书[我]。峰数,

书[我]。ClassNum,book[i]。年龄,书[我]。性);

}

fclose(FP);

返回0;

}

int Search(地址簿[],char str1[],int n)

{

int flag = 0;

int str[5];

int flag _ num = 0;

int j;

int gf

int ksd = 0;

for(int I = 0;我& lt数数;i++)

{

如果(n==1)

{

if(strcmp(str1,book[i])。ClassNum)==0)

flag = 2;

}

else if(n==2)

{

if(strcmp(str1,book[i])。Name)==0)

flag = 2;

}

if(flag==2)

{

如果(ksd==0)

{

printf(" Name \ t phone \ t \ t \ t学生ID \ tSex \ tAge \ n ");

ksd = 1;

}

printf("%8s\t%8s\t%s\t%s\t%d\n ",book[i]。名,书[我]。峰数,

书[我]。ClassNum,book[i]。性,书[我]。年龄);

str[flag _ num++]= I;

flag = 1;

}

}

如果(标志==0)

{

printf(!!!没有记录!!!\ n ");

系统(“暂停”);

系统(“cls”);

}

if(flag==1)

{

Printf("-=1。确认删除=-\t-=2。cancel =-\ n ");

scanf("%d ",& ampj);

if(1==j)

{

gf = 1;

for(int m = str[0];m & lt计数-标志_数量;m++)

{

for(int j = gf-1;j & ltflag _编号;j++)

{

if((m+gf)==str[j])

gf++;

}

strcpy(书[m].名字,书[m+gf]。姓名);

书[m]。年龄=书[m+gf]。年龄;

strcpy(书[m].ClassNum,book[m+gf]。class num);

strcpy(书[m].PhonNum,book[m+gf]。phon num);

strcpy(书[m].性,书[m+gf]。性);

}

count =计数-标志_数量;

Writetxt(书);

}

else if(2==j)

{

printf(!!!操作已取消!!!\ n ");

}

系统(“暂停”);

}

返回0;

}

int FSearch(地址簿[],字符str2[],int n)

{

int flag = 0;

int ksd = 0;

for(int I = 0;我& lt数数;i++)

{

如果(n==1)

{

if(strcmp(str2,book[i])。PhonNum)==0)

flag = 2;

}

else if(3==n)

{

if(strcmp(str2,book[i])。Name)==0)

flag = 2;

}

else if(2==n)

{

if(strcmp(str2,book[i])。ClassNum)==0)

flag = 2;

}

if(flag==2)

{

if(0==ksd)

{

printf(" Name \ t phone \ t \ t \ t学生ID \ tSex \ tAge \ n ");

ksd = 1;

}

printf("%8s\t%8s\t%s\t%s\t%d\n ",book[i]。名,书[我]。峰数,

书[我]。ClassNum,book[i]。性,书[我]。年龄);

flag = 1;

}

}

if(1==flag)

系统(“暂停”);

else if(flag==0)

{

printf(!!!没有这样的记录!!!\ n ");

系统(“暂停”);

系统(“cls”);

}

返回0;

}

int Taxis(通讯录[])

{

/* for(int I = 0;我& lt数数;i++)

{

for(int j = 0;j & ltcount-1-I;j++)

{

if(strcmp(书[j].ClassNum,book[j+1]。ClassNum)>0)

{

地址bk;

strcpy(黑色。名,书[j]。姓名);

bk。年龄=书[j]。年龄;

strcpy(黑色。ClassNum,book[j]。class num);

strcpy(黑色。PhonNum,书[j]。phon num);

strcpy(黑色。性,书[j]。性);

strcpy(书[j].名字,书[j+1]。姓名);

书[j]。年龄=书[j+1]。年龄;

strcpy(书[j].ClassNum,book[j+1]。class num);

strcpy(书[j].PhonNum,book[j+1]。phon num);

strcpy(书[j].性,书[j+1]。性);

strcpy(书[j+1]。姓名,bk。姓名);

书[j+1]。年龄=bk。年龄;

strcpy(书[j+1]。ClassNum浅滩。class num);

strcpy(书[j+1]。丰纳姆浅滩。phon num);

strcpy(书[j+1]。性,bk。性);

}

}

}

printf(!!!操作成功!!!\ n ");

系统(“暂停”);

系统(“cls”);

Writetxt(书);*/

返回0;

}

int Exit()

{

退出(1);

返回0;

}

这是我之前写的一个程序。有一份书面文件,里面有一些虚拟的联系方式。如果有必要,我会把整个项目发给你,并留下电子邮件...O(∩_∩)O~