用C语言实现的学生管理系统
来源:互联网 发布:网易邮箱大师mac版 编辑:程序博客网 时间:2024/05/16 11:35
用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->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;}
阅读全文
0 0
- 用C语言实现的学生管理系统
- 用C语言实现 坐标管理系统(类似于学生管理系统的功能)
- C语言实现学生管理系统
- 学生管理系统C语言实现
- c语言实现的简单学生管理系统
- 我的C语言学生管理系统!
- 基于C语言的学生管理系统
- 用C语言写的学生管理系统
- 用c++语言实现学生管理系统
- C语言学生管理系统
- 学生管理系统(c语言)
- 学生管理系统c语言
- C语言学生管理系统
- C语言学生管理系统
- 学生管理系统 c语言
- c语言实现的学生信息管理系统
- c语言 学生管理系统(数组实现)
- C语言 学生管理系统(结构体实现)
- Ubuntu交叉编译U-boot
- [ACM]CCF CSP [201612-5]E题 卡牌游戏【75分的程序】
- 【OneNote 小技巧】——利用OneNote进行录音和录像
- MySQL与Oracle 差异比较之二基本语法
- Leetcode 107
- 用C语言实现的学生管理系统
- 插入排序
- ROS消息的创建
- course 系统1.2
- KMP算法 (c++ 构造完整的DFA)
- 递归
- Exchange Seats
- 勾股定理及其逆定理的一种简单证明方法
- 线程、进程和通信