用C语言实现的学生管理系统
2017-10-14 19:47
591 查看
用C语言实现的学生管理系统
可以输入学生的学号,姓名,年龄,年级;
可以输入学生的学号,姓名,年龄,年级;
插入学生信息,默认插入到第一个
通过学号,对学生进行排序
由于自己学C语言指针时,不太认真,所以有这个作业时,遇到了很多困难,不过最后还是写出来了,很高兴
可以输入学生的学号,姓名,年龄,年级;
可以输入学生的学号,姓名,年龄,年级;
插入学生信息,默认插入到第一个
通过学号,对学生进行排序
由于自己学C语言指针时,不太认真,所以有这个作业时,遇到了很多困难,不过最后还是写出来了,很高兴
#include <stdio.h> #include <stdlib.h> #include<malloc.h> #include<string.h> struct student *head; typedef struct student{ char sno[10]; char name[10]; int sage; int grade; struct student *next; }; //链表初始化 struct student * create(int n){ struct student *h,*m,*q; h=(struct student*)malloc(sizeof(struct student)); m=h; int i=1; for(i=1;i<=n;i++){ q=(struct student*)malloc(sizeof(struct student)); scanf("%s%s%d%d",q->sno,q->name,&q->sage,&q->grade); m->next=q; m=m->next; } m->next=NULL; return h; } //删除学生信息 struct student * del(head){ struct student *p; p=(struct student*)malloc(sizeof(struct student)); p=head; char out[10]; printf("请输入要删除学生姓名的学号\n"); scanf("%s",out); while(p->next!=NULL&&strcmp(out, (p->next)->sno) != 0){ p=p->next; } p->next=(p->next)->next; return head; } //打印学生信息 void print(head){ struct student *p; p=(struct student*)malloc(sizeof(struct student)); p=head; while(p->next!=NULL){ printf("%s %s %d %d\n",(p->next)->sno,(p->next)->name,(p->next)->sage,(p->next)->grade); p=p->next; } } //插入学生信息 struct student* insert(head){ struct student *q,*p; q=(struct student*)malloc(sizeof(struct student)); p=(struct student*)malloc(sizeof(struct student)); //q->next=(struct student*)malloc(sizeof(struct student)); p=head; printf("请输入要插入的学生信息\n"); scanf("%s %s %d %d",q->sno,q->name,&q->sage,&q->grade); q->next=p->next; p->next=q; return head; } //查找学生信息 struct student * search(head){ struct student *p; p=(struct student*)malloc(sizeof(struct student)); p=head; char out[10]; printf("请输入要查找的学生姓名的学号\n"); scanf("%s",out); while(p->next!=NULL&&strcmp(out, (p->next)->sno) != 0){ p=p->next; } printf("学号,姓名,年龄,年级\n"); printf("%s%s%d%d",p->next->sno,p->next->name,p->next->sage,p->next->grade); //p->next=(p->next)->next; return head; } //排序学生信息 struct student * sort(head){ struct student *p,*temp,*q,*h; p=(struct student*)malloc(sizeof(struct student)); temp=(struct student*)malloc(sizeof(struct student)); q=(struct student*)malloc(sizeof(struct student)); h=(struct student*)malloc(sizeof(struct student));; //p=head->next; //min=p->next; // //p=temp; h=head; head=q; while(h->next!=NULL){ p=h->next; temp=h; while(p->next!=NULL){ if(strcmp((p->next)->sno,(temp->next)->sno)<0){ temp=p; //暂时最小的前一个节点 } p=p->next; } //printf("%s",(temp->next)->sno); q->next=temp-& 4000 gt;next; temp->next=(temp->next)->next; q=q->next; } return head; }; int main() { int n; int i; int j=1; printf("请输入学生个数\n"); scanf("%d",&n); printf("学号 姓名 年龄 年级\n"); head=(struct student*)malloc(sizeof(struct student)); head=create(n); printf("1删除信息 2插入信息 3查找信息 4排序信息 5打印信息\n"); while(j){ scanf("%d",&i); switch(i){ case 1:{head=del(head);break;} case 2:{head=insert(head);break;} case 3:{head=search(head);break;} case 4:{head=sort(head);break;} case 5:{print(head);break;} } } return 0; }
相关文章推荐
- linux终端版学生信息管理系统【C语言实现】
- Linux环境下C语言实现简单的基于文件的学生信息管理系统
- (一个代码学会c语言操作数据库)linux上通过c语言操作数据库实现基本的学生信息管理系统(增、删、查、改‘显示)
- C语言实现---学生成绩管理系统
- C语言利用结构体数组实现学生成绩管理系统
- C语言使用链表实现学生信息管理系统
- 基于C语言实现学生成绩管理系统
- C语言实现学生信息管理系统
- C语言实现——学生管理系统
- 学生成绩管理系统课程设计(C语言,链表实现)
- c语言实现学生档案管理系统
- linux的学生管理系统——C语言命令行实现
- c语言使用链表编写一个可以实现班级学生管理系统,增加,删除,修改学生信息
- C语言实现学生管理系统
- c语言实现的学生信息管理系统
- C语言实现学生信息管理系统(单链表)
- 用C语言关于学生管理系统的几种实现方法(一位数组,二维数组,指针,结构体)
- C语言实现学生信息管理系统
- C语言实现学生成绩管理系统
- C语言数组实现学生信息管理系统设计