栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言学生管理系统

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言学生管理系统

#include 
#include 
#include 
#include 

typedef struct Student{
	char name[20];
	int  age;
	int  stunum;
	int  score;
}Student;
typedef struct LNode{
    Student stu;
    LNode* Next;
}LNode;

LNode* Ptrl = NULL;

void Panel();
void Input();
void Printout();
void Find();
void Modify();
void Delete();
void Count();
void Save();
void Read();

int main()
{
	while(1){
		Panel();
		char cmp = getch();
		switch (cmp){
			case '1':
				Input();
				break;
			case '2':
				Printout();
				break;
			case '3':
				Find();
				break;
			case '4':
				Modify();
				break;
			case '5':
				Delete();
				break;
			case '6':
				Count();
				break;
			case '7':
				Save();
				break;
			case '8':
				Read();
				break;
			case '0':
				printf("The system is over!n");
				return 0;
		}
	}
	return 0;
}

void Panel()
{
	printf("***********************n");
	printf("******功能清单如下*****n");
	printf("*** [1]录入学生信息 ***n");
	printf("*** [2]打印学生信息 ***n");
	printf("*** [3]查找学生信息 ***n");
	printf("*** [4]修改学生信息 ***n");
	printf("*** [5]删除学生信息 ***n");
	printf("*** [6]统计学生人数 ***n");
	printf("*** [7]保存学生信息 ***n");
	printf("*** [8]读入学生信息 ***n");
	printf("*** [0]退出学生系统 ***n");
	printf("***********************n");
}


void Input()
{
	LNode* p = (LNode*)malloc(sizeof(LNode));
	p->Next  = NULL;
	if(Ptrl == NULL){
		Ptrl = p;
	}
	else{
		p->Next = Ptrl;
		Ptrl    = p;
	}
    printf("Please input student's name:n");
    scanf("%s",p->stu.name);
    printf("Please input student's age:n");
    scanf("%d",&p->stu.age);
    printf("Please input student's studentnumber:n");
    scanf("%d",&p->stu.stunum);
    printf("Please input student's score:n");
    scanf("%d",&p->stu.score);
    printf("The operation is finished.n");
    system("pause");
    system("cls");
}

void Printout()
{
	LNode* p = Ptrl;
	if(p != NULL){
		while(p != NULL){
		printf("**************************************n");
		printf("nametagetstudentnumbertscoren");
		printf("%st%dt%dtt%dn",
			p->stu.name,
			p->stu.age,
			p->stu.stunum,
			p->stu.score);
		p = p->Next;
		}
		printf("**************************************n");
	}
	else{
		printf("Empty!n");
	}
	system("pause");
	system("cls");
}

void Find()
{
	char name[20];
	int stunum;
	LNode* p=Ptrl;

	printf("Please input the name of the student which you want to find.n");
	scanf("%s",name);
	printf("Please input the studentnumber of the student which you want to find.n");
	scanf("%d",&stunum);
	while(p != NULL){
		if(p->stu.stunum == stunum || 0 ==strcmp(p->stu.name,name)){
			printf("nametagetstudentnumbertscoren");
			printf("%st%dt%dtt%dn",
				p->stu.name,
				p->stu.age,
				p->stu.stunum,
				p->stu.score);
				break;
		}
		p = p->Next;
	}
	if(p == NULL){
		printf("This information does not exist.n");
	}
	system("pause");
	system("cls");
}

void Modify()
{
	int stunum;
	LNode* p = Ptrl;
	
	printf("Please input the studentnumber of the student which you want to modify.n");
	scanf("%d",&stunum);
	while(p != NULL){
		if(p->stu.stunum == stunum){
			printf("The changed name:n");
			scanf("%s",p->stu.name);
			printf("The changed studentname:n");
			scanf("%d",&p->stu.stunum);
			printf("The changed score:n");
			scanf("%d",&p->stu.score);
			break;
		}
		p = p->Next;
	}
	if(p == NULL){
		printf("This information does not exist.n");
	}
	system("pause");
	system("cls");
}

void Delete()
{
	int stunum;
	LNode* d1;
	LNode* d2;
	
	printf("Please input the studentnumber of the student which you want to delete.n");
	scanf("%d",&stunum);
	if(Ptrl->stu.stunum == stunum){
		d1 = Ptrl;
		Ptrl = Ptrl->Next;
		free(d1);
		printf("The operation is finished.n");
		system("pause");
		system("cls");
	}
	else{
		LNode*	p = Ptrl;
		while(p->Next != NULL){
			if(p->Next->stu.stunum == stunum){
				d2 = p->Next;
				p->Next = p->Next->Next;
				free(d2);
				printf("The operation is finished.n");
			}
		}
		if(p == NULL){
			printf("This information does not exist.n");
		}
		system("pause");
		system("cls");
	}
}

void Count()
{
	LNode* p = Ptrl;
	int count=0;
	
	while(p != NULL){
		p = p->Next;
		count++;
	}
	printf("The total number of the students is %dn",count);
	system("pause");
	system("cls");
}

void Save()
{
	FILE* fp = fopen("D:\text2.txt","w");
	LNode* p;
	
	if(fp == NULL){
		printf("Failed to open file.n");
		system("pause");
		system("cls");
		return;
	}
	p = Ptrl;
	while(p != NULL){
		fwrite(&p->stu,sizeof(Student),1,fp);
		p = p->Next;
	}
	fclose(fp);
	printf("Data is successfully saved.n");
	system("pause");
	system("cls");
}

void Read()
{
	FILE* fp = fopen("D:\text2.txt","r");
	LNode* p;
	
	if(fp == NULL){
		printf("Failed to open file.n");
		system("pause");
		system("cls");
		return;
	}
	Student stu;
	while(fread(&stu,sizeof(Student),1,fp)){
		p = (LNode*)malloc(sizeof(LNode));
		p->Next == NULL;
		memcpy(p,&stu,sizeof(Student));
	}
	if(Ptrl == NULL){
		Ptrl = p;
	}
	else{
		p->Next = Ptrl;
		Ptrl = p;
	}
	fclose(fp);
	printf("Data is successfully loaded.n");
	system("pause");
	system("cls");
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/849370.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号