zoukankan      html  css  js  c++  java
  • 用链表写的学生管理系统 成绩的录入与查询都已经是实现了

    #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 = 0;
    	pHead->next = NULL;
    //这里让当前节点等于头节点
    	pCur = pHead;
    	while (flag != -1)
    	{
    		pM = (SLIST *)malloc(sizeof(SLIST));
    		if (pM == NULL)
    		{
    			//SList_Destory(pHead);
    			ret = -2;
    			printf("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  
    ");
    		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("
    Begin ");
    	//p = p->next;
    	while (p)
    	{
    		//printf("%d
    ", p->data);
    		printf("学生的姓名   ");
    		printf("%s
    ", p->name);
    
    		printf("学生数学成绩");
    		printf("%d
    ", p->math);
    
    		printf("学生英语成绩");
    		printf("%d
    ", 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("
    Begin ");
    	{
    
    		printf("您要查找的同学信息例如以下");
    		printf("学生的姓名   ");
    		printf("%s
    ", p->name);
    
    		printf("学生数学成绩");
    		printf("%d
    ", p->math);
    
    		printf("学生英语成绩");
    		printf("%d
    ", 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的出现位置插入y
    int 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 = y;
    	pM->next = NULL;
    
    	while (pCur)
    	{
    		if (pCur->data == x)
    		{
    			break;
    		}
    		pPre = pCur;
    		pCur = pCur->next;
    	}
    
    	if (pM == NULL)
    	{
    		ret = -2;
    		printf("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 == y)
    		{
    			break;
    		}
    		pPre = pCur;
    		pCur = pCur->next;
    	}
    	if (pCur == NULL)
    	{
    		printf("没有找到节点 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("------------------------学生管理系统-------------------------
    ");
    	for (;;)
    	{
    		printf("假设要输入学生信息请输入: 1  
    ");
    		printf("假设要查询学生信息请输入: 2  
    ");
    		printf("假设要查询全部学生请输入: 3  
    ");
    		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("
    ");
    	//SList_Select(pHead, "han");
    	//system("pause");
    }

  • 相关阅读:
    Globus Toolkit 4.0正式版发布
    五四爱国纪念歌——最早反映五四运动的歌曲(zz)
    历史上的昨天和今天(zz)
    苹果:2.7GHz G5比3.6GHz P4快98%(zz)
    上海地铁又有人跳轨……
    使用IPAddress解析IP地址时要注意的问题
    WinHEC:电脑硬件和微软OS发展历程展(zz)
    emplace_back与push_back方法的区别
    处理Excel,填充空白区域
    折腾词库,一个词库互转程序
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5218451.html
Copyright © 2011-2022 走看看