⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stu_info_7.8.c

📁 linux 下的学生管理系统 非常值得学习的不可或缺的资源!!!!
💻 C
📖 第 1 页 / 共 4 页
字号:
/***************************************************
*工程名:学生信息管理系统
*作者:Min Hu
*日期:2008-6-10----2008-7-9
****************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <conio.h>
#include <time.h> 
#include <ctype.h>
#include <io.h>
#include <direct.h>
#define VERSION		 	" Ver 1.0 "
#define AUTHER	 	 	" Auther: Min Hu "
#define EMAIL           " email:humin1102@126.com"
#define TITLE           " Student Information Manager System "
#define WELCOME	 		" Welcome to you! "
#define MESSAGE	 	 	" Message "
#define MENULIST	 	" Menu List "
#define ADDINFO	 	    " Add student's info "
#define SORTDATA	 	" Sort data "
#define PRINTDATA  	 	" Print student's report "
#define SAVE		 	" Save data to file "
#define LOAD		 	" Load data from file "
#define SEARCH		 	" Search students "
#define UPDATE		 	" Update students Information"
#define STATSCORE	 	" Stat Score "
#define MAXCOUNT	 100
//全局变量
char ch;
int count=0;
int sno[MAXCOUNT]={0};
float total[MAXCOUNT];
double avg[MAXCOUNT];
int save_flag=0; //记录保存点
struct students
{
	char sno[4];
	char name[21];
	int age; 
	float score[5];
};
struct LINK
{
	struct students studate;
	struct LINK *next;
};
typedef struct students STU;
typedef struct LINK  INFO;
INFO *head=NULL,*last=NULL;
INFO stu_link;
STU data,stu[100];

/*用户自定义函数*/
void InsertData(STU studate);
void Gotoxy(x,y);
void Getxy(int *x,int *y);
void SetColor(int FontColor,int BackGroundColor) ;
void  Time();
void Welcome();
void MakeMenuInfo();
int JuZhong(dest,n);
void MenuList();
void ClearMessage();
void InputError(int x,int y,char ch);
void AddInfo();
int GetString(char buffer[],int maxlen);
void Left_Right(char temp[]);
void AddSno();
void AddName();
void AddAge();
void AddScore();
void PrintData();
void SortData();
void Sort_Print_Message();
void SortSnoAsc();
void SortSnoDesc();
void SortNameAsc();
void SortNameDesc();
void SortTotalAsc();
void SortTotalDesc();
void Exit_Save();
void Exit_System();
void SearchData();
void SearchSno();
void SearchName();
void UpdateData(int num,int x,int y);
void DeleteData(int num,int x,int y);
void SaveData();
char *Getfilename(char fname[100],char file[20]);
void LocalData();
void Stat();
void StatScore(int num);
void StatTotal();
/*****************************************************************
***函数名:InsertData 光标函数
***参数:INFO stu_info
***功能:插入数据
***返回值:无
*****************************************************************/	
void InsertData(STU studate)
{
	INFO *p;
	p=NULL;
	p=(INFO *)malloc(sizeof(INFO));
	if(p==NULL)
	{
		printf("Error!Out of memory!");
		exit(0);
	}
	p->studate=studate;
	p->next=NULL;
	if(head==NULL)
	{
		head=p;
	}
	else
	{	
		last->next=p;
	}
	last=p;
}
/*****************************************************************
***函数名:Gotoxy  光标函数
***参数:int x, int y
***功能:获取光标位置
***返回值:无
*****************************************************************/	
void Gotoxy(int x, int y)
{
	COORD pos = {x,y};
	HANDLE hOutPut = GetStdHandle(STD_OUTPUT_HANDLE);// 获取句柄
	
	SetConsoleCursorPosition(hOutPut, pos);  //设置句柄
}
/*****************************************************************
***函数名:Getxy  光标函数
***参数:int *x, int *y
***功能:记录当前位置坐标
***返回值:无
*****************************************************************/	
void Getxy(int *x,int *y)
{
	HANDLE hOutPut;	// 获取句柄
	CONSOLE_SCREEN_BUFFER_INFO Stu_Info;
	COORD pos;
	hOutPut= GetStdHandle(STD_OUTPUT_HANDLE);
   	GetConsoleScreenBufferInfo(hOutPut, &Stu_Info);	
	pos = Stu_Info.dwCursorPosition;
	*x = pos.X;
	*y = pos.Y;
}
/*****************************************************************
***函数名:SetColor  
***参数:int FontColor,int BackGroundColor
***功能:设置VC控制台字体和背景颜色
***返回值:无
*****************************************************************/		
void SetColor(int FontColor,int BackGroundColor)                                                                                                           //可以接受0/1/2个参数
{
	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hCon,(unsigned short)(FontColor|BackGroundColor));
}
/*****************************************************************
***函数名:Time  
***参数:无
***功能:显示系统动态时间
***返回值:无
*****************************************************************/	
void  Time()
{ 
	time_t t=time(NULL); 
	Gotoxy(53,24);
	puts(asctime(localtime(&t))); 
} 
/*****************************************************************
***函数名:Welcome
***参数:无
***功能:欢迎界面
***返回值:无
*****************************************************************/	
void Welcome()
{
	int i;
	Gotoxy(23,5);
	printf(TITLE);
	Gotoxy(28,7);
	printf(EMAIL);
	Gotoxy(32,8);
	printf(AUTHER);	
	Gotoxy(35,9);
	printf(VERSION);	
	Gotoxy(32,11);
	printf(WELCOME);
	Gotoxy(27,13);
	printf("Loading");
	for(i=0;i<15;i++)
	{
		Sleep(60);
		printf(".");
	}
} 
/*****************************************************************
***函数名:MakeMenuInfo
***参数:无
***功能:制作菜单信息
***返回值:无
*****************************************************************/	
void MakeMenuInfo()
{
	int i;
	Gotoxy(23,1);
	printf(TITLE);	
	Gotoxy(21,2);
	for(i=1;i<=40;i++)
		printf("*");
	Gotoxy(0,4);
	for(i=1;i<=80;i++)
		printf("=");
	Gotoxy(0,18);
	for(i=1;i<=80;i++)
		printf("=");
	//MESSAGE居中显示
	Gotoxy(35,18);	
	printf(MESSAGE);
	Gotoxy(0,23);
	for(i=1;i<=80;i++)
		printf("=");
	Gotoxy(2,24);
	printf(VERSION);
	Gotoxy(23,24);
	printf(AUTHER);
	Time();
	Gotoxy(0,5);

}
/*****************************************************************
***函数名:JuZhong
***参数:char * dest[],int n
***功能:实现菜单项居中显示
***返回值:无
*****************************************************************/		
int JuZhong(char * dest[],int n)
{
	int max=0;
	int s,i,t;
	for(i=0;i<n;i++)
	{
		t=strlen(dest[i]);
		max=max > t ? max : t;
	}	
	s=(80-max)/2;
	return s;
}
/*****************************************************************
***函数名:ClearMessage
***参数:无
***功能:清除消息
***返回值:无
*****************************************************************/	
void ClearMessage()
{
	fflush(stdin);
	Gotoxy(0,19);
	printf("%*s",80," ");
}
/*****************************************************************
***函数名:InputError
***参数:int x,int y,char ch(x,y坐标)
***功能:对输入不符合条件进行处理,打印相应信息
***返回值:无
*****************************************************************/	
void InputError(int x,int y,char ch)
{
	if(ch>='a' && ch<='z' || ch>='A' && ch<='Z')
	{
		ClearMessage();
		Gotoxy(0,19);
		printf("Error illegal char!Please enter again!");
	}
	else if((ch>='0' && ch<='9'))
	{
		ClearMessage();
		Gotoxy(0,19);
		printf("Error illegal digit!Please enter again!");
	}
	else if(ch==13)
	{
		ClearMessage();
		Gotoxy(0,19);
		printf("Error null!Please enter again!");
	}
	else
	{
		ClearMessage();
		Gotoxy(0,19);
		printf("Error input illegal!Please enter again!");
	}
	getch();
	Gotoxy(x+1,y);
	printf("\b \b");
	Gotoxy(x+1,y);
}
/*****************************************************************
***函数名:GetString
***参数:char buffer[],int maxlen
***功能:实现字符串输入,接收到的字符串放入指定的字符串buffer中
***说明:该函数限定输入字符个数最大不超过maxLen个,当输入已满
		 maxLen个时,客户输入无任务响应也没有回显,但可以用
		 "Backspace"键退格修改
***返回值:返回输入字符串的长度
*****************************************************************/
int GetString(char buffer[],int maxlen)
{
	int i=0,len;
	char ch;
	do
	{
		ch=getch();
		if(ch==27)  //ESC->27
		{
			break;
		}		
		if(ch==13)  // <CR>->13
		{
			buffer[i]='\0';
			break;
		}
		if(ch==8 && i>0)  //退格
		{
			printf("\b \b");  
			--i;
			if(i==0)
				continue;
		}
		if(i<maxlen && ch>=32)
		{
			buffer[i++]=ch;
			printf("%c",ch);
		}
	}while(1);
	len=strlen(buffer);
	return len;
}
/*****************************************************************
***函数名:Left_Right
***参数:char temp[]
***功能:去除左右空格
***返回值:无
*****************************************************************/	
void Left_Right(char temp[])  //去除左右空格
{
	int i,len;	
	i=0;
	while(temp[i])  //左空格
	{		
		if(temp[i]!=' ')	
			break;
		i++;
	}
	strcpy(temp,temp+i);

	len=strlen(temp);
	for(i=len - 1;i>=0;i--)  //右空格
	{
		if(temp[i]!=' ')
		{
			temp[i+1]='\0';
			break;
		}
	}
}
/*****************************************************************
***函数名:MenuList
***参数:无
***功能:显示菜单项
***返回值:无
*****************************************************************/		
void MenuList()
{
	int i,s,x,y;
	char ch;
	char *menu[]=
	{	"1.  Add student's info",
		"2.  Sort data",
		"3.  Print student's report",
		"4.  Save data to file",
		"5.  Load data from file",
		"6.  Search students",
		"7.  Stat Score",
		"0.  Exit"
	};	
	system("cls");
	Gotoxy(35,3);
	printf(MENULIST);
	MakeMenuInfo();	
	printf("\n");
	s=JuZhong(menu,8);	//菜单项--居中显示
	for(i=0;i<=7;i++)    //打印菜单项
		printf("%*s%s\n",s," ",menu[i]);
	Gotoxy(0,0);
	Gotoxy(27,15);
	printf("Please Make a choices[0-7]:");
	Getxy(&x,&y);
	do
	{
		ClearMessage();
		Gotoxy(0,19);
		printf("Please Input 0-7 digit. <example:1>");
		Gotoxy(x,y);
		ch=getche();
		getch();
		switch(ch)
		{
			case '1':AddInfo();break;
			case '2':SortData();break;
			case '3':PrintData();break;
			case '4':SaveData();break;
			case '5':LocalData();break;
			case '6':SearchData();break;
			case '7':Stat();break;		
			case '0':Exit_Save();break;
			default:InputError(x,y,ch);break;
		}
	}while(!(ch>='0' && ch<='7'));
}
/*****************************************************************
***函数名:AddInfo
***参数:无
***功能:用户添加信息
***返回值:无
*****************************************************************/	
void AddInfo()
{
	int i,x,y;
	char *AddInfo[]=
	{	"             Sno *:",
		"            Name *:",
		"             Age *:",
		"         Chinese *:",
		"         English *:",
		"            Math *:",
		"         Physics *:",
		"       Chemistry *:"
	};
	if(count>100)
	{
		ClearMessage();
		Gotoxy(0,19);
		printf("The data is full!Pleased key to continue ...");
		getch();
		return;
	}
	do
	{	
		system("cls");
		Gotoxy(30,3);
		printf(ADDINFO);	
		MakeMenuInfo();	
		Gotoxy(0,0);
		for(i=0;i<=7;i++) 
		{
			Gotoxy(20,7+i);
			printf("%s\n",AddInfo[i]);
		}
		fflush(stdin);
		AddSno();
		AddName();
		AddAge();
		AddScore();
		do
		{
			ClearMessage();
			Gotoxy(0,19);
			printf("Add Student's information Success ! Are you continue(Y/N)?");
			Getxy(&x,&y);
			Gotoxy(x,y);
			ch=getche();
			getch();
			if(ch=='Y' || ch=='y' || ch=='N' || ch=='n')
			{
				break;
			}
			else
			{
				ClearMessage();
				Gotoxy(0,19);
				printf("Error!Please enter again.");
				getch();
				Gotoxy(x+1,y);printf("\b \b");
				continue;
			}
		}while(1);
		stu[count]=data;		
		total[count]=stu[count].score[0]+stu[count].score[1]+stu[count].score[2]+stu[count].score[3]+stu[count].score[4];
		avg[count]=(float)total[count]/5.0;
		/*
		InsertData(stu_link.studate);
		total[count]=stu_link.studate.score[0]+stu_link.studate.score[1]+stu_link.studate.score[2]+stu_link.studate.score[3]+stu_link.studate.score[4];
		avg[count]=(float)total[count]/5.0;
		*/
		count++;
		save_flag=1;
	}while(ch=='Y' || ch=='y');

}
/*****************************************************************
***函数名:AddSno
***参数:无
***功能:实现学号自动增长
***返回值:无
*****************************************************************/
void AddSno()  //学号
{
	int i;
	char tempsno[5];
	Gotoxy(40,7);
	for(i=1;i<=MAXCOUNT;i++)
	{
		if(sno[i-1]==0)
		{
			sno[i-1]=i;
			sprintf(tempsno,"%03d",i);
			puts(tempsno);
			break;
		}
	}
	strcpy(data.sno,tempsno);
	//strcpy(stu_link.studate.sno,tempsno);
}
/*****************************************************************
***函数名:AddName
***参数:无
***功能:去除左右空格,判断非法字符

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -