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

📄 mis_sms(finish).c

📁 学生信息管理系统 代码量在3000左右。原创作品。(内附程序流程图)
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
*********************************************************
*  					 头文件
*********************************************************
*/ 
#include <stdio.h>
#include <windows.h>
#include <wincon.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/*
*********************************************************
*  					  常量
*********************************************************
*/
#define DEBUG
#define __0 0x60
#define _0 0x30
#define _1 0x31
#define _2 0x32
#define _3 0x33
#define _4 0x34
#define _5 0x35
#define _6 0x36
#define _7 0x37
#define _ESC 0x1B
#define _PAGEUP 0x49
#define _PAGEDOWN 0x51
#define _DELETE 0x53
#define _BACKSPACE 0x08
#define _ENTER 13
#define _HOME 71
#define _END 79
#define _INSERT 82
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
#define ERROR -3
#define STU_MAX 999 //学生最大上限
#define BACKMENU -1
#define INSERT_RECORD -1
#define MAKE_NEW_FILE -2
#define EMPTY -2
#define BACK 240
#define FOREGROUND_WHILE	 0x000F
const int FILE_NAME_LIMIT = 8;
const int ISVALID_FILENAME_VALID= 1;
const int ISVALID_FILENAME_ERROR = -1;
const int ISVALID_FILENAME_EMPTY = -2;
const int ISVALID_FILENAME_OVERFLOW = -3;
const int ISVALID_FILENAME_ERRORDOT = -4;

/*
*********************************************************
*  					  变量
*********************************************************
*/
FILE *fp,*fp1;

char fn[20];
int savedatalabel=0;  // 0 表示内存中没有数据
char loadfilename[9]={'\0'};    // 记录载入的文件名,如果是新建的记录,文件名为空
int filedatachange = -1;
int stu_count=1; //记录学生数
int dataend=0;
int exitflag=0;
int searchflag=0;
int statflag = 0;
int sortway=3;

struct stu_info
{
	char sno[6];
	char sname[21];
	int  sage;
	char schi[6];
	char smath[6];
	char seng[6];
	char spho[6];
	char sche[6];
};
typedef struct stu_info Stu_Info;
struct stu_lnode
{
	struct stu_info data;
	struct stu_lnode *next,*pre;
};
typedef struct stu_lnode Stu_Lnode;
Stu_Lnode *in,*head,*tail,*p,*temp,*temphead,*temptail;	
/*
*********************************************************
*  				      函数原型
*********************************************************
*/



/*
*************************************************************
* 函数描述:定位光标位置的函数
* 输入参数:x,y 用于指定要定位到的坐标
* 返回值  :无
*************************************************************
*/
void GoToXY(int x, int y)
{
	COORD pos = {x,y};
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);	// 获取标准输出设备句柄
	
	SetConsoleCursorPosition(hOut, pos);
}

void WhereXY(int *x, int *y)
{
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);	// 获取标准输出设备句柄	  
	COORD pos;
	CONSOLE_SCREEN_BUFFER_INFO bInfo;
   	GetConsoleScreenBufferInfo( hOut, &bInfo );	
	pos = bInfo.dwCursorPosition;
	*x = pos.X;
	*y = pos.Y;
}

/*
*************************************************************
* 函数描述:在指定坐标画矩形函数
* 输入参数:矩形左上角的X Y 坐标 矩形内显示的字符串
* 返回值  :无
*************************************************************
*/
void PrintRectangle(int x,int y,char *str)
{
	int j=0,i,len,space;
	len=strlen(str);
	if (len%2 == 0)
	space=(20-len)/2;
	else 
    {
		space=(21-len)/2;
		j=1;
	}
	GoToXY(x,y);
	printf("%c",218);
	for (i=0;i<20+j;i++)
		printf("%c",196);
	printf("%c",191);
	GoToXY(x,y+1);
	printf("%c",179);

	for (i=0;i<space;i++)
	printf(" ");
	printf("%s",str);
	for (i=0;i<space;i++)
	printf(" ");
	printf("%c",179);
	GoToXY(x,y+2);
	printf("%c",192);
	for (i=0;i<20+j;i++)
		printf("%c",196);
	printf("%c",217);	
}

/*
*************************************************************
* 函数描述:信息添加界面绘制的函数
* 输入参数:自动生成的学号字符串
* 返回值  :无
*************************************************************
*/
void PrintSubjectMenu(char *stu_No)
{
	GoToXY(15,3);
	printf("            No:");
	printf("%s",stu_No);
	GoToXY(15,4);
	printf("          Name:");
	GoToXY(15,5);
	printf("           Age:");
	GoToXY(15,6);
	printf(" Chinese Score:");
	GoToXY(15,7);
	printf(" English Score:");
	GoToXY(15,8);
	printf("    Math Score:");
	GoToXY(15,9);
	printf(" Phogric Score:");
	GoToXY(15,10);
	printf("Chemical Score:");	
}

/*
*************************************************************
* 函数描述:计算总分的函数
* 输入参数:q 为结构体指针,指向要统计的学生
* 返回值  :通过str 返回统计结构
*************************************************************
*/

void CalculateTotal(Stu_Lnode *q,char str[5])
{
	int len;
	float total;
	total=atof(q->data.schi)+atof(q->data.seng)+atof(q->data.smath)+atof(q->data.spho)+atof(q->data.sche);	
	sprintf(str,"%0.1f",total);
	len=strlen(str);
	if(str[len-1]!='0')
		str[len-1]='5';
	
}
/*
*************************************************************
* 函数描述:计算平均分的函数
* 输入参数:同上
* 返回值  :同上
*************************************************************
*/
void CalculateAvg(Stu_Lnode *q,char str[5])
{
	int len;
	float savg;
	savg=(atof(q->data.schi)+atof(q->data.seng)+atof(q->data.smath)+atof(q->data.spho)+atof(q->data.sche))/5.0;
	sprintf(str,"%0.1f",savg);
	len=strlen(str);
	if(str[len-1]!='0')
		str[len-1]='5';
	
}
/*
*************************************************************
* 函数描述:按学号和总分排序的函数
* 输入参数:排序方式  (4种)
* 返回值  :若没有数据为空
*************************************************************
*/
int StructSort(int way)
{
	int i,count=0,j;
	char str1[5],str2[5];
	Stu_Lnode *q;
	Stu_Lnode *stemp = (Stu_Info *)malloc(sizeof(Stu_Info)); 
	q=head;
	if(q==NULL)
	{
		return EMPTY;
	}
	while(q!=tail)
	{
		count++;        //计算节点
		q=q->next;
	}
	if (count == 0)
		return EMPTY;
	q=head->next;	
		for(i=0;i<count;i++)
		{
			for (j=1;j<count-i;j++)		
			{	
				CalculateTotal(q,str1);
				CalculateTotal(q->next,str2);
					if(
						(way==4 && atoi(q->data.sno) < atoi(q->next->data.sno))
						||
						(way==3 && atoi(q->data.sno) > atoi(q->next->data.sno))
						||
						(way==2 && atof(str1) < atof(str2))
						||
						(way==1 && atof(str1) > atof(str2))
						)   
					{
						memcpy(stemp,q,sizeof(Stu_Info));
						memcpy(q,q->next,sizeof(Stu_Info));
						memcpy(q->next,stemp,sizeof(Stu_Info));
					}			
				q=q->next;
			}
			q=head->next;
		}
		
}

/*
*************************************************************
* 函数描述:打印学生信息的函数
* 输入参数:同上
* 返回值  :同上
*************************************************************
*/

void PrintStudentRecord(Stu_Lnode *q,char *stotal,char *savg,int k)
{
	int chil,engl,mathl,phyl,chel,totall,avgl,avgl_2;
	int i;
	chil=engl=mathl=phyl=chel=totall=avgl=avgl_2=32;
	switch(k)
	{
	case 1:			
			chil=179;
			break;		
	case 2:		
			engl=179;
			break;
	case 3:
			mathl=179;
			break;
	case 4:
			phyl=179;
			break;
	case 5:
			chel=179;
			break;
	case 6:
			totall=179;
			break;
	default : 
		break;
	}
printf("%c %-4s%-21s%-3d%c%-5s%c%-7s%c%-4s%c%-7s%c%-8s%c%-5s%c%c%-5s\n",
	   179,q->data.sno,q->data.sname,q->data.sage,chil,q->data.schi,engl,q->data.seng,mathl,q->data.smath,phyl,q->data.spho,chel,q->data.sche,totall,stotal,avgl,avgl_2,savg);					
  }

int GetchKey()
{
	int _key;
	while(1)
	{
		_key=getch();
		if(_key>200)
		{
			_key = getch();
			break;
		}
		return _key;
	}
	return _key;
}

void ClearMassage()
{	
	int i,j;
	for(i=0;i<4;i++)
	{	
		GoToXY(1,18+i);
		for (j=0;j<78;j++)
			printf(" ");		
	}
}

/*
*************************************************************
* 函数描述:清除指定行的函数
* 输入参数:行首的X Y 坐标
* 返回值  :无
*************************************************************
*/
void Clear(int x,int y)
{
	int i;
	GoToXY(x,y);
	for(i=0;i<78;i++)
	printf(" ");
}

void SpaceAlert()
{
	GoToXY(1,19);
	printf("Alert , First character can't input \"Space\"");
	Sleep(800);
	Clear(1,19);
}


void PrintAlert(int top)
{
	Clear(1,19);
	GoToXY(1,19);
	if (top>0 && top<10)
	{
		printf("Error---Please make choise between [0-%d]",top);
	}
	else
	{
		printf("Error---Please press key with [ENTER] and [ESC]");
	}
	GoToXY(1,20);
	printf("Press any key to continue");
	GetchKey();
	ClearMassage();
}


int GetString(char *str,int lenlimit)
{
	int key,i=0;
	while (1)
	{		
		key=GetchKey();
		if (key == _ESC)
		{
			str[i]='\0';
			return -1;
		}

		if (key==_BACKSPACE)
		{
			if (i==0)
			{
				continue;
			}
			else 
			{
				printf("\b \b");
				i--;
				continue;
			}
		}		
		if (key==_ENTER)
		{
			str[i]='\0';
			if (i==0)
			{
				return EMPTY;
			}
			return 1;
		}
		if (i==lenlimit)
		{
			continue;
		}
		if (isprint(key))
		{
			str[i]=key;
			i++;
			putchar(key);
			continue;
		}
	}
}
int InputDataCheck(char *str,int lenlimit,int x,int y)
{	 
	int xx,yy;
	int space=0,front=0;
	int i=0;
	int stringisvalid=1 ;	
	while(1)
	{	
		str[i]=GetchKey();
		WhereXY(&xx,&yy);
		if (str[0]==' ')
			SpaceAlert();
		if (xx==x+lenlimit)
		{
			while(1)
			{
				if(str[i]==_BACKSPACE || str[i] == _ENTER)
					break;
				str[i]=GetchKey();
			}				
		}
		if (xx!=x)
		{
			if (str[i]==' ')
			{
			GoToXY(x+i,y);
			printf("%c",str[i]);
			i++;		
			continue;
			}
		}				
		if (isdigit(str[i]))// || isalpha(str[i]) || str[i]=='.')
		{

			GoToXY(x+i,y);
			printf("%c",str[i]);		
		}
		else 
		{
			if (str[i]==_BACKSPACE)
			{
				WhereXY(&xx,&yy);		//定位光标
				if (xx!=x)				//如果不在第一个元素
				{
					str[--i]='\0';
					printf("\b");
					printf(" ");
					printf("\b");					
					continue;
				}
				else					//如果是第一个元素
				{
					GoToXY(x,y);
					continue;
				}
			}
			if(str[i] == _ENTER)		//若是回车
			{
				WhereXY(&xx,&yy);
				if (xx!=x)				//不在第一个元素
				{
					str[i]='\0';
					GoToXY(x,y);
					printf("%s",str);
					return 1;
				}
				else
					return EMPTY;
			}
			else 
				GoToXY(x+i,y);
			continue;			
		}
		i++;		
	}
}

void ClearDisplay(int x,int y)
{
	int i,j;
	for (i=0;i<16;i++)
	{
		GoToXY(x,y+i);
		for (j=0;j<78;j++)
			printf(" ");
	}
}

void ClearAll()
{
	ClearMassage();
	ClearDisplay(1,1);
}

void PrintRecordFrame(int k)
{
	int chil,engl,mathl,phyl,chel,totall,avgl,avgl_2;
	int i;
	chil=engl=mathl=phyl=chel=totall=avgl=avgl_2=32;
	switch(k)
	{
	case 1:			
			chil=engl=179;
			break;		
	case 2:		
			engl=mathl=179;
			break;
	case 3:
			mathl=phyl=179;
			break;
	case 4:
			phyl=chel=179;
			break;
	case 5:
			chel=totall=179;
			break;
	case 6:
			totall=avgl_2=179;
			break;
	default : 
		break;
	}
	GoToXY(0,0);
	printf("%c",218);
	GoToXY(1,0);
	for (i=0;i<78;i++)	
	printf("%c",196);
	printf("%c",191);
	GoToXY(0,1);
	printf("%c No  Name                 Age%cChina%cEnglish%cMath%cPhysics%cChemical%cTotal%c%cAvg  %c\n",179,chil,engl,mathl,phyl,chel,totall,avgl,avgl_2,179);	
	GoToXY(0,2);
	printf("%c",179);
	for (i=0;i<78;i++)
	printf("%c",196);
	printf("%c",179);
	GoToXY(0,3);
	for (i=0;i<9;i++);
	printf("%c",179);
	GoToXY(0,13);
	printf("%c",195);
	for (i=0;i<78;i++)
		printf("%c",196);
	printf("%c",180);
	//GoToXY(2,3);
}
void ClearPrintDisplayAll()
{
	int i,j;
	GoToXY(1,1);
	for (i=0;i<12;i++)		
	{
		for (j=0;j<78;j++)
			printf(" ");
		GoToXY(1,2+i);
	}
	for (i=0;i<3;i++)
	{
		GoToXY(1,14+i);
			for (j=0;j<78;j++)
				printf(" ");
	}
}
void PrintSign(char *str,int yy)
{
	GoToXY(1,yy);
	printf(" ");
	GoToXY(78,yy);
	printf(" ");
	if (strcmp("up",str)==0)
		yy--;
	if (strcmp("down",str)==0)
		yy++;
	GoToXY(1,yy);
	printf("[");
	GoToXY(78,yy);
	printf("]");
}

ClearPrintDisplay()
{
	int i,j;
	GoToXY(1,3);
	for (i=0;i<10;i++)		
	{
		for (j=0;j<78;j++)
			printf(" ");
		GoToXY(1,4+i);
	}
}

void PrintTopBorder()
{

⌨️ 快捷键说明

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