直升机航模制作:怎样建立一个链表操作题(包括建立,插入,删除,打印等)?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 12:09:18
请给出一个完整的C语言代码

太复杂了

这是我曾经的一个作业题,我做得不好,但还凑合,希望能帮你一点忙
#include<stdio.h>
#include<alloc.h>
#define LEN sizeof(struct student)
struct student
{
long num;
char nam[20];
char cla[10];
int s[5];
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("\nNO.:");
scanf("%ld",&p->num);
printf("\nname:");
scanf("%s",&p->nam);
printf("\nclass:");
scanf("%s",&p->cla);
printf("Input scores:maths english physics art P.E\n");
for(i=0;i<5;i++)
scanf("%d",&p->s[i]);
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 num class maths english physics art P.E ");
printf("\n %-12s%ld%s\n",p->nam,p->num,p->cla);
for(i=0;i<5;i++)
printf("%d",p->s[i]);
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("\nnumber:%ld",p->num );
printf("\nclass:%s",p->cla);
for(i=0;i<5;i++)
printf("\nscore:%d",p->s[i]);
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("\n name num class maths english physics art P.E ");
printf("\n %-8s%ld%s\n",p->nam,p->num,p->cla);
for(i=0;i<5;i++)
printf("%8d",p->s[i]);
printf("\n***********************************************");}

}

picture1()
{
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!");
}
}
picture2()
{
int k;
printf("----------------------------------\n");
printf("| input 1: find() |\n");
printf("----------------------------------\n");
printf("| input 2: display() |\n");
printf("----------------------------------\n");

printf("please input k(1-2)\n");
scanf("%d",&k);
switch(k)
{
case 1: find();break;
case 2: record();break;
default :printf("\nIt is possible to make a mistake!");
}
}
main()
{

char stu1[10]="student";
char stu2[10]="1234";
char stu3[10]="manager";
char stu4[10]="12345";
char stu5[10];
char stu6[10];
int t,k;
char e;
head=NULL;
printf(" ---------------------------- \n");
printf(" | WELCOME TO THIS SYSTEM | \n");
printf(" ---------------------------- \n");
printf("\n\n\n\n\n");
printf("-------------------------------------------\n");
printf("| please input your identity |\n");
printf("-------------------------------------------\n");
printf("| identity: |\n");
printf(" ");
scanf("%s",stu5);
printf("|-----------------------------------------|\n");
printf("\n");
printf("|please input your password |\n");
printf("-------------------------------------------\n");
printf("| password: |\n");
printf(" ");
scanf("%s",stu6);
printf("|-----------------------------------------|\n");
printf("\n");
if(strcmp(stu5,stu1)==0&&strcmp(stu6,stu2)==0)
{
t=4;
}
else if(strcmp(stu5,stu3)==0&&strcmp(stu6,stu4)==0)
{
t=1;
}

else printf("the error\n");
if(t==1)
{ while(1)
{
picture1();
printf("Are you back to the main menu Y or N\n");
fflush(stdin);
scanf("%c",&e);
if(e=='Y'||e=='y') picture1();
else if(e=='N'||e=='n') break;
}
}

else if(t==4)
{ while(1)
{ picture2();
printf("Are you back to the main menu Y or N\n");
fflush(stdin);
scanf("%c",&e);
if(e=='Y'||e=='y')picture2();
else if(e=='N'||e=='n') break;
}
}

}
功能描述
整个功能共有两大主要功能
1. 供普通用户登陆并查询用户信息
不同身份在界面输入学号和姓名后即可登陆该系统并查询自己的数学、英语、物理、美术和体育五科成绩。
2. 供管理员登陆并管理整个系统
(1) 管理员在界面输入密码登陆管理系统
(2) 管理员可以录入用户的成绩并保存
(3) 管理员对用户成绩可以进行新建、显示、删除、插入、查找、统计的功能