C语言学生信息管理系统在(多文件系统)

一、实验目的
 

本实验的目的是通过实现一个学生信息管理系统,综合运用C语言中的数据类型、函数、文件操作等知识,提高对C语言的理解和掌握能力。

二、功能需求 

  1. 制作一个学生信息管理系统。
  2. 在制作的系统中,能录入学生信息、删除学生信息、修改学生信息,查询学生信息、排序学生信息。
  3. 系统使用方法便捷,简单,功能容易实现。
  4. 学生的信息包括:学号、姓名、班级、性别、英语成绩,C语言成绩,平均成绩,总成绩
  5. 避免系统bug的出现,优化系统。

三.功能说明 


添加学生信息:将学生的信息输入到学生信息管理系统中。

删除学生信息:将学生信息管理系统中不需要的学生信息删除。

修改学生信息:在学生信息管理系统中修改学生的部分信息。

查询学生信息:在学生信息管理系统中输入需求显示查询结果。

显示学生信息:在学生信息管理系统中按需求显示所有学生信息。

排序学生信息:按一定规律对学生信息进行排序。

学生存档并退出:保存操作结果并退出系统。

四.构造算法框架

  1.构造功能框架

#include <stdio.h>
#include <stdlib.h>
#include "student.h"
struct node*phead=NULL;
int count = 0;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void createHeadNode();
void createFace();
void initData(struct node * phead);
void addNewNode(struct node * phead);
void deleteNode(struct node * phead);
void searchNode(struct node * phead);
void updateNode(struct node * phead);
void showAllInfo(struct node * phead);
void info_output(struct node * pfind);
void fushData(struct node * phead); 
 
int main(int argc, char *argv[]) {
	createHeadNode();
	createFace();
	return 0;
}

 2.设计系统目录

void createFace(){
	int a=0; 
	initData(phead);
	printf("当前文件中有%d条学生信息\n",count);
	printf("\t\t\t欢迎使用学生信息管理系统\n");
	printf("\t\t----------1.添加学生信息----------\n");
	printf("\t\t----------2.删除学生信息----------\n");
	printf("\t\t----------3.查询学生信息----------\n");
	printf("\t\t----------4.修改学生信息----------\n");
	printf("\t\t----------5.显示学生信息----------\n");
	printf("\t\t----------6.排序与统计  ----------\n");
	printf("\t\t-------7.学生信息存档并退出-------\n");
}

运行结果 :

五.在框架的基础上一一实现各项功能  

1. 录入学生信息:将学生的信息输入到学生信息管理系统中,并保存到文件中。

void addNewNode(struct node * phead){
	struct node * pnew = NULL;
	struct node * pfind =phead;
	while (pfind->pnext!=NULL){
		pfind =pfind->pnext;
	}
	pnew = (struct node *)malloc(sizeof(struct node));
	pnew->data.ave=0;
	pnew->data.total=0;
	printf("请输入学号:\n");
	scanf("%d",&pnew->data.num);
	
	printf("请输入姓名:\n");
	scanf("%s",pnew->data.name);
	
	printf("请输入数学成绩:\n");
	scanf("%f",&pnew->data.Math);
		pnew->data.total +=pnew->data.Math;
		
	printf("请输入语文成绩:\n");
	scanf("%f",&pnew->data.Chinese);
        pnew->data.total +=pnew->data.Chinese;
	
	printf("请输入英语成绩:\n");
	scanf("%f",&pnew->data.English);
	    pnew->data.total +=pnew->data.English;
	    
	    pnew->data.ave=pnew->data.total / 3.0;
	    
	    pnew->pnext =NULL;
	    pfind->pnext =pnew;
	    
	    printf("%s同学的信息添加成功\n",pnew->data.name);
	
}

运行结果

2.删除学生信息:将学生信息管理系统中不需要的学生信息删除,在删除完成后需将学生人数进行减一。

void deleteNode(struct node * phead){
	int num = 0;
	struct node * target = NULL;
	struct node * pfind = phead;
	struct node * ptemp;
	printf("请输入您想删除学生的学号\n");
	scanf("%d",&num);
	target =  findTheNode(phead,num);
	if (target ==NULL){
		printf("对不起,查无此记录\n");
		return;
	}
	else{
		ptemp = target ->pnext;
		while(pfind->pnext != target){
			pfind = pfind->pnext;
		}
		free(target);
		target = NULL;
		pfind->pnext = ptemp;
		printf("删除成功\n");
	}
}

运行结果:

3.查询学生信息:在学生信息管理系统中输入需求显示查询结果。

void searchNode(struct node * phead){
	int num = 0;
	struct node * target = NULL;
	printf("请输入您想查找学生的学号\n");
	scanf("%d",&num); 
	target = findTheNode(phead,num);
	if(target ==NULL){
		printf("查无此人\n");
	}
	else{
		info_output(target);
	}
}

运行结果:

4.修改学生信息:在学生信息管理系统中修改学生的部分信息。

void updateNode(struct node * phead){
	int num = 0;
	struct node * target = NULL;
	printf("请输入您想修改学生的学号\n");
	scanf("%d",&num); 
	target = findTheNode(phead,num);
	if(target ==NULL){
		printf("查无此人\n");
	}
	else{
	target->data.ave=0;
	target->data.total=0;
		printf("请输入学号:\n");
	scanf("%d",&target->data.num);
	
	printf("请输入姓名:\n");
	scanf("%s",target->data.name);
	
	printf("请输入数学成绩:\n");
	scanf("%f",&target->data.Math);
		target->data.total +=target->data.Math;
		
	printf("请输入语文成绩:\n");
	scanf("%f",&target->data.Chinese);
        target->data.total +=target->data.Chinese;
	
	printf("请输入英语成绩:\n");
	scanf("%f",&target->data.English);
	    target->data.total +=target->data.English;
	    
	    target->data.ave=target->data.total / 3.0;
	    
	    printf("修改成功!\n");
	    info_output(target);
	}
}

运行结果:

5.显示学生信息:在学生信息管理系统中按需求显示所有学生信息。

void info_output(struct node * pfind){
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("学号:%d\t姓名:%s\t数学:%.2f\t语文:%.2f\t英语:%.2f\t平均分:%.2f\t总分:%.2f\t\n",pfind->data.num,pfind->data.name,pfind->data.Math,pfind->data.Chinese,pfind->data.English,pfind->data.ave,pfind->data.total);
    }

运行结果:

6.排序学生信息:按一定规律对学生信息进行排序。

void sortNodeByTotal(struct node * phead){//根据选择排序 
	struct node *pfind1=phead->pnext;
	struct node *pfind2=phead->pnext;
	float max;
	struct node *p=NULL;
	struct student replace;
	while (pfind1 !=NULL){
		max=pfind1->data.total;
		p = pfind1;
		for (pfind2 = pfind1->pnext; pfind2 != NULL;pfind2 = pfind2->pnext){
			if(max<pfind2->data.total){
				max = pfind2->data.total;
				p = pfind2;
			}
		}
		p->data.total = pfind1->data.total;
		pfind1->data.total = max;
		
		replace.num = p->data.num;
		p->data.num = pfind1->data.num;
		pfind1->data.num = replace.num;
		
		strcpy(replace.name, p->data.name);
		strcpy(p->data.name, pfind1->data.name);
		strcpy(pfind1->data.name, replace.name);
		
		replace.Math = p->data.Math;
		p->data.Math = pfind1->data.Math;
		pfind1->data.Math = replace.Math;
		
		replace.Chinese = p->data.Chinese;
		p->data.Chinese =pfind1->data.Chinese;
		pfind1->data.Chinese = replace.Chinese;
		
		replace.English = p->data.English;
		p->data.English = pfind1->data.English;
		pfind1->data.English = replace.English;
		
		replace.ave = p->data.ave;
		p->data.ave = pfind1->data.ave;
		pfind1->data.ave = replace.ave;
		
		pfind1 = pfind1->pnext;
	}
	printf("排序完成\n");
	showAllInfo(phead);
}

运行结果:

六、实验总结

通过这次实验,我们不仅掌握了学生管理系统的设计和实现方法,还培养了团队合作和问题解决的能力。我们意识到软件开发不仅仅是编写代码,还需要仔细思考用户需求,设计合理的系统架构,并通过测试和调试来验证和改进系统。这些经验对于我们今后的学习和工作都具有重要的意义。

  • 34
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值