恩平市政府:那位高人能帮我做下C语言的题目,跪求

来源:百度文库 编辑:高校问答 时间:2024/05/03 01:54:30
目的:1。掌握一般磁盘文件的打开,关闭和读写操作
2。建立学生电子通讯录管理系统
要求:1。建立数据文件,内容包含5名学生的姓名及其电话和E—mail地址
2。查找用户输入的学生的电话或E-mail地址
3。插入用户输入新学生的姓名及电话和E-mail地址
4。删除用户输入的学生的姓名,电话和E-mail地址
5。用户可以在所提供的菜单中选择执行的操作
6。程序应具有一定的健壮性
试验训练原理
1。一般磁盘文件的输入和输出库函数的使用方法
2。一般磁盘文件的操作流程
实训项目1实训步骤
画出程序流程图
完成代码原型
上机编码实现程序
测试调试并运行,打印结果
完成实训报告,准备演示程序
介于流程图不方便,所以只要程序就行了
万分感谢
我也明白,我是学生,这个问题是在不会
我多等几天都没事
谢谢各位了

#include<stdio.h>
#include<alloc.h>
#define LEN sizeof(struct student)
struct student
{
char nam[20];
long phone;
char email[40];
struct student *next;
}*head=NULL;
void new()
{
struct student *head,*p;
insert();
}

insert()
{
struct student *p;
char c;
int i;
p=(struct student *)malloc(LEN);
printf("\nname:");
scanf("%s",&p->nam);
printf("\nphone:");
scanf("%ld",&p->phone);
printf("\nemail:");
scanf("%s",&p->email);
p->next=head;
head=p;
printf("\nDo you continue to insert Y or N\n");
fflush(stdin);
scanf("%c",&c);
if(c=='Y'||c=='y') insert();
if( c=='N'||c=='n') return ;
}
void display()
{

struct student *p;
int n=0,i;
char t;
p=head;
while(p!=NULL)
{
printf("\n***********************************************");
printf("\n name phone email ");
printf("\n %12s%ld%s\n",p->nam,p->phone,p->email);

printf("\n***********************************************");
p=p->next;
n++;
if(n%3==0)
{
printf("to be continued.put any key!");
fflush(stdin);
scanf("%c",&t);
clrscr( );
}
}
}
find()
{
struct student *p;
char c;
char name1[20];
int i;
p=head;
printf("\nPlease input the name:");
scanf("%s",name1);
while((strcmp(name1,p->nam)!=0)&&(p!=NULL))
p=p->next;
if(p==NULL)
printf("\nIt is not existing in the list");
else
{printf("\n############################################");
printf("\nphone:%ld",p->phone);
printf("\nemail:%s",p->email);
printf("\n###########################################");
}
printf("\nDo you continue to find Y or N");
fflush(stdin);
scanf("%c",&c);
if(c=='Y'||c=='y')find ();
if(c=='N'||c=='n') return ;
}

delete()

{
struct student *p,*p1;
char c;
char name2[20];
p=head;
printf("Please input a name:");
scanf("%s",name2);
while((strcmp(name2,p->nam)!=0)&&(p!=NULL))
{p1=p;
p=p->next;
}
if(p==NULL)
printf("\nIt is not exist in the list");
else
p1->next=p->next;
printf("\nDo you continue to delete Y or N");
fflush(stdin);
scanf("%c",&c);
if(c=='Y'||c=='y') delete();
if(c=='N'||c=='n') return;

}

save()
{
FILE *fp;
struct student *p;
fp=fopen("d:\\stu_list.txt","w");
p=head;
if(p==NULL)
{printf("\nThis is a null list!");
}
else
do
{ fwrite(p,LEN,1,fp);
p=p->next;
}while(p!=NULL);
fclose(fp);
}

exit ()
{ char c;
printf("\n **************************");
printf("\nWill you save ? Y or N\n");
fflush(stdin);
scanf("%c",&c);
if(c=='y'||c=='Y') save ();
else
if(c=='n'||c=='N');
return;
}
record()
{
FILE *fp;
struct student *p;
int i;
p=head;
if((fp=fopen("d:\\stu_list.txt","r"))==NULL)
{
printf("Can't open this file\n");
return;
}
for(;fread(p,LEN,1,fp)!=0;)
{printf("\n***********************************************");
printf("\nphone:%ld",p->phone);
printf("\nemail:%s",p->email);
printf("\n***********************************************");}

}

main()
{
int k;
printf("------------------------------------------\n");
printf("| input 1: new() |\n");
printf("-----------------------------------------|\n");
printf("| input 2: insert() |\n");
printf("------------------------------------------\n");
printf("| input 3: find() |\n");
printf("------------------------------------------\n");
printf("| input 4: del() |\n");
printf("------------------------------------------\n");
printf("| input 5: display() |\n");
printf("------------------------------------------\n");
printf("| input 6: record() |\n");
printf("------------------------------------------\n");
printf("| input 0: exit() |\n");
printf("------------------------------------------\n");
printf(" please input k(1-6)\n");
scanf("%d",&k);
switch(k)
{
case 1: new ();break;
case 2: insert();break;
case 3: find();break;

case 4: delete();break;
case 5: display(); break;
case 6: record();break;
case 0: exit();break;
default :printf("\nIt is possible to make a mistake!");
}}

编译是通过了,但有个毛病
以前我做过一个类似的作业,照你的要求修改了一下
在出现“WIll you save?”后,就退出了,我本是想让他返回到提供的菜单中的
水平有限!
如果你急着用,就先拿这个用,我再看看有什么办法

我知道你拿了全部家当出来,不简单,但是这个作业太花时间,恐怕……

花点money吧!