100分,用C++编写一个学生通讯录管理系统,之前问错板块了。
问题在这里,附加了100分。不过问错分类了。http://zhidao.baidu.com/question/209604394.html...
问题在这里,附加了100分。不过问错分类了。http://zhidao.baidu.com/question/209604394.html
展开
展开全部
刚好最近写了个。你看看吧.
# include<stdio.h>
# include<malloc.h>
#include<stdlib.h>
# define NULL 0
# define LEN sizeof(struct student)
void menu();
struct student
{
int num;//学号
char name[10]; //姓名
char phone[20]; //电话
char address[20];
struct student *next; //地址
}*head;
int n=0; //统计链表中的人数
//初始化链表头文件
struct student *create(void)
{
struct student *p1,*p2;
int num;
p1=p2=(struct student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元
printf("请输入信息,在学号处键以 0 结束输入!\n");
printf(" 学号:");
scanf("%d",&num);;
head=NULL; //给指针head赋初值
while (num!=0)
{ //调用字符比较函数strcmp()用来判断是否继续输入
p1=(student *)malloc(LEN); //调用malloc()函数用来开辟一个新的存储单元
if(p1==NULL) printf("内存分配错误!\n");
p1->num=num;
printf("姓名:");
scanf("%s",p1->name);
printf("电话:");
scanf("%s",p1->phone);
printf("地址:");
scanf("%s",p1->address);
if(n==0)head=p1; //如果是输入第一组客户信息就将指针p1赋给指针head
else p2->next=p1; //否则将p1赋给p2所指结构体的next指针
p2=p1; //将指针p1赋给指针p2
n++;
printf(" 学号:");
scanf("%d",&num);;
}//end of while
p2->next=NULL; //将p2所指结构体的next指针重新赋空值
return head;
}
//添加成员
void add()
{
struct student *p1,*p2,*p3;
p1=p2=p3=(struct student*)malloc(sizeof (LEN));
if(p1==NULL)
{ printf("内存分配错误\n"); return; }
printf("请输入学生相关信息:\n");
printf(" 学号:\n");
scanf("%d",&((*p1).num));
printf("姓名:\n");
scanf("%s",(*p1).name);
printf("电话:\n");
scanf("%s",(*p1).phone);
printf("地址:\n");
scanf("%s",(*p1).address);
n=n+1;
p2=head;
if(head==NULL) //若没调用次函数以前的头指针head为空
{
head=p1;p1->next=NULL;
} //则将p1赋给头指针head并将p1所指结构体成员指针next赋空值
else
{
while((p1->num>p2->num)&&(p2->next!=NULL))
{
p3=p2; //p3指向原p2指向的结点
p2=p2->next;
} //p2后移一个结点
if(p1->num<=p2->num)
{
if(head==p2)
{
p1->next=head;
head=p1;
} //插入到第一个结点之前
else
{
p3->next=p1;
p1->next=p2;
} //插入到p3所指结点之后
}
else
{
p2->next=p1;
p1->next=NULL;
} //插入到尾结点之后
}
n++;
printf("你输入的信息已经成功插入");
}
//查找学生信息
void select(struct student *head)
{
struct student *p1;
int num0;
printf("请输入待查找学生的学号\n");
scanf("%d",&num0);
if(head==NULL)
{ printf("学生通讯录中暂无学生信息\n");menu();}
else
{
p1=head;
while((num0!=p1->num)&&(p1->next!=NULL))
p1=p1->next;
if(num0==p1->num)
{
printf("此学生相关信息如下:\n");
printf("学号:%d,姓名:%s,电话:%s,地址:%s\n",p1->num,p1->name,p1->phone,p1->address);
}
else
printf("学生通讯录中没有您要找的信息!\n");
}//end of if
}
//删除学生信息
void del(struct student *head)
{
struct student *p1,*p2;
int num;
printf("请输入要删除学生的学号\n");
scanf("%d",&num);
if(head==NULL)
printf("学生通讯录中暂无数据\n");
else
{
p1=head;
while((num!=p1->num)&&(p1->next!=NULL))
{p2=p1;p1=p1->next;}
if(num==p1->num)
{
if(p1==head) head=p1->next;
else p2->next=p1->next;
printf("删除学生信息如下:\n");
printf("学号:%d,姓名:%s,电话:%s,地址:%s\n",p1->num,p1->name,p1->phone,p1->address);
n=n-1;
}
// else printf("通讯录中不存在学号为%d的学生信息\n",num);
}//end of if
}
//显示学生信息
void display(struct student *head)
{
struct student *p;
if(head==NULL)
printf("这是一个空表,请先输入信息!\n");
else
{
printf("\n现有%d名人员信息\n",n);
p=head;
do{
printf("学号:%d,姓名:%s,电话:%s,地址:%s\n",p->num,p->name,p->phone,p->address);
p=p->next;
}while(p!=NULL);
}//the end of else
}
/*退出程序
void Exit(int i)
{
exit(1);
}*/
void menu()
{
int choice;
do{
printf("\t\t****************************************************\n");
printf("\t\t\t 学生通讯录 \t\t\n");
printf("\t\t\t请根据数字选择相应的操作(1~6) \t\t\n");
printf("\t\t\t1.输入学生信息(学号 姓名 电话 地址)\t\t\n");
printf("\t\t\t2.增加学生信息(学号 姓名 电话 地址)\t\t\n");
printf("\t\t\t3.查找学生信息(输入学生学号) \t\t\n");
printf("\t\t\t4.删除学生信息(输入学生学号) \t\t\n");
printf("\t\t\t5.显示学生信息(学号 姓名 电话 地址)\t\t\n");
printf("\t\t\t6.退出通讯录 \t\t\n");
printf("\t\t****************************************************\n");
scanf("%d",&choice);
while(choice<1||choice>7)
{
printf(" 对不起您的输入错误!请输入您的选择(1--6):\t");
scanf("%d",&choice);
}
switch(choice)
{
case 1: head=create();break;
case 2: add();break;
case 3: select(head);break;
case 4: del(head);break;
case 5: display(head);break;
case 6: break;
default:printf("输入的数据有误,请重新输入\n"); break;
}
}
while(choice!=6);
}
//主函数
void main()
{
menu();
}
# include<stdio.h>
# include<malloc.h>
#include<stdlib.h>
# define NULL 0
# define LEN sizeof(struct student)
void menu();
struct student
{
int num;//学号
char name[10]; //姓名
char phone[20]; //电话
char address[20];
struct student *next; //地址
}*head;
int n=0; //统计链表中的人数
//初始化链表头文件
struct student *create(void)
{
struct student *p1,*p2;
int num;
p1=p2=(struct student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元
printf("请输入信息,在学号处键以 0 结束输入!\n");
printf(" 学号:");
scanf("%d",&num);;
head=NULL; //给指针head赋初值
while (num!=0)
{ //调用字符比较函数strcmp()用来判断是否继续输入
p1=(student *)malloc(LEN); //调用malloc()函数用来开辟一个新的存储单元
if(p1==NULL) printf("内存分配错误!\n");
p1->num=num;
printf("姓名:");
scanf("%s",p1->name);
printf("电话:");
scanf("%s",p1->phone);
printf("地址:");
scanf("%s",p1->address);
if(n==0)head=p1; //如果是输入第一组客户信息就将指针p1赋给指针head
else p2->next=p1; //否则将p1赋给p2所指结构体的next指针
p2=p1; //将指针p1赋给指针p2
n++;
printf(" 学号:");
scanf("%d",&num);;
}//end of while
p2->next=NULL; //将p2所指结构体的next指针重新赋空值
return head;
}
//添加成员
void add()
{
struct student *p1,*p2,*p3;
p1=p2=p3=(struct student*)malloc(sizeof (LEN));
if(p1==NULL)
{ printf("内存分配错误\n"); return; }
printf("请输入学生相关信息:\n");
printf(" 学号:\n");
scanf("%d",&((*p1).num));
printf("姓名:\n");
scanf("%s",(*p1).name);
printf("电话:\n");
scanf("%s",(*p1).phone);
printf("地址:\n");
scanf("%s",(*p1).address);
n=n+1;
p2=head;
if(head==NULL) //若没调用次函数以前的头指针head为空
{
head=p1;p1->next=NULL;
} //则将p1赋给头指针head并将p1所指结构体成员指针next赋空值
else
{
while((p1->num>p2->num)&&(p2->next!=NULL))
{
p3=p2; //p3指向原p2指向的结点
p2=p2->next;
} //p2后移一个结点
if(p1->num<=p2->num)
{
if(head==p2)
{
p1->next=head;
head=p1;
} //插入到第一个结点之前
else
{
p3->next=p1;
p1->next=p2;
} //插入到p3所指结点之后
}
else
{
p2->next=p1;
p1->next=NULL;
} //插入到尾结点之后
}
n++;
printf("你输入的信息已经成功插入");
}
//查找学生信息
void select(struct student *head)
{
struct student *p1;
int num0;
printf("请输入待查找学生的学号\n");
scanf("%d",&num0);
if(head==NULL)
{ printf("学生通讯录中暂无学生信息\n");menu();}
else
{
p1=head;
while((num0!=p1->num)&&(p1->next!=NULL))
p1=p1->next;
if(num0==p1->num)
{
printf("此学生相关信息如下:\n");
printf("学号:%d,姓名:%s,电话:%s,地址:%s\n",p1->num,p1->name,p1->phone,p1->address);
}
else
printf("学生通讯录中没有您要找的信息!\n");
}//end of if
}
//删除学生信息
void del(struct student *head)
{
struct student *p1,*p2;
int num;
printf("请输入要删除学生的学号\n");
scanf("%d",&num);
if(head==NULL)
printf("学生通讯录中暂无数据\n");
else
{
p1=head;
while((num!=p1->num)&&(p1->next!=NULL))
{p2=p1;p1=p1->next;}
if(num==p1->num)
{
if(p1==head) head=p1->next;
else p2->next=p1->next;
printf("删除学生信息如下:\n");
printf("学号:%d,姓名:%s,电话:%s,地址:%s\n",p1->num,p1->name,p1->phone,p1->address);
n=n-1;
}
// else printf("通讯录中不存在学号为%d的学生信息\n",num);
}//end of if
}
//显示学生信息
void display(struct student *head)
{
struct student *p;
if(head==NULL)
printf("这是一个空表,请先输入信息!\n");
else
{
printf("\n现有%d名人员信息\n",n);
p=head;
do{
printf("学号:%d,姓名:%s,电话:%s,地址:%s\n",p->num,p->name,p->phone,p->address);
p=p->next;
}while(p!=NULL);
}//the end of else
}
/*退出程序
void Exit(int i)
{
exit(1);
}*/
void menu()
{
int choice;
do{
printf("\t\t****************************************************\n");
printf("\t\t\t 学生通讯录 \t\t\n");
printf("\t\t\t请根据数字选择相应的操作(1~6) \t\t\n");
printf("\t\t\t1.输入学生信息(学号 姓名 电话 地址)\t\t\n");
printf("\t\t\t2.增加学生信息(学号 姓名 电话 地址)\t\t\n");
printf("\t\t\t3.查找学生信息(输入学生学号) \t\t\n");
printf("\t\t\t4.删除学生信息(输入学生学号) \t\t\n");
printf("\t\t\t5.显示学生信息(学号 姓名 电话 地址)\t\t\n");
printf("\t\t\t6.退出通讯录 \t\t\n");
printf("\t\t****************************************************\n");
scanf("%d",&choice);
while(choice<1||choice>7)
{
printf(" 对不起您的输入错误!请输入您的选择(1--6):\t");
scanf("%d",&choice);
}
switch(choice)
{
case 1: head=create();break;
case 2: add();break;
case 3: select(head);break;
case 4: del(head);break;
case 5: display(head);break;
case 6: break;
default:printf("输入的数据有误,请重新输入\n"); break;
}
}
while(choice!=6);
}
//主函数
void main()
{
menu();
}
上海矽旭微电子
2024-12-16 广告
2024-12-16 广告
在上海矽旭微电子,我们重视每位员工的成长与发展。数字后端培训作为提升技术实力的关键环节,涵盖了从逻辑综合到物理实现的全过程,包括布局规划、时钟树生成、布线优化及功耗分析等核心技能。通过实战演练与理论讲解相结合,旨在增强工程师解决复杂布局布线...
点击进入详情页
本回答由上海矽旭微电子提供
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define FORMAT "%s\t\t%s\t\t%s\t%d\t%s\n"
int count=0;
struct Address
{
char Name[21];
int Age;
char Sex[6];
char ClassNum[11];
char PhonNum[12];
};
int Enterface();
int Add(Address book[]);
int Modify(Address book[]);
int Delent(Address book[]);
int Insert(Address book[]);
int Find(Address book[]);
int Show(Address book[]);
int FindName(Address book[]);
int FindClassNum(Address book[]);
int DelName(Address book[]);
int DelClassNum(Address book[]);
int FindPhonNum(Address book[]);
int Readtxt(Address book[]);
int Writetxt(Address book[]);
int Search(Address book[],char str1[],int n);
int FSearch(Address book[],char str2[],int n);
int Taxis(Address book[]);
int Exit();
////////////////////////////////////////////////////////////////////
void main()
{
Address book[100];
int choice;
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");
system("pause");
system("cls");
Readtxt(book);
while(or=='m')
{
choice=Enterface();
switch(choice)
{
case 1: Add(book);
break;
case 2: Modify(book);
break;
case 3: Delent(book);
break;
case 4: Insert(book);
break;
case 5: Find(book);
break;
case 6: Show(book);
break;
case 7: Exit();
break;
default : printf("!!!输入错误!!!\n");
Exit();
break;
}
}
}
int Enterface()
{
int choice=0;
printf("*******************\n");
printf(" 1.添加\n");
printf(" 2.修改\n");
printf(" 3.删除\n");
printf(" 4.插入\n");
printf(" 5.查找\n");
printf(" 6.显示\n");
printf(" 7.退出\n");
printf("*******************\n");
printf("请输入您的选择:");
scanf("%d",&choice);
return choice;
}
int Add(Address book[])
{
char or='Y';
while('Y'==or)
{
printf("请输入姓名:");
scanf("%s",&book[count].Name);
flag1:
printf("请输入电话号码:");
scanf("%s",&book[count].PhonNum);
for(int i=0;i<count;i++)
{
if(strcmp(book[count].PhonNum,book[i].PhonNum)==0)
{
printf("!!!号码已存在!!!\n");
goto flag1;
}
}
flag2:
printf("请输入学号:");
scanf("%s",&book[count].ClassNum);
for(i=0;i<count;i++)
{
if(strcmp(book[count].ClassNum,book[i].ClassNum)==0)
{
printf("!!!学号已存在!!!\n");
goto flag2;
}
}
printf("请输入年龄:");
scanf("%d",&book[count].Age);
printf("请输入性别:");
scanf("%s",&book[count].Sex);
getchar();
count++;
printf("是否继续添加('Y'添加,其他键返回主界面):");
scanf("%c",&or);
if('Y'!=or)
{
system("cls");
break;
}
}
Taxis(book);
Writetxt(book);
// printf("sdfsdfsdf\n");
return 0;
}
int Modify(Address book[])
{
char str[11];
int flag=0;
int ksd=0;
printf("去年个输入学号:");
scanf("%s",&str);
for(int i=0;i<count;i++)
{
if(strcmp(str,book[i].ClassNum)==0)
{
if(ksd==0)
{
printf(" 姓名\t 电话\t\t学号\t性别\t年龄\n");
ksd=1;
}
printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Sex,book[i].Age);
// str[flag_num++]=i;
flag=1;
// i--;
break;
}
}
if(flag==0)
{
printf("!!!无此记录!!!\n");
return 0;
}
printf("请输入姓名:");
scanf("%s",&book[i].Name);
flag0:
printf("请输入电话号码:");
scanf("%s",&book[i].PhonNum);
for(int j=0;j<count;j++)
{
if(j==i)
continue;
if(strcmp(book[i].PhonNum,book[j].PhonNum)==0)
{
printf("!!!号码已存在!!!\n");
goto flag0;
}
}
flag3:
printf("请输入学号:");
scanf("%s",&book[i].ClassNum);
for(j=0;j<count;j++)
{
if(j==i)
continue;
if(strcmp(book[i].ClassNum,book[j].ClassNum)==0)
{
printf("!!!学号已存在!!!\n");
goto flag3;
}
}
printf("请输入年龄:");
scanf("%d",&book[i].Age);
printf("请输入性别:");
scanf("%s",&book[i].Sex);
getchar();
printf("修改完毕!\n");
Writetxt(book);
system("pause");
// printf("modify\n");
return 0;
}
int Delent(Address book[])
{
// printf("delent\n");
int choice=0;
printf("================\n");
printf(" 1.按姓名删除\n");
printf(" 2.按学号删除\n");
printf("================\n");
scanf("%d",&choice);
switch(choice)
{
case 1: DelName(book);
break;
case 2: DelClassNum(book);
break;
default :
break;
}
return 0;
}
int Insert(Address book[])
{
Add(book);
// printf("insert\n");
return 0;
}
int Find(Address book[])
{
int choice=0;
printf("================\n");
printf(" 1.按姓名查找\n");
printf(" 2.按学号查找\n");
printf(" 3.按电话查找\n");
printf("================\n");
scanf("%d",&choice);
switch(choice)
{
case 1: FindName(book);
break;
case 2: FindClassNum(book);
break;
case 3: FindPhonNum(book);
break;
default :
break;
}
// printf("find\n");
return 0;
}
int FindName(Address book[])
{
char aname[30];
printf("请输入要查找的名字:");
scanf("%s",&aname);
FSearch(book,aname,3);
return 0;
}
int FindClassNum(Address book[])
{
char anum[20];
printf("请输入要查找的学号:");
scanf("%s",&anum);
FSearch(book,anum,2);
return 0;
}
int FindPhonNum(Address book[])
{
char aphonnum[20];
printf("请输入要查找的学号:");
scanf("%s",&aphonnum);
FSearch(book,aphonnum,1);
return 0;
}
int Show(Address book[])
{
int or=0;
if(count==0)
{
printf("!!!无记录!!!\n");
system("pause");
system("cls");
}
else
{
printf(" 姓名\t 电话\t\t学号\t性别\t年龄\n");
for(int i=0;i<count;i++)
printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Sex,book[i].Age);
system("pause");
}
printf("是否排序?\n-=1.排序=- -=2.返回主界面=-\n");
scanf("%d",&or);
if(1==or)
Taxis(book);
return 0;
}
int DelName(Address book[])
{
char aname[20];
printf("请输入要删除的姓名:");
scanf("%s",&aname);
Search(book,aname,2);
return 0;
}
int DelClassNum(Address book[])
{
char anum[20];
printf("请输入要删除的学号:");
scanf("%s",&anum);
Search(book,anum,1);
return 0;
}
int Readtxt(Address book[])
{
FILE *fp1;
fp1=fopen("photonumbers.txt","r");
if(fp1 == NULL)
{
printf("wrong!\n");
system("pause");
}
while(!feof(fp1))
{
if(!fscanf(fp1,"%s\t\t%s\t\t%s\t%d\t%s",book[count].Name,book[count].PhonNum,
book[count].ClassNum,&book[count].Age,book[count].Sex))
printf("读入出错!");
count++;
}
count--;
fclose(fp1);
return 0;
}
int Writetxt(Address book[])
{
FILE *fp;
fp=fopen("photonumbers.txt","w");
for(int i=0;i<count;i++)
{
fprintf(fp,FORMAT,book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Age,book[i].Sex);
}
fclose(fp);
return 0;
}
int Search(Address book[],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;i<count;i++)
{
if(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)
{
if(ksd==0)
{
printf(" 姓名\t 电话\t\t学号\t性别\t年龄\n");
ksd=1;
}
printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Sex,book[i].Age);
str[flag_num++]=i;
flag=1;
}
}
if(flag==0)
{
printf("!!!无记录!!!\n");
system("pause");
system("cls");
}
if(flag==1)
{
printf("-=1.确认删除=-\t-=2.取消=-\n");
scanf("%d",&j);
if(1==j)
{
gf=1;
for(int m=str[0];m<count-flag_num;m++)
{
for(int j=gf-1;j<flag_num;j++)
{
if((m+gf)==str[j])
gf++;
}
strcpy(book[m].Name,book[m+gf].Name);
book[m].Age=book[m+gf].Age;
strcpy(book[m].ClassNum,book[m+gf].ClassNum);
strcpy(book[m].PhonNum,book[m+gf].PhonNum);
strcpy(book[m].Sex,book[m+gf].Sex);
}
count=count-flag_num;
Writetxt(book);
}
else if(2==j)
{
printf("!!!操作已取消!!!\n");
}
system("pause");
}
return 0;
}
int FSearch(Address book[],char str2[],int n)
{
int flag=0;
int ksd=0;
for(int i=0;i<count;i++)
{
if(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(" 姓名\t 电话\t\t学号\t性别\t年龄\n");
ksd=1;
}
printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Sex,book[i].Age);
flag=1;
}
}
if(1==flag)
system("pause");
else if(flag==0)
{
printf("!!!无此记录!!!\n");
system("pause");
system("cls");
}
return 0;
}
int Taxis(Address book[])
{
/* for(int i=0;i<count;i++)
{
for(int j=0;j<count-1-i;j++)
{
if(strcmp(book[j].ClassNum,book[j+1].ClassNum)>0)
{
Address bk;
strcpy(bk.Name,book[j].Name);
bk.Age=book[j].Age;
strcpy(bk.ClassNum,book[j].ClassNum);
strcpy(bk.PhonNum,book[j].PhonNum);
strcpy(bk.Sex,book[j].Sex);
strcpy(book[j].Name,book[j+1].Name);
book[j].Age=book[j+1].Age;
strcpy(book[j].ClassNum,book[j+1].ClassNum);
strcpy(book[j].PhonNum,book[j+1].PhonNum);
strcpy(book[j].Sex,book[j+1].Sex);
strcpy(book[j+1].Name,bk.Name);
book[j+1].Age=bk.Age;
strcpy(book[j+1].ClassNum,bk.ClassNum);
strcpy(book[j+1].PhonNum,bk.PhonNum);
strcpy(book[j+1].Sex,bk.Sex);
}
}
}
printf("!!!操作成功!!!\n");
system("pause");
system("cls");
Writetxt(book);*/
return 0;
}
int Exit()
{
exit(1);
return 0;
}
留个邮箱啊。。。可以把整个工程发给你,这样省去甚多麻烦,另外的那个问题我也回答了...呵呵
#include<stdlib.h>
#include<string.h>
#define FORMAT "%s\t\t%s\t\t%s\t%d\t%s\n"
int count=0;
struct Address
{
char Name[21];
int Age;
char Sex[6];
char ClassNum[11];
char PhonNum[12];
};
int Enterface();
int Add(Address book[]);
int Modify(Address book[]);
int Delent(Address book[]);
int Insert(Address book[]);
int Find(Address book[]);
int Show(Address book[]);
int FindName(Address book[]);
int FindClassNum(Address book[]);
int DelName(Address book[]);
int DelClassNum(Address book[]);
int FindPhonNum(Address book[]);
int Readtxt(Address book[]);
int Writetxt(Address book[]);
int Search(Address book[],char str1[],int n);
int FSearch(Address book[],char str2[],int n);
int Taxis(Address book[]);
int Exit();
////////////////////////////////////////////////////////////////////
void main()
{
Address book[100];
int choice;
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");
system("pause");
system("cls");
Readtxt(book);
while(or=='m')
{
choice=Enterface();
switch(choice)
{
case 1: Add(book);
break;
case 2: Modify(book);
break;
case 3: Delent(book);
break;
case 4: Insert(book);
break;
case 5: Find(book);
break;
case 6: Show(book);
break;
case 7: Exit();
break;
default : printf("!!!输入错误!!!\n");
Exit();
break;
}
}
}
int Enterface()
{
int choice=0;
printf("*******************\n");
printf(" 1.添加\n");
printf(" 2.修改\n");
printf(" 3.删除\n");
printf(" 4.插入\n");
printf(" 5.查找\n");
printf(" 6.显示\n");
printf(" 7.退出\n");
printf("*******************\n");
printf("请输入您的选择:");
scanf("%d",&choice);
return choice;
}
int Add(Address book[])
{
char or='Y';
while('Y'==or)
{
printf("请输入姓名:");
scanf("%s",&book[count].Name);
flag1:
printf("请输入电话号码:");
scanf("%s",&book[count].PhonNum);
for(int i=0;i<count;i++)
{
if(strcmp(book[count].PhonNum,book[i].PhonNum)==0)
{
printf("!!!号码已存在!!!\n");
goto flag1;
}
}
flag2:
printf("请输入学号:");
scanf("%s",&book[count].ClassNum);
for(i=0;i<count;i++)
{
if(strcmp(book[count].ClassNum,book[i].ClassNum)==0)
{
printf("!!!学号已存在!!!\n");
goto flag2;
}
}
printf("请输入年龄:");
scanf("%d",&book[count].Age);
printf("请输入性别:");
scanf("%s",&book[count].Sex);
getchar();
count++;
printf("是否继续添加('Y'添加,其他键返回主界面):");
scanf("%c",&or);
if('Y'!=or)
{
system("cls");
break;
}
}
Taxis(book);
Writetxt(book);
// printf("sdfsdfsdf\n");
return 0;
}
int Modify(Address book[])
{
char str[11];
int flag=0;
int ksd=0;
printf("去年个输入学号:");
scanf("%s",&str);
for(int i=0;i<count;i++)
{
if(strcmp(str,book[i].ClassNum)==0)
{
if(ksd==0)
{
printf(" 姓名\t 电话\t\t学号\t性别\t年龄\n");
ksd=1;
}
printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Sex,book[i].Age);
// str[flag_num++]=i;
flag=1;
// i--;
break;
}
}
if(flag==0)
{
printf("!!!无此记录!!!\n");
return 0;
}
printf("请输入姓名:");
scanf("%s",&book[i].Name);
flag0:
printf("请输入电话号码:");
scanf("%s",&book[i].PhonNum);
for(int j=0;j<count;j++)
{
if(j==i)
continue;
if(strcmp(book[i].PhonNum,book[j].PhonNum)==0)
{
printf("!!!号码已存在!!!\n");
goto flag0;
}
}
flag3:
printf("请输入学号:");
scanf("%s",&book[i].ClassNum);
for(j=0;j<count;j++)
{
if(j==i)
continue;
if(strcmp(book[i].ClassNum,book[j].ClassNum)==0)
{
printf("!!!学号已存在!!!\n");
goto flag3;
}
}
printf("请输入年龄:");
scanf("%d",&book[i].Age);
printf("请输入性别:");
scanf("%s",&book[i].Sex);
getchar();
printf("修改完毕!\n");
Writetxt(book);
system("pause");
// printf("modify\n");
return 0;
}
int Delent(Address book[])
{
// printf("delent\n");
int choice=0;
printf("================\n");
printf(" 1.按姓名删除\n");
printf(" 2.按学号删除\n");
printf("================\n");
scanf("%d",&choice);
switch(choice)
{
case 1: DelName(book);
break;
case 2: DelClassNum(book);
break;
default :
break;
}
return 0;
}
int Insert(Address book[])
{
Add(book);
// printf("insert\n");
return 0;
}
int Find(Address book[])
{
int choice=0;
printf("================\n");
printf(" 1.按姓名查找\n");
printf(" 2.按学号查找\n");
printf(" 3.按电话查找\n");
printf("================\n");
scanf("%d",&choice);
switch(choice)
{
case 1: FindName(book);
break;
case 2: FindClassNum(book);
break;
case 3: FindPhonNum(book);
break;
default :
break;
}
// printf("find\n");
return 0;
}
int FindName(Address book[])
{
char aname[30];
printf("请输入要查找的名字:");
scanf("%s",&aname);
FSearch(book,aname,3);
return 0;
}
int FindClassNum(Address book[])
{
char anum[20];
printf("请输入要查找的学号:");
scanf("%s",&anum);
FSearch(book,anum,2);
return 0;
}
int FindPhonNum(Address book[])
{
char aphonnum[20];
printf("请输入要查找的学号:");
scanf("%s",&aphonnum);
FSearch(book,aphonnum,1);
return 0;
}
int Show(Address book[])
{
int or=0;
if(count==0)
{
printf("!!!无记录!!!\n");
system("pause");
system("cls");
}
else
{
printf(" 姓名\t 电话\t\t学号\t性别\t年龄\n");
for(int i=0;i<count;i++)
printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Sex,book[i].Age);
system("pause");
}
printf("是否排序?\n-=1.排序=- -=2.返回主界面=-\n");
scanf("%d",&or);
if(1==or)
Taxis(book);
return 0;
}
int DelName(Address book[])
{
char aname[20];
printf("请输入要删除的姓名:");
scanf("%s",&aname);
Search(book,aname,2);
return 0;
}
int DelClassNum(Address book[])
{
char anum[20];
printf("请输入要删除的学号:");
scanf("%s",&anum);
Search(book,anum,1);
return 0;
}
int Readtxt(Address book[])
{
FILE *fp1;
fp1=fopen("photonumbers.txt","r");
if(fp1 == NULL)
{
printf("wrong!\n");
system("pause");
}
while(!feof(fp1))
{
if(!fscanf(fp1,"%s\t\t%s\t\t%s\t%d\t%s",book[count].Name,book[count].PhonNum,
book[count].ClassNum,&book[count].Age,book[count].Sex))
printf("读入出错!");
count++;
}
count--;
fclose(fp1);
return 0;
}
int Writetxt(Address book[])
{
FILE *fp;
fp=fopen("photonumbers.txt","w");
for(int i=0;i<count;i++)
{
fprintf(fp,FORMAT,book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Age,book[i].Sex);
}
fclose(fp);
return 0;
}
int Search(Address book[],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;i<count;i++)
{
if(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)
{
if(ksd==0)
{
printf(" 姓名\t 电话\t\t学号\t性别\t年龄\n");
ksd=1;
}
printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Sex,book[i].Age);
str[flag_num++]=i;
flag=1;
}
}
if(flag==0)
{
printf("!!!无记录!!!\n");
system("pause");
system("cls");
}
if(flag==1)
{
printf("-=1.确认删除=-\t-=2.取消=-\n");
scanf("%d",&j);
if(1==j)
{
gf=1;
for(int m=str[0];m<count-flag_num;m++)
{
for(int j=gf-1;j<flag_num;j++)
{
if((m+gf)==str[j])
gf++;
}
strcpy(book[m].Name,book[m+gf].Name);
book[m].Age=book[m+gf].Age;
strcpy(book[m].ClassNum,book[m+gf].ClassNum);
strcpy(book[m].PhonNum,book[m+gf].PhonNum);
strcpy(book[m].Sex,book[m+gf].Sex);
}
count=count-flag_num;
Writetxt(book);
}
else if(2==j)
{
printf("!!!操作已取消!!!\n");
}
system("pause");
}
return 0;
}
int FSearch(Address book[],char str2[],int n)
{
int flag=0;
int ksd=0;
for(int i=0;i<count;i++)
{
if(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(" 姓名\t 电话\t\t学号\t性别\t年龄\n");
ksd=1;
}
printf("%8s\t%8s\t%s\t%s\t%d\n",book[i].Name,book[i].PhonNum,
book[i].ClassNum,book[i].Sex,book[i].Age);
flag=1;
}
}
if(1==flag)
system("pause");
else if(flag==0)
{
printf("!!!无此记录!!!\n");
system("pause");
system("cls");
}
return 0;
}
int Taxis(Address book[])
{
/* for(int i=0;i<count;i++)
{
for(int j=0;j<count-1-i;j++)
{
if(strcmp(book[j].ClassNum,book[j+1].ClassNum)>0)
{
Address bk;
strcpy(bk.Name,book[j].Name);
bk.Age=book[j].Age;
strcpy(bk.ClassNum,book[j].ClassNum);
strcpy(bk.PhonNum,book[j].PhonNum);
strcpy(bk.Sex,book[j].Sex);
strcpy(book[j].Name,book[j+1].Name);
book[j].Age=book[j+1].Age;
strcpy(book[j].ClassNum,book[j+1].ClassNum);
strcpy(book[j].PhonNum,book[j+1].PhonNum);
strcpy(book[j].Sex,book[j+1].Sex);
strcpy(book[j+1].Name,bk.Name);
book[j+1].Age=bk.Age;
strcpy(book[j+1].ClassNum,bk.ClassNum);
strcpy(book[j+1].PhonNum,bk.PhonNum);
strcpy(book[j+1].Sex,bk.Sex);
}
}
}
printf("!!!操作成功!!!\n");
system("pause");
system("cls");
Writetxt(book);*/
return 0;
}
int Exit()
{
exit(1);
return 0;
}
留个邮箱啊。。。可以把整个工程发给你,这样省去甚多麻烦,另外的那个问题我也回答了...呵呵
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询