1、 通讯录要求完成添加、删除、查找、按顺序排列等功能。
2、 程序要求有主界面显示上述功能,可以自己增加相关功能。
3、 程序要求使用函数、结构体、数组、指针,任意选择适当的数据类型来完成程序。
4、 程序使用C语言完成源代码的编写工作。
请大家帮忙解决下!谢啦!
15 个解决方案
#1
你干嘛不自己做?
#2
先设计一个结构体保存通讯录的字段,然后用指针数组或链表存储即可。
#3
你这不是作业吧=-=!作业要自己更生啊~
#4
好好学习,天天向上!
#5
这种问题自己写吧
没有这样的直接要代码的
没有这样的直接要代码的
#6
帮楼主想,不过还是你动手吧
#7
这是我上个学期做的一个课程设计,楼主可以参考并修改一下:
#include<graphics.h>
#include<stdio.h>
#define Esc 27
#define Enter 13
#define Up 72
#define Down 80
struct listnode{
char phone[20];
char name[20];
struct listnode *next;
};
typedef struct listnode nodetype;
Frame()
{
int x,y;
for(x=8;x<=70;x++)
{
textcolor(BLUE);
gotoxy(x,7);
cprintf("-");
textcolor(BLUE);
gotoxy(x,18);
cprintf("-");
}
for(y=7;y<=18;y++)
{
textcolor(BLUE);
gotoxy(8,y);
cprintf("*");
textcolor(BLUE);
gotoxy(70,y);
cprintf("*");
}
}
void ShowMessage(nodetype *s,nodetype *l)
{
if(l->next==NULL)
{
textcolor(YELLOW);
gotoxy(10,10);
cprintf("The Message Box is Empty!");
}
else
{
textcolor(WHITE);
gotoxy(10,10);
cprintf("The name is: ");
cprintf("%s",s->name);
textcolor(WHITE);
gotoxy(10,12);
cprintf("The phone number is: ");
cprintf("%s",s->phone);
}
}
void ChangeName(nodetype *s)
{ int i;
Frame();
textcolor(YELLOW);
gotoxy(12,10);
cprintf("Put in the right name: ");
for(i=0;i<=19;i++)
s->name[i]=' ';
scanf("%s",s->name);
clrscr();
}
void ChangePhoneNumber(nodetype *s)
{
int i;
Frame();
textcolor(YELLOW);
gotoxy(12,10);
cprintf("Put in the right phone number:\n");
for(i=0;i<=19;i++)
s->phone[i]=' ';
scanf("%s",s->phone);
clrscr();
}
nodetype *delete_linklist(nodetype *l,nodetype *s) /*Delete the current node*/
{
nodetype *p;
p=l;
while(p->next!=s)
{
p=p->next;
}
s=p->next;
p->next=s->next;
free(s);
return l->next;
}
nodetype *add_linklist(nodetype *l)
{ nodetype *p,*s;
int j=2,i;
char x[20];
char na[20]="";
Frame();
textcolor(YELLOW);
gotoxy(12,10);
cprintf("Please Input the name: ");
scanf("%s",&na);
textcolor(YELLOW);
gotoxy(12,12);
cprintf("Please Input the phone number: ");
scanf("%s",&x);
p=l;
while(p->next!=NULL)
{p=p->next;j++;}
s=(nodetype*)malloc(sizeof(nodetype));
for(i=0;i<=19;i++)
s->phone[i]=x[i];
for(i=0;i<=19;i++)
s->name[i]=na[i];
s->next=p->next;
p->next=s;
clrscr();
return s;
}
nodetype *PageUp(nodetype *s,nodetype *l)
{
nodetype *p;
p=l;
if(l->next==s)
return s;
else
while(p->next!=s)
{
p=p->next;
}
return p;
}
nodetype *PageDn(nodetype *s)
{ if(s->next==NULL)
return s;
else
s=s->next;
return s;
}
Save(nodetype *l)
{
FILE *cfPtr;
nodetype *p;
p=l;
if((cfPtr=fopen("data.txt","w"))==NULL){
printf("File could not be opened\n");
}
else{
while(p->next!=NULL)
{ p=p->next;
fprintf(cfPtr,"%s %s\n",p->name,p->phone); }
}
fclose(cfPtr);
}
Initial(nodetype *l)
{ char phone[20];
char name[20];
int i;
nodetype *p,*s;
FILE *cfPtr;
p=l;
s=l->next;
if((cfPtr=fopen("data.txt","r"))==NULL){
printf("File could not be opened\n");
}
else{
while(!feof(cfPtr)){
fscanf(cfPtr,"%s%s",name,phone);
s=(nodetype *)malloc(sizeof(nodetype));
for(i=0;i<=19;i++)
{
s->name[i]=name[i];
s->phone[i]=phone[i];
}
s->next=NULL;
p->next=s;
p=s;
}
fclose(cfPtr);
if(l->next!=NULL)
{
p=l;
while(p->next!=s)
{
p=p->next;
}
s=p->next;
p->next=s->next;
free(s);
}
}
}
void ShowMenu(int c1,int c2,int c3,nodetype *s,nodetype *l,int c4,int c5,int c6,int c7,int c8)
{
Frame();
textcolor(c1);
gotoxy(45,10);
cprintf("AddToTheLast");
textcolor(c2);
gotoxy(45,11);
cprintf("DeleteCurrentData");
textcolor(c3);
gotoxy(45,12);
cprintf("ChangeCurrentName");
ShowMessage(s,l);
textcolor(GREEN);
gotoxy(25,8);
cprintf("WELCOME TO MY MESSAGEE BOX!");
textcolor(c4);
gotoxy(45,13);
cprintf("ChangeCurrentPhoneNumber");
textcolor(c5);
gotoxy(45,14);
cprintf("PgUp");
textcolor(c6);
gotoxy(45,15);
cprintf("PgDn");
textcolor(c7);
gotoxy(45,16);
cprintf("Save");
textcolor(c8);
gotoxy(45,17);
cprintf("Quit");
}
void MenuControl(nodetype *l)
{
int cy;
char key;
nodetype *s;
clrscr();
cy=10;
Initial(l);
s=l->next;
ShowMenu(RED,WHITE,WHITE,s,l,WHITE,WHITE,WHITE,WHITE,WHITE);
while(1)
{
if(kbhit())
{
key=getch();
if(key==Esc)
exit(0);
else
if(key==Enter)
{
clrscr();
switch(cy)
{
case 10:s=add_linklist(l);
break;
case 12:s=delete_linklist(l,s);
break;
case 14:ChangeName(s);
break;
case 16:ChangePhoneNumber(s);
break;
case 18:s=PageUp(s,l);
break;
case 20:s=PageDn(s);
break;
case 22:Save(l);
break;
case 24:exit(0);
break;
}
}
else
if(key==72)
{
if(cy==10);
else
cy-=2;
}
else
if(key==80)
{
if(cy==24);
else
cy+=2;
}
switch(cy)
{
case 10:ShowMenu(RED,WHITE,WHITE,s,l,WHITE,WHITE,WHITE,WHITE,WHITE);
break;
case 12:ShowMenu(WHITE,RED,WHITE,s,l,WHITE,WHITE,WHITE,WHITE,WHITE);
break;
case 14:ShowMenu(WHITE,WHITE,RED,s,l,WHITE,WHITE,WHITE,WHITE,WHITE);
break;
case 16:ShowMenu(WHITE,WHITE,WHITE,s,l,RED,WHITE,WHITE,WHITE,WHITE);
break;
case 18:ShowMenu(WHITE,WHITE,WHITE,s,l,WHITE,RED,WHITE,WHITE,WHITE);
break;
case 20:ShowMenu(WHITE,WHITE,WHITE,s,l,WHITE,WHITE,RED,WHITE,WHITE);
break;
case 22:ShowMenu(WHITE,WHITE,WHITE,s,l,WHITE,WHITE,WHITE,RED,WHITE);
break;
case 24:ShowMenu(WHITE,WHITE,WHITE,s,l,WHITE,WHITE,WHITE,WHITE,RED);
break;
}
}
}
}
main()
{
nodetype *l;
FILE *fp;
l=(nodetype *)malloc(sizeof(nodetype));
l->next=NULL;
MenuControl(l);
}
#8
运行环境:winTC.
#9
刚有人写了个,给你个做个参考
#include<stdio.h>
struct student
{
int num;
char *name;
char sex;
int age;
char *add;
};
struct student student_1[3];
struct student *p;
int main()
{
int i;
student_1[0].num=10010;
student_1[0].name="zhang";
student_1[0].sex='M';
student_1[0].age=21;
student_1[0].add="Nei Meng Gu";
student_1[1].num=10011;
student_1[1].name="tang";
student_1[1].sex='M';
student_1[1].age=20;
student_1[1].add="Bei Jing";
student_1[2].num=10012;
student_1[2].name="li";
student_1[2].sex='W';
student_1[2].age=23;
student_1[2].add="Ji Lin";
p=student_1;
//printf("error\n");
//for(p;p<p+3;p++)
for(i=0;i<3;i++)
{
printf("%d\t%s\t%c\t%d\t%s\n",student_1[i].num,student_1[i].name,student_1[i].sex,student_1[i].age,student_1[i].add);
//printf("%d\t%s\t%c\t%d\t%s\n",p[i].num,p[i].name,p[i].sex,p[i].age,p[i].add);
}
system("pause");
return 0;
}
#10
谢谢各位啦!我会认真做的!
#11
直接要代码是不对滴,直接给代码更是害人滴,搞这个就是要静的下心去慢慢琢磨,楼主加油,什么不懂尽管问
#12
#13
对于作业,我们应该 无视
#14
借鉴可以,不要copy啦
#15
楼主有什么问题可以来这里问我们会尽力帮你的
#1
你干嘛不自己做?
#2
先设计一个结构体保存通讯录的字段,然后用指针数组或链表存储即可。
#3
你这不是作业吧=-=!作业要自己更生啊~
#4
好好学习,天天向上!
#5
这种问题自己写吧
没有这样的直接要代码的
没有这样的直接要代码的
#6
帮楼主想,不过还是你动手吧
#7
这是我上个学期做的一个课程设计,楼主可以参考并修改一下:
#include<graphics.h>
#include<stdio.h>
#define Esc 27
#define Enter 13
#define Up 72
#define Down 80
struct listnode{
char phone[20];
char name[20];
struct listnode *next;
};
typedef struct listnode nodetype;
Frame()
{
int x,y;
for(x=8;x<=70;x++)
{
textcolor(BLUE);
gotoxy(x,7);
cprintf("-");
textcolor(BLUE);
gotoxy(x,18);
cprintf("-");
}
for(y=7;y<=18;y++)
{
textcolor(BLUE);
gotoxy(8,y);
cprintf("*");
textcolor(BLUE);
gotoxy(70,y);
cprintf("*");
}
}
void ShowMessage(nodetype *s,nodetype *l)
{
if(l->next==NULL)
{
textcolor(YELLOW);
gotoxy(10,10);
cprintf("The Message Box is Empty!");
}
else
{
textcolor(WHITE);
gotoxy(10,10);
cprintf("The name is: ");
cprintf("%s",s->name);
textcolor(WHITE);
gotoxy(10,12);
cprintf("The phone number is: ");
cprintf("%s",s->phone);
}
}
void ChangeName(nodetype *s)
{ int i;
Frame();
textcolor(YELLOW);
gotoxy(12,10);
cprintf("Put in the right name: ");
for(i=0;i<=19;i++)
s->name[i]=' ';
scanf("%s",s->name);
clrscr();
}
void ChangePhoneNumber(nodetype *s)
{
int i;
Frame();
textcolor(YELLOW);
gotoxy(12,10);
cprintf("Put in the right phone number:\n");
for(i=0;i<=19;i++)
s->phone[i]=' ';
scanf("%s",s->phone);
clrscr();
}
nodetype *delete_linklist(nodetype *l,nodetype *s) /*Delete the current node*/
{
nodetype *p;
p=l;
while(p->next!=s)
{
p=p->next;
}
s=p->next;
p->next=s->next;
free(s);
return l->next;
}
nodetype *add_linklist(nodetype *l)
{ nodetype *p,*s;
int j=2,i;
char x[20];
char na[20]="";
Frame();
textcolor(YELLOW);
gotoxy(12,10);
cprintf("Please Input the name: ");
scanf("%s",&na);
textcolor(YELLOW);
gotoxy(12,12);
cprintf("Please Input the phone number: ");
scanf("%s",&x);
p=l;
while(p->next!=NULL)
{p=p->next;j++;}
s=(nodetype*)malloc(sizeof(nodetype));
for(i=0;i<=19;i++)
s->phone[i]=x[i];
for(i=0;i<=19;i++)
s->name[i]=na[i];
s->next=p->next;
p->next=s;
clrscr();
return s;
}
nodetype *PageUp(nodetype *s,nodetype *l)
{
nodetype *p;
p=l;
if(l->next==s)
return s;
else
while(p->next!=s)
{
p=p->next;
}
return p;
}
nodetype *PageDn(nodetype *s)
{ if(s->next==NULL)
return s;
else
s=s->next;
return s;
}
Save(nodetype *l)
{
FILE *cfPtr;
nodetype *p;
p=l;
if((cfPtr=fopen("data.txt","w"))==NULL){
printf("File could not be opened\n");
}
else{
while(p->next!=NULL)
{ p=p->next;
fprintf(cfPtr,"%s %s\n",p->name,p->phone); }
}
fclose(cfPtr);
}
Initial(nodetype *l)
{ char phone[20];
char name[20];
int i;
nodetype *p,*s;
FILE *cfPtr;
p=l;
s=l->next;
if((cfPtr=fopen("data.txt","r"))==NULL){
printf("File could not be opened\n");
}
else{
while(!feof(cfPtr)){
fscanf(cfPtr,"%s%s",name,phone);
s=(nodetype *)malloc(sizeof(nodetype));
for(i=0;i<=19;i++)
{
s->name[i]=name[i];
s->phone[i]=phone[i];
}
s->next=NULL;
p->next=s;
p=s;
}
fclose(cfPtr);
if(l->next!=NULL)
{
p=l;
while(p->next!=s)
{
p=p->next;
}
s=p->next;
p->next=s->next;
free(s);
}
}
}
void ShowMenu(int c1,int c2,int c3,nodetype *s,nodetype *l,int c4,int c5,int c6,int c7,int c8)
{
Frame();
textcolor(c1);
gotoxy(45,10);
cprintf("AddToTheLast");
textcolor(c2);
gotoxy(45,11);
cprintf("DeleteCurrentData");
textcolor(c3);
gotoxy(45,12);
cprintf("ChangeCurrentName");
ShowMessage(s,l);
textcolor(GREEN);
gotoxy(25,8);
cprintf("WELCOME TO MY MESSAGEE BOX!");
textcolor(c4);
gotoxy(45,13);
cprintf("ChangeCurrentPhoneNumber");
textcolor(c5);
gotoxy(45,14);
cprintf("PgUp");
textcolor(c6);
gotoxy(45,15);
cprintf("PgDn");
textcolor(c7);
gotoxy(45,16);
cprintf("Save");
textcolor(c8);
gotoxy(45,17);
cprintf("Quit");
}
void MenuControl(nodetype *l)
{
int cy;
char key;
nodetype *s;
clrscr();
cy=10;
Initial(l);
s=l->next;
ShowMenu(RED,WHITE,WHITE,s,l,WHITE,WHITE,WHITE,WHITE,WHITE);
while(1)
{
if(kbhit())
{
key=getch();
if(key==Esc)
exit(0);
else
if(key==Enter)
{
clrscr();
switch(cy)
{
case 10:s=add_linklist(l);
break;
case 12:s=delete_linklist(l,s);
break;
case 14:ChangeName(s);
break;
case 16:ChangePhoneNumber(s);
break;
case 18:s=PageUp(s,l);
break;
case 20:s=PageDn(s);
break;
case 22:Save(l);
break;
case 24:exit(0);
break;
}
}
else
if(key==72)
{
if(cy==10);
else
cy-=2;
}
else
if(key==80)
{
if(cy==24);
else
cy+=2;
}
switch(cy)
{
case 10:ShowMenu(RED,WHITE,WHITE,s,l,WHITE,WHITE,WHITE,WHITE,WHITE);
break;
case 12:ShowMenu(WHITE,RED,WHITE,s,l,WHITE,WHITE,WHITE,WHITE,WHITE);
break;
case 14:ShowMenu(WHITE,WHITE,RED,s,l,WHITE,WHITE,WHITE,WHITE,WHITE);
break;
case 16:ShowMenu(WHITE,WHITE,WHITE,s,l,RED,WHITE,WHITE,WHITE,WHITE);
break;
case 18:ShowMenu(WHITE,WHITE,WHITE,s,l,WHITE,RED,WHITE,WHITE,WHITE);
break;
case 20:ShowMenu(WHITE,WHITE,WHITE,s,l,WHITE,WHITE,RED,WHITE,WHITE);
break;
case 22:ShowMenu(WHITE,WHITE,WHITE,s,l,WHITE,WHITE,WHITE,RED,WHITE);
break;
case 24:ShowMenu(WHITE,WHITE,WHITE,s,l,WHITE,WHITE,WHITE,WHITE,RED);
break;
}
}
}
}
main()
{
nodetype *l;
FILE *fp;
l=(nodetype *)malloc(sizeof(nodetype));
l->next=NULL;
MenuControl(l);
}
#8
运行环境:winTC.
#9
刚有人写了个,给你个做个参考
#include<stdio.h>
struct student
{
int num;
char *name;
char sex;
int age;
char *add;
};
struct student student_1[3];
struct student *p;
int main()
{
int i;
student_1[0].num=10010;
student_1[0].name="zhang";
student_1[0].sex='M';
student_1[0].age=21;
student_1[0].add="Nei Meng Gu";
student_1[1].num=10011;
student_1[1].name="tang";
student_1[1].sex='M';
student_1[1].age=20;
student_1[1].add="Bei Jing";
student_1[2].num=10012;
student_1[2].name="li";
student_1[2].sex='W';
student_1[2].age=23;
student_1[2].add="Ji Lin";
p=student_1;
//printf("error\n");
//for(p;p<p+3;p++)
for(i=0;i<3;i++)
{
printf("%d\t%s\t%c\t%d\t%s\n",student_1[i].num,student_1[i].name,student_1[i].sex,student_1[i].age,student_1[i].add);
//printf("%d\t%s\t%c\t%d\t%s\n",p[i].num,p[i].name,p[i].sex,p[i].age,p[i].add);
}
system("pause");
return 0;
}
#10
谢谢各位啦!我会认真做的!
#11
直接要代码是不对滴,直接给代码更是害人滴,搞这个就是要静的下心去慢慢琢磨,楼主加油,什么不懂尽管问
#12
#13
对于作业,我们应该 无视
#14
借鉴可以,不要copy啦
#15
楼主有什么问题可以来这里问我们会尽力帮你的