首页 > 代码库 > 用链表写的学生管理系统 成绩的录入与查询都已经是实现了
用链表写的学生管理系统 成绩的录入与查询都已经是实现了
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct teacher{ char name[32]; int math; int english; int data; struct Node *next;}SLIST;int Creat_SList();int SList_Print();int SList_SelectPrint(SLIST *pHead);int Creat_SList(SLIST **handle){ char name[32] = {0}; int flag = 0; int math = 0; int english = 0; int ret = 0; SLIST *pHead = NULL, *pCur = NULL, *pM = NULL; //先分配内存 pHead = (SLIST *)malloc(sizeof(SLIST)); if (pHead == NULL) { ret = -1; printf("func Creat_SList err ret=%d", ret); return ret; } pHead->data = http://www.mamicode.com/0;"func Creat_SList() err:%d malloc err", ret); return ret; } //char name[32] = { 0 }; printf("请输入学生的姓名 "); scanf("%s",name); strcpy(pM->name, name); //pM->name[] = name; printf("请输入学生数学成绩"); scanf("%d", &math); pM->math = math; printf("请输入学生英语成绩"); scanf("%d", &english); pM->english = english; printf("如果完成当前学生的编辑请输入 -1 若要继续输入学生信息 则输入 1 \n"); scanf("%d",&flag); pM->next = NULL; //让pM接在pCur的后面也就是说明pHead中是没有存储数据的而是一个 空的头结点 pCur->next = pM; pCur = pM; } *handle = pHead; return ret; //END:}int SList_Print(SLIST *pHead){ int ret = 0; SLIST *p = NULL; p = pHead->next;//bug if (pHead == NULL) { return -1; } printf("\nBegin "); //p = p->next; while (p) { //printf("%d\n", p->data); printf("学生的姓名 "); printf("%s\n", p->name); printf("学生数学成绩"); printf("%d\n", p->math); printf("学生英语成绩"); printf("%d\n", p->english); p = p->next; system("pause"); } printf("End "); return ret;}//对查询进行输出int SList_SelectPrint(SLIST *pHead){ int ret = 0; SLIST *p = NULL; p = pHead; if (pHead == NULL) { return -1; } printf("\nBegin "); { printf("您要查找的同学信息如下"); printf("学生的姓名 "); printf("%s\n", p->name); printf("学生数学成绩"); printf("%d\n", p->math); printf("学生英语成绩"); printf("%d\n", p->english); } printf("End "); return ret;}//对学生信息进行查找 需要打印查找结果int SList_Select(SLIST *pHead,char *name){ int ret = 0; int flag = 0; char myname[32] = { 0 }; SLIST *pCur; strcpy(myname, name); if (pHead == NULL) { int ret = -1; printf("SList_Insert err"); return ret; } //pCur = pHead->next; pCur = pHead->next; while (pCur) { //name 进行比较 第一个人可以进行正常查询但是不能 正常输出 if (strcmp(pCur->name, myname) == 0) { //这里判断是正确的 // SList_Print(pCur); SList_SelectPrint(pCur); flag = 1; break; } pCur = pCur->next; } if (flag == 0) { printf("查无此人查无此人查无此人查无此人"); } return ret;}//在x的出现位置插入yint SList_NodeInsert(SLIST *pHead, int x, int y);int SList_NodeInsert(SLIST *pHead, int x, int y){ int ret = 0; SLIST *pPre, *pCur, *pM; if (pHead == NULL) { int ret = -1; printf("SList_Insert err"); return ret; } pPre = pHead; pCur = pHead->next; //不断的malloc新节点数据域赋值 pM = (SLIST *)malloc(sizeof(SLIST)); pM->data = http://www.mamicode.com/y;"SList_Insert err"); return ret; } pM->next = pCur;//pPre->next; pPre->next = pM;//pPre = pM; return ret;}//删除 找到y并将它删除int SList_NodeDel(SLIST *pHead, int y){ int ret = 0; SLIST *pPre, *pCur; if (pHead == NULL) { int ret = -1; printf("SList_Insert err"); return ret; } pPre = pHead; pCur = pHead->next; while (pCur) { if (pCur->data =http://www.mamicode.com/= y)"没有找到节点 y:%d", y); return -2; } pPre->next = pCur->next;//pTemp = pPre->next; //pPre = pTemp; return ret;}void main(){ SLIST * pHead = NULL; int flag = 0; printf("------------------------学生管理系统-------------------------\n"); for (;;) { printf("如果要输入学生信息请输入: 1 \n"); printf("如果要查询学生信息请输入: 2 \n"); printf("如果要查询所有学生请输入: 3 \n"); scanf("%d", &flag); if (flag == 1) { Creat_SList(&pHead); } if (flag == 2) { printf("请输入要查询的人的名字"); char name[32] = { 0 }; scanf("%s", name); printf("s%",name); //进行查询并且打印结果 SList_Select(pHead,name); } if (flag == 3) { SList_Print(pHead); } printf("----------------------------------------------------------"); system("pause"); } //printf("\n"); //SList_Select(pHead, "han"); //system("pause");}
用链表写的学生管理系统 成绩的录入与查询都已经是实现了,码迷,mamicode.com
用链表写的学生管理系统 成绩的录入与查询都已经是实现了
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。