计算机程序设计基础结课报告,计算机程序设计基础课程设计报告.doc

#includestruct student

{

char name[20];

long int num;

int score1,score2;

char sex;

struct student *next;

};

int n;

long num;

struct student *head=NULL,*stu;

struct student *creat()

{

struct student *head,*p,*q;

n=0;

head=NULL;

p=q=(struct student *)malloc(sizeof(struct student));

do{

printf("enter date(input 0 for end):\n");

printf("please input Student num:");

scanf("%ld%*c", &p->num);

if (0 == p->num)

break;

printf("please input Student name:");

scanf("%s", &p->name);

printf("please input Student score1:");

scanf("%d", &p->score1);

printf("please input Student score2:");

scanf("%d", &p->score2);

printf("please input Student sex(m/w):");

scanf("%*c%c%*c", &p->sex);

n++;

if(n==1)

{

head=p;

head->next=NULL;

}

else

q->next=p;

q=p;

p=(struct student *)malloc(sizeof(struct student));

}while(p->num!=0);

q->next=NULL;

return(head);

}

struct student *insert(struct student *head)

{

struct student *p0,*p1,*p2;

struct student *stud = (struct student *)malloc(sizeof(struct student));

printf("please input Student num:");

scanf("%ld%*c", &stud->num);

printf("please input Student name:");

scanf("%s", &stud->name);

printf("please input Student score1:");

scanf("%d", &stud->score1);

printf("please input Student score2:");

scanf("%d", &stud->score2);

printf("please input Student sex(m/w):");

scanf("%*c%c%*c", &stud->sex);

p0 = head;

while( p0->next ){

p0 = p0->next;

}

p0->next = stud;

stud->next = NULL;

return head;

}

struct student *delete(struct student *head,long num)

{

struct student *p1,*p2;

if(head==NULL)

{

printf("\nlist null!\n");

return NULL;

}

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("delete:%ld\n",num);

free(p1);

n--;

}

else

printf("%ld not been found!\n",num);

return(head);

}

void print(struct student *head)

{

struct student *p;

p=head;

if(head!=NULL)

{

printf("\n\n| Student Num | | Student Name | | Score1 | | Score2 | | sex |\n");

do{

printf("| %11ld | | %12s | | %6d | | %6d | | %c |\n",p->num,p->name,p->score1,p->score2,p->sex);

p=p->next;

}

while(p!=NULL);

}

else

printf("this is a NULL list");

}

struct student *find(struct student *head,long num)

{

struct student *p1,*p2;

if(head==NULL)

{

printf("\n list null!\n");

return NULL;

}

p1=head;

while(p1!=NULL&&p1->num!=num)

{

p1=p1->next;

}

if(p1!=NULL)

{

printf("Find:");

printf("Stu Num:%ld\nStu name:%s\nStu sco1:%d\nStu sco2:%d\nStu sex:%c\n",p1->num,p1->name,p1->score1,p1->score2,p1->sex);

}

else

printf("%ld not been found!\n",num);

return(head);

}

int main()

{

struct student *stud;

int menu();

while(1)

{

switch(menu())

{

case 1:

head=creat();

break;

case 2:

head = insert(head);

printf("\n\tcontinue!");

break;

case 3:

scanf("%d%*c",&num);

delete(head, num);

printf("\n\tcontinue!");

break;

case 4:

print(head);

printf("\n\tcontinue!");

getch();

break;

case 5:

printf("Please input find num:");

scanf("%d%*c",&num);

find(head, num);

printf("\n\tcontinue!");

getch();

break;

case 6:

clrscr();

case 7:

exit(0);

}

}

}

int menu()

{

char d[7];

int c;

printf("\n\n%16s"," ");

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

printf("\t\t1.creat list\n");

printf("\t\t2.insert list\n");

printf("\t\t3.delete list\n");

printf("\t\t4.print list\n");

printf("\t\t5.find list\n");

printf("\t\t6.clrscr\n");

printf("\t\t7.exit\n");

do{

printf("\n\tenter select(1-7): ");

gets(d);

c=atoi(d);

}

while(c<0||c>7);

return c;

}

- 13 -

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值