#include"stdlib.h" #include"stdio.h"
struct stud {char name[20]; long num;
float score; float score_1; float score_2; float score_3; struct stud *next; }; struct stud *head, *this, *new; main() { char ch; int flag=1; head=NULL; printf("***************************************************************\n"); printf("| -> welcome to use ! <- |\n"); printf("| |\n"); printf("| All rights resevered 03101 Huang wenmin |\n"); printf("********* Http://elian.hbisp.com **********\n");
while(flag) {
printf(" ---------------------------------------------------------------\n"); printf(" 1.Add new information. 2.List all information. \n"); printf(" 3.Delete a student's record . 4.Quit. \n"); printf("---------------------------------------------------------------\n"); printf("Type the fist letter of the item to choose.And the press Enter.\n"); ch=getchar();getchar(); switch(ch) { case'a': case'A':new_record();break; case'l': case'L':listall();break; case'd': case'D':del_record();break; case'q': case'Q':exit(0);break; default:flag=0; } } }
new_record(void) /*输入信息*/ { char numstr[20]; new=(struct stud *) malloc (sizeof (struct stud)); if(head==NULL) head=new; else {this=head; while (this->next!=NULL) this=this->next; this->next=new; } this=new; printf("\nenter name:"); gets(this->name); printf("\nenter number:"); gets(numstr); this->num=atol(numstr); printf("\nEnter Enlish score:"); gets(numstr); this->score=atof(numstr); printf("\nEnter Chinese score:"); gets(numstr); this->score_1=atof(numstr); printf("\nEnter Computer score:"); gets(numstr); this->score_2=atof(numstr); printf("\nEnter Mathimatics score:"); gets(numstr); this->score_3=atof(numstr); this->next=NULL;
}
listall(void) /*列出已记录的信息*/ {int i=0; if(head==NULL) {printf("\I am sorry,but the list is nempty list.:P \n\n\n");
return; } this=head; do{ printf("\nrecord number %d\n",++i); printf("name:%s\n",this->name); printf("num:%ld\n",this->num); printf("Enlish score:%6.2f\n",this->score); printf("Chinese score:%6.2f\n",this->score_1); printf("Computer score:%6.2f\n",this->score_2); printf("Mathimatics score:%6.2f\n",this->score_3); this=this->next; }while(this!=NULL); } del_record(void) /*删除信息*/ { if(head==NULL) printf("no found!\n\n\n"); /*如果链表头为空则返回*/
else { char *p,*p1;/*一个指向输入的学生名,另一个指向结构中的学生名*/ int s;/*比较字符结果,相等为0,不等为其它数*/ printf("enter name to del:\n"); scanf("%s",p); this=head; new=NULL; do { p1=this->name; if( !( s=strcmp(p,p1) ) ) /*如果比较相等,则跳出循环*/ break; new=this;/*保存上一个结构指针*/ this=this->next;/*指向下一个结构*/ } while ( NULL != this->next ); if( !(new)) head=this->next;/*如果头结点为要删除的学生,将下一个结点作为头结点*/ else if( !(this->next=NULL) ) /*如果是最后一个结点为要删除的学生*/ new->next=NULL; else new=this->next;/*将上一个结点指为本节点的下一个结点*/ printf("deled successfully!\n\n\n"); } } 上周在这里求这个程序:
用链表实现学生成绩管理系统
2。能查询学生各科成绩;
3。能修改学生各科成绩;
4。删除学生成绩;
5。退出程序。
jiely的回复是:
可以给你个参考的程序,呵呵~,不过要帮你写,可能大家都没有时间吧~~~~~,大家可以帮你修改程序,但不是代劳~ |
那现在偶完成了些,可有个问题需要修改,就是在运行完删除命令后,再运行其他,怎么就马上退出程序了啊?帮忙修改一下?
修改个人成绩的函数怎么写啊,我写不来,帮一下可以吗
[此贴子已经被作者于2004-06-10 23:14:22编辑过]