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

📄 function2.c

📁 学生管理系统 在linux编译C语言写的
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "Pre-defined.h"

//================================获取标准输出设备句柄===================================//

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)
	{ 	
		COORD pos ;
 		HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); 
		CONSOLE_SCREEN_BUFFER_INFO bInfo;
   		GetConsoleScreenBufferInfo( hOut, &bInfo ); 
   		pos = bInfo.dwCursorPosition;
 		*x = pos.X;
 		*y = pos.Y;
	}
//================================定长接收函数===================================//

/* 参数:Str接收输入的字符串;max输入字符串的最大值;
     tage=1或0,取1,是正常调用,取0,是输入密码之类时调用,
	 取2,是输入ESC键时返回主菜单的调用。
*/          
void GetStr(char str[],int max,int tage)
                                      
{
   int ch,i=0;
   while(1)
   {
      ch=getch();
	  if(tage==2)
		{
		  if(ch==27)
		  {
			  str[0]=27;
			  break;
		  }
		}
	  if(i>=max&&ch!=13&&ch!=8)
		  continue;
	  if(ch==0xe0||ch==0)
		  {
			  getch();
			  continue;
		  }
	  if(ch==13)
		  {            
			  str[i]='\0';
			  break;
		  }
	  else if(ch==8)
		  {
			  if(i==0)
			  {
			 	  continue;
			  }
			 else
			  {
				  printf("\b \b");
				  i--;
			  }
		  }
	  else
		 {
			 if(tage==1)
				{
					printf("*");
		     	  
				}
			 else
				{
					printf("%c",ch);
				}
			 str[i]=ch;
			 i++;
		 }
	}
   
}
//================================矩形区域清空函数===================================//

void Empty(int x1,int y1,int x2,int y2)  //(x1,y1)、(x2,y2)分别为矩形区域的左上角和右下角坐标
 {
	int i,j;
	for(i=0;i<=y2-y1;i++)
	{	
		GoToXY(x1,y1+i);
		for(j=0;j<=x2-x1;j++)
		printf(" ");
	}
	GoToXY(x1,y1);
 }
//================================人性化提示用户输入的错误!===================================//

char Personalized_Tips(int x,int y,int n)
{
	char ch;
	while(1)				
	{	
		GoToXY(x,y);
		ch=getch();		
			if(ch<=0)
			ch=getch()+150;		 	
		if(ch>='0'&&ch<=n+48)
		{
			printf("%c",ch);
			break;
		}
		else
			if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))//输入字符的提示!
			{	
				printf("%c",ch);
				Empty(2,21,70,21);
				printf("Input Error,you input a letter!!");
			}
			else 
				if(ch==13||ch==32)//输入空格、回车的提示!
					{
						GoToXY(x,y);
						printf(" \b");
						Empty(2,21,70,21);
						printf("Input Error,you input a null character!!");
					}	
				
				else
					if(ch>n+'0'&&ch<='9')//输入的数字大于n的提示!
				{
					printf("%c",ch);
					Empty(2,21,70,21);
					printf("Input Error,you input > %d!!",n);
				}				
					else
					{
						GoToXY(x,y);
						printf(" \b");
						Empty(2,21,70,21);
						printf("Input Error,you input a symbol or funtion key!!");//其它的提示!
					}
		}
	return ch;
}
//================================打印中对于翻页的个性化提示错误===================================//

int Personalized(int x,int y,int n)//n=1时为普通打印! n=2时为查询打印!
{
	int ch;
	while(1)				
	{	
		GoToXY(x,y);
		ch=getch();		
		if(ch==0 || ch==224)
			ch=getch()+200;	
		if(n==1&&(ch==271||ch==281||ch==273||ch==279||ch=='0'||ch=='5'))
			{	
				break;
			}
		else if(n==2&&(ch==271||ch==281||ch==273||ch==279||ch==283||ch=='0'||ch=='5'||ch=='7'))
			{	
				break;
			}

		else if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z'))
			{	
				printf("%c",ch);
				Empty(2,21,70,21);
				printf("Error,you input a letter!!");
			}
		else if(ch==13||ch==32)
			{
				GoToXY(x,y);
				printf(" \b");
				Empty(2,21,70,21);
				printf("Error,you input a null character!!");
			}	
				
		else if((n==1&&(ch>'0'&&ch<'5'||ch>'5'&&ch<='9'))||(n==2&&(ch>'0'&&ch<'5'||ch>'5'&&ch<='9'&&ch!=7)))
			{
				printf("%c",ch);
				Empty(2,21,70,21);
				if(n==1)
				{
					printf("Error,you input is a number what is not '0' or '5'!");
				}
				else
				{
					printf("Error,you input is a number what is not '0' or '5'or '7'!");

				}	
		}
				
		else
			{
				GoToXY(x,y);
				printf(" \b");
				Empty(2,21,70,21);
				printf("Error,you input a symbol or funtion key!!");
			}	
	}
	return ch;

}
//================================处理姓名中左中右空格===================================//
void Deal_Space(char *name) 
{
	int j=0;
	char ch=name[0];	
	strlwr(name);
	while(ch!='\0')						
	{
		if(j==0&&ch==32)
		{
			strcpy(name,name+1);//去除左空格
			ch=name[0];
			continue;
		}
		else
			if(ch==32&&name[j+1]==32)
			{
				strcpy(name+j,name+j+1);//去除中空格
				ch=name[j];
				continue;
			}
			else
				if(ch==32&&name[j+1]=='\0')//去除右空格
				{
					name[j]='\0';
					ch=name[j];
				}
				else
				{
					j++;
					ch=name[j];
				}
	}
}
//================================规范姓名输入===================================//
void Name_Judge(char *name)					
{
	int x,y;
	char ch;
	int j=0;
	WhereXY(&x,&y);
	while(1)					
	{
		int sign;
		Empty(x,y,x+20,y);
		GetStr(name,20,2);
		if(name[0]==27)
		{
			break;
		}
		else
		{
				
			while(1)					//判断名字是否都是字母或者空格
		{
				ch=name[j];
				if(isalpha(ch)||ch==32)
					j++;
				else
					break;
			}
			if(name[j]!='\0')
			{
				Empty(2,21,75,21);
				printf("Only the names of letters or spaces constitute,please input again!");
				Empty(x,y,x+20,y);
				continue;
			}
			else
			{	j=0;
				sign=0;
				ch=name[0];
				while(ch!='\0')				//判断名字是否只有空格。
				{
					if(isalpha(ch))
					{	
						sign=1;
						break;
					}
					else
					{
						ch=name[j];
						j++;	
					}
				}
				if(sign==1)
					break;
				else
				{
				    Empty(2,21,75,21);
					printf("name cann't null,please input again!");
					Empty(x,y,x+20,y);
				}			
			}
	}
	}
	Deal_Space(name);//处理姓名中左中右空格!
}
//================================对年龄的处理===================================//

int Age_Judge(char *str)
{
	int x,y;
	
	char ch;
	WhereXY(&x,&y);	
    while(1)
	{	
		int j=0;
		int s=0;

		GetStr(str,3,2);
		ch=str[j];
		while(ch!='\0')
		{	if(isdigit(ch)||ch==27)
			{
			    if(ch==27)//按ESC返回!
				{
					str[0]=27;
					return (-1);
					break;
				}
				j++;
				ch=str[j];
			}
			else 
			{
				GoToXY(2,21);
				Empty(2,21,70,21);
				printf("error!you input not number!");//判断是不是数字!
				Empty(x,y,x+3,y);
				s=1;
				break;
			}
		}
		if(s==1)
			continue;
		if(str[0]=='\0')
			{
				GoToXY(2,21);
				Empty(2,21,70,21);//判断是不是越界!
				printf("error! you input NULL! please input 0<=score<=100!");
				Empty(x,y,x+3,y);
			}
		else
		{
			
			
			if(atoi(str)>=7&&atoi(str)<=50)
			{
			    Empty(x,y,x+3,y);
				break;
			}
			else
			{
				GoToXY(2,21);
				Empty(2,21,70,21);
				printf("please input 7<=age<=50!");
				Empty(x,y,x+3,y);
			}
		}
	 

	}
return atoi(str);
}
//================================对分数的处理===================================//

double Score_Judge(char *str,int i)
{
	int x,y;
	char ch;
	WhereXY(&x,&y);
	while(1)
	{	
		int j=0;
		int m=0;
		int s=0;
		GetStr(str,5,2);
		ch=str[j];		
		while(ch!='\0')
		{
			if(isdigit(ch)||ch==46||ch==27)
			{
				if(ch==27)
				{
					str[0]=27;
					return (-1);
				}
				if(ch==46)
					m=j;
				j++;
				ch=str[j];			
			}
			else 
			{
				GoToXY(2,21);
				Empty(2,21,70,21);
				printf("error!you input not number!");//判断是不是数字!
				Empty(x,i,x+6,i);
				s=1;
				break;
			}
		}
		if(s==1)
			continue;
		if(str[0]=='\0')
		{
			GoToXY(2,21);
			Empty(2,21,70,21);
			printf("error! you input NULL! please input 0<=score<=100!");//是否为空!
			Empty(x,i,x+6,i);
		}
		else
			if(atof(str)>=0&&atof(str)<=100)		
			{	if(str[m]==46)
					if(str[m+1]=='0' || str[m+1]=='5')//判断成绩的小数点部分!
					{
						Empty(x,i,x+6,i);
						break;
					}
					else 
					{
						Empty(2,21,70,21);
						printf("error! you input must the mantissa is 0.1 or 0.5's dight!");
						Empty(x,i,x+6,i);
					}
					else
					{
						Empty(x,i,x+6,i);
						break;
					}
			}
			else
			{
				GoToXY(2,21);
				Empty(2,21,70,21);
				printf("please input 0<=score<=100!");//判断是不是越界!
				Empty(x,i,x+6,i);
			}
	}
return atof(str);
}
//================================对学号的处理===================================//

int Sno_Judge(char *str)
{
	
	char ch;
    while(1)
	{	
		int j=0;
		int s=0;

		GetStr(str,3,2);
		
		ch=str[j];
       if(str[0]==27)
			return -1;
		while(ch!='\0')
		{	if(isdigit(ch))
			{

			     
			if(ch==27)//按ESC键返回!	
			{
				str[0]=27;
				return (-1);
				break;
				}
				j++;
				ch=str[j];
				
			}
			else 
			{
			
				Empty(2,21,70,21);
				printf("error!you input not number!");//判断地否为数字!
				Empty(29,20,70,20);
				s=1;
				break;
			}
		}
		if(s==1)
			continue;
		if(str[0]=='\0')
			{
				GoToXY(2,21);
				Empty(2,21,70,21);
				printf("error! you input NULL! please input 0<=sno<=100!");//判断是否为空!
				Empty(29,20,70,20);
			}
		else
		{
			if(atoi(str)>0&&atoi(str)<=100)
			{
				break;
			}
			else
			{
				Empty(2,21,70,21);
				printf("please input 0<sno<=100!");
				Empty(29,20,70,20);
			}
		}
	 

	}
return atoi(str);
}
//================================对学号和总分的选择排序===================================//

void Select_Sort(int wage)
{
	LinkList *p,*q,*m;
	double m_tatal,q_tatal;
    Stu temp;
	for(p=head;p!=NULL;p=p->next)
	{
		m=p;
		for(q=p->next;q!=NULL;q=q->next)
		{


			m_tatal=m->data.score[0] +m->data.score[1] +m->data.score[2] +m->data.score[3] +m->data.score[4];
			q_tatal=q->data.score[0] +q->data.score[1] +q->data.score[2] +q->data.score[3] +q->data.score[4];
			if((wage==1&&m->data.sno > q->data.sno)||((wage==2)&&(m->data.sno < q->data.sno))||(wage==3&&m_tatal > q_tatal)||(wage==4&&m_tatal < q_tatal))
				//按学号升降排序和按总分升降排序!
				{	
					m=q;
				}
		}
		if(m!=p)
			{
				temp=m->data;
				m->data=p->data;
				p->data=temp;
			}
		
	}
}

//================================求出链表总结点数===================================//

int GetLinkLen(LinkList *h)
{
	int len=0;
	LinkList *p=h;
	while(p)
	{
		len++;
		p=p->next;
	}
	return len;
}

//================================精确查找学号函数===================================//

int SearchSno()
{
	LinkList *p=NULL;
	char m[3];
	int k;
	temphead=NULL;
	Empty(2,20,60,20);
	printf("please a sno for searching:");
	if(Sno_Judge(m)==-1)//按ESC键返回!
		return -1;
	p=head;
	while(p)
	{
						
        
		if(p->data.sno==atoi(m))
		{

			InsertNoderes(p->data);
			break;
		}
		p=p->next;

	}
	if(temphead==NULL)
				 {
					 Empty(2,21,60,21);
					 printf("Find not data!please any key to return!!");
   					 getch();
				 }
				else
				{
				 while(1)
				 {
					 k=Print_Function(temphead,2,1,0);
					 if(k==1)
						Modify_Function();
					 else 
						 break;
				 }

				}
	  return 0;
}
//================================模糊查询姓名函数===================================//

int SearchName()
{
	LinkList *p=NULL,*q=NULL;
	char m[21];
	int k;
	temphead=NULL;
	Empty(2,20,60,20);
    printf("please a name for searching:");
	Name_Judge(m);	

	if(m[0]==27)//按ESC返回!
		return -1;
	p=head;
	q=temphead;
	while(p)
	{
						
   		if(strstr(p->data.name,m)!=NULL)
		{
			InsertNoderes(p->data);
		}
		p=p->next;
	}
		while(1)
				{
				if(temphead==NULL)
					{

						Empty(2,21,60,21);
						printf("Find not data!please any key to return!!");
						getch();
						return 0;
			
					}
				else
					{

						while(1)
						{
							k=Print_Function(temphead,2,2,0);//调用打印函数!

							if(k==-1)
							  return 0;
							if(k==1)
								Modify_Function();
							else
								break;

						}
					Exit_Judge();
					if(key=='Y'||key=='y')
						{
							continue;	
						}
					else if(key=='N'||key=='n')	
							return 0;
					}
				}

}
//================================删除查询到的学号函数===================================//

LinkList * DeleteOneStudent(LinkList *newhead)
{ 
	LinkList *p=head;
	LinkList *q;
	if(p->data.sno==newhead->data.sno)//删除临时链表和原链表!
		{	
			head=head->next;
			free(p);
			free(newhead);
		}
	else
		{
		while(p->next!= NULL)
			{
				if(p->next->data.sno==newhead->data.sno)
				{
					q=p->next; 
					p->next =p->next->next;
					if(q==last)
					{
						p->next=NULL;
						last=p;
					}
					free(q);
					free(newhead);
					break;
				}
				else
					p=p->next;

			}
		}
	return NULL;
}
//================================删除查询到的姓名中学号的函数===================================//

LinkList * DeleteStudent(LinkList *newhead,int sno)
{

⌨️ 快捷键说明

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