c语言小项目——学生信息管理系统

学生信息管理系统

原理是使用链表和动态内存分配来实现间断输入却可以将它们连接在一起的功能。

然后再使用头结点可以从头开始遍历这整个链表,然后就可以访问其中的所有成员

功能:

  1. 交互菜单界面。
  2. 录入、浏览、删除、退出系统功能函数。
  3. 使用死循环和break语句实现特定输入的结束程序运行和不断的显示菜单功能。

头文件

//#include <iostream>
using namespace std;
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//抽象出来一个学生的信息
//使用数据结构需要先分析然后写正确 
typedef struct student
{
	char name[20];
	int age;
	char sex[5];
	char tel[20];
}student;
struct Node 
{
	//int data;
	student data;
	struct Node *next;
 }; 
struct Node *creatlist()
{
	//动态申请内存然后将头指针置为空指针 
	struct Node* headNode = (struct Node*)malloc(sizeof(struct Node)); 
	//表头的初始化处理 也可以加上数据,但没必要 
	headNode->next = NULL;
	return headNode;
}
//创建节点 
struct Node *createNode(student data)
{
	struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
	newNode->data = data;
	newNode->next = NULL;
	return newNode;
}
//头节点插入法 
void insertnode(struct Node *headNode, student data)
{
	struct Node *newNode = createNode(data);
	//表头法
	newNode->next = headNode->next;
	headNode->next = newNode; 
 } 
 //链表的删除
 void deleteNode(struct Node *headNode, char *name)
 {
 	//删除名字 
 	struct Node *posNode = headNode->next;
 	struct Node *posFrontNode = headNode;
 	if(posNode == NULL)
 	{
 		printf("数据为空无法删除\n");
 		return ;
	 }
 	while(strcmp(posNode->data.name,name) != 0)
 	{
 		posFrontNode = posNode;
 		posNode = posFrontNode->next;
 		if(posNode == NULL)
 		{
 			printf("未找到指定位置无法删除!\n");
		 }
	 }
	 posFrontNode->next = posNode->next;
	 free(posNode);
  } 
//打印链表
void printlist(struct Node *headNode)
{
	struct Node* pMove = headNode->next;
	printf("Name:\t\tage:\t\tsex\t\ttel:\n");
	while(pMove)
	{
		printf("%s\t\t%d\t\t%s\t\t%s\n",pMove->data.name,pMove->data.age,pMove->data.sex,pMove->data.tel);
		pMove = pMove->next;
	}
	printf("\n");
}
 //查找功能
struct Node* searchbydata(struct Node *headNode, char *name)
 {
 	struct Node* pMove = headNode->next;
 	if(pMove == NULL)
 	return NULL;
 	while(strcmp(pMove->data.name,name) != 0)
 	{
 		pMove = pMove->next;
	 }
	 return pMove;
  } 

源代码

/*
	1.界面
	2.数据结构的设计
	3.交互
	#define _CRT_SECURE_NO_WARNINGS//用于取消VS中的scanf_s的警告语句
*/
#include <stdio.h>
#include <stdlib.h>
#include "mylist.h"
/*
	抽象出来一个学生的信息
	使用数据结构需要先分析然后写正确
*/
void menu();//页面函数
int keydown(); //菜单函数
struct Node* list = creatlist();
int main()
{
	int flag;
	while(1)
	{
		menu();
		flag = keydown();
		if(flag == 1)
		{
			system("pause");
			system("cls");
		}
		else
			goto end;
	}
	//system("pause");(_ 使用VS时请取消该注释)
end:
	return 0;
}
void menu()
{
	//菜单页面
	printf("___________________[学生信息管理系统]___________________________\n");
	printf("\t\t0.退出系统\n");
	printf("\t\t1.录入信息\n");
	printf("\t\t2.浏览信息\n");
	printf("\t\t3.删除信息\n");
	printf("\t\t4.查找信息\n");
	printf("———————————————————————\n");
}
int keydown()
{
	int choice  = 0;
	char name_d[30], name_f[30];
	struct student data;
	printf("请输入相应的数字(请勿输入字符)\n");
	scanf("%d",&choice);
	switch(choice)
	{
		case 0:
			printf("正常退出!n");
			//system("pause");(_ 使用VS时请取消该注释)
			return 0;
		case 1:
			printf("-----------录入信息-----------\n");
			printf("请输入学生姓名:");
			scanf("%s",data.name);
			printf("请输入年龄:");
			scanf("%d",&data.age);
			getchar();
			printf("请输入性别:");
			scanf("%s",data.sex);
			printf("请输入电话:");
			scanf("%s",data.tel);
			insertnode(list,data);
			return 1;
		case 2:
			printf("-----------浏览信息-----------\n");
			printlist(list);
			return 1;
		case 3:
			printf("-----------删除信息-----------\n");
			printf("请输入你要删除的姓名:");
			scanf("%s",name_d);
			deleteNode(list,name_d);
			return 1;
		case 4:
			printf("-----------查找信息-----------\n");
			printf("请输入你要查找的姓名:");
			scanf("%s",name_f);
			searchbydata(list,name_f);
			return 1;
		default:
		{
			printf("选择错误,请重新输入!\n");
			return 1;
		}
	}
}

此程序并不完善,待我后续继续完善。可以实现正确的

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值