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

📄 function2.c

📁 学生管理系统 在linux编译C语言写的
💻 C
📖 第 1 页 / 共 2 页
字号:
	LinkList  *q=head,*p=newhead,*p1;//删除临时链表和原链表!
	if(sno==p->data.sno)
	{
		newhead=newhead->next;
		free(p);
	}
	else
	{
		while(p->next!=NULL)
		{
			if(p->next->data.sno==sno)
				break;
			else
				p=p->next;
		}
		if(p->next==NULL)

			printf("Find not data!!");
		else
		{
			p1=p;
			p=p->next;
			p1->next=p->next;
			if(p==templast)
			{
				p1->next =NULL;
				templast=p1;
			}
			free(p);
		}
	}
	if(sno==q->data.sno)
	{
		head=head->next;
		free(q);
	}
	else
	{
		while(q->next!=NULL)
		{
			if(q->next->data.sno==sno)
				break;
			else
				q=q->next;
		}
		if(q->next==NULL)
		{
			printf("Find not data!!");
		}
		else
		{
			p1=q;
			q=q->next;
			p1->next=q->next;
			if(q==last)
			{
				p1->next =NULL;
				last=p1;
			}
			free(q);
		}
	}
	temphead=newhead;
	return newhead;
}

//================================释放所有链表结点===================================/

void DeleteAll(LinkList *h)
{
	LinkList *temp = h;
	while(temp != NULL)
	{
		h = h->next;
		free(temp);		
		temp=h;
	}
	h = NULL;
}

//================================统计前三甲函数===================================//

int Stat_Topthree(int wage)
{
	LinkList *p,*q;
	double m_tatal,q_tatal;
	int flag=3;
	int lenght;
    lenght=GetLinkLen(head);
	if(wage>=1&&wage<=5)
	{
		Stu temp;
		for(p=head;p!=NULL;p=p->next)//按学科成绩进行降序排序!
			{
				for(q=p->next;q!=NULL;q=q->next)
					{
						if(p->data.score[wage-1]<q->data.score[wage-1])
							{
								temp=p->data;
								p->data=q->data;
								q->data=temp;
							}
					}
			}
			if(lenght<=3)
			flag=lenght;
			else
			{
				p=head->next->next;
				for(q=p->next;q!=NULL;q=q->next)
				{
					
					if(p->data.score[wage-1]==q->data.score[wage-1])
					{
						flag++;
						continue;
					}
					else
						break;
				}

			}
	}
	if(wage==6)
	{
		Select_Sort(4);//按总分进行降序排序!
		if(lenght<=3)
		flag=lenght;
		else
		{
			p=head->next->next;
			for(q=p->next;q!=NULL;q=q->next)
			{
				m_tatal=p->data.score[0] +p->data.score[1] +p->data.score[2] +p->data.score[3] +p->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(m_tatal==q_tatal)
				{
					flag++;
					continue;
				}
				else
					break;
			}

		}

	}
	return flag;

}
//================================将结点插入临时链表函数===================================//
LinkList * InsertNoderes(Stu Data)
{	
	LinkList *p=NULL;
	p=(LinkList *)malloc(sizeof(LinkList));
	if(p==NULL)
	{
		printf("Memory!");
		exit(0);
	}
	p->data =Data;
	p->next =NULL;
	if(temphead==NULL)
	{
		temphead=p;
		
	}
	else
	{
		templast->next=p;
	}
	templast=p;
	return temphead;
}
//================================将结点插入原链表函数===================================//	
void InsertNode(Stu Data)
{	
	LinkList *p=NULL;
	p=(LinkList *)malloc(sizeof(LinkList));
	if(p==NULL)
	{
		printf("  Memory !");
		exit(0);
	}
	p->data =Data;
	p->next =NULL;
	if(head==NULL)
	{
		head=p;
	}
	else
	{
		last->next=p;
	}
	last=p;
}
//================================保存在默认工作目录函数===================================//
void Auto_Save(char file[])
{
		FILE *fp;
		LinkList *p; 
		int k=0, len=GetLinkLen(head);
		fp=fopen(file,"wb");//打开文件!
		if(fp==NULL)//保存失败!
			{
				Empty(2,21,70,21);
				printf("File save Fail!! please input any key to return!!");
				getch();
				return;
			}
		for(p=head;p!=NULL;p=p->next)//向文件里面一条一条写入数据!
			{
				if(fwrite(&p->data ,sizeof(Stu),1,fp)!=1)
				{
				  break;
				}
				else
					k++;
			}
		fclose(fp);//关闭文件!
		if(k!=len)//保存失败!
			{
				Empty(2,21,70,21);
				printf("File save Fail!! please any key to return!!");
				getch();
			}
		else
			{
			   isSave=1;//保存标签!
			   Empty(2,21,70,21);
			   printf("from %s file write %d count! please input any key to return!!",file,len);
			   getch();
			}



}
//================================读取默认工作目录函数===================================//
void Auto_Load(char file[])
{
		FILE *fp;
		int k=0;
		Stu tempdata;
		DeleteAll(head);//在读取前将所有结点释放!
		fp=fopen(file,"rb");//打开文件!
		if(fp==NULL)//保存失败!
			{
				Empty(2,21,70,21);
				printf("File open Fail!! please any key to return!!");
				getch();
				return;
			}
		while(1)
			{
				if(fread(&tempdata ,sizeof(Stu),1,fp)!=1)//从文件里一条一条读出数据!
					{
						break;
					}
				else
					{
						InsertNode(tempdata);//向原链表一条一条插入数据!
						k++;
					}
			}
		fclose(fp);//关闭文件!
		Empty(2,21,70,21);
		printf("from %s file read %d count! please any key to return!!",file,k);
		getch();
}
//================================另存在不同工作目录文件函数===================================//
int Save_As()
{
		
		char filename[20];
		int x,y;
		int old_Drive,new_Drive,len,i=0,j=0;
		char buffer[_MAX_PATH];//	_MAX_PATH为最大路径名长度, buffer为接收路径名的字符数组名!
		char str[7]={'*','|',':','?','\"','<','>'};//文件名不能包括的七种字符,其中对于':'在输入合法路径名前三位中的':'是合法的!
		char tempfile[_MAX_PATH];
		old_Drive=_getdrive();//得到当前工作盘符!
		_getdcwd(old_Drive,buffer,_MAX_PATH);//保存当前工作路径	!
		GoToXY(2,18);
		printf("example as e:/ye/ye.txt  e:\\e\\ye.txt");//例子:对于'/'或'\'都是合法的!
		GoToXY(2,20);
		printf("Please input the path name to save:");
		WhereXY(&x,&y);
		do 
		{
			int n=0;
			Empty(x,y,70,20);
			GoToXY(x,y);
			GetStr(filename,20,2);
			if(filename[0]==27)//按ESC键返回-1 !
				{
					return -1;
				}
			len=strlen(filename);
			if(len==0)//文件名为空!
				{
					Empty(2,21,70,21);
					printf("file is null!please input again!!");
					continue;
				}
			
			for(i=len-1;len>8&&i>len-9;i--)//判断文件名称不能超过8位!
			{
				if(filename[i]=='\\'||filename[i]=='/')
				{
					break;
				}
			}
			if(i==len-9)
			{
				Empty(2,21,70,21);
				printf("input error!the file is out of lenght!please input again!!");
				continue;
			}
			Deal_Space(filename);//去除左空格!
			//测文件名第一个是不是字母,并且第二个是:,并且第三个是\\或/  ( 如果满足这些条件是合法的路径写法)!
			//分别对于有无输入路径时判断文件名是否包含非法字符!
			if(isalpha(filename[0]) && filename[1]==':' && (filename[2]=='\\' ||filename[2]=='/'))
			{
				for(i=0;i<7;i++)
					{
						if(strchr(filename+3,str[i])!=NULL)
							{
								n=i+1;
								Empty(2,21,70,21);
								printf("input error!the file is include '%c' please input again!!",str[i]);
								break;
							}
					}
				if(n==i+1)
				{
					continue;
				}
				new_Drive=toupper(filename[0])-'A'+1; //得到新路径的盘符编号!	
				if(_chdrive(new_Drive))//_chdrive(new_Drive)为真说明盘符不存在!
					{
						Empty(2,21,70,21);
						printf("_Drive is not exist! please input again!!");
						continue;
					}
				else
					{
						_chdir("\\");//改变工作路径!
  						strcpy(tempfile,filename+3);//否则如果存在则把字符copy到tempfile中!
						if(strlen(tempfile)==0)//例如只输入 E:/ 提示出错!
						{
							Empty(2,21,70,21);
							printf("the file is null! please input again!");
							continue;
						}
					}
			}
			else
			{
				for(i=0;i<7;i++)
				{
					if(strchr(filename,str[i])!=NULL)
						{
							n=i+1;
							Empty(2,21,70,21);
							printf("input error!the file is include '%c' please input again!!",str[i]);
								break;
						}
				}
				if(n==i+1)
						continue;
				strcpy(tempfile,filename);//如果没有输入路径则直接copy
			}

			i=0;
			do
			{	
				
				if(tempfile[i]=='\\'||tempfile[i]=='/')// 例如D:/ff/wee/df 如果从ff开始后又碰到\说明要创建一层文件夹!
				{
					j=i;
					i=0;//用于计算每一层文件夹中字符的个数,所以每一层前要置0 !
					*(tempfile+j)='\0';   
					if(_chdir(tempfile)!=0)  
					{
						_mkdir(tempfile);//创建文件夹!
						_chdir(tempfile);//改变工作路径到文件夹下!
					}
					strcpy(tempfile,tempfile+j+1);//再把 例如D:/ff 后的文件名copy到tempfile中
				}
					i++;
			}while(tempfile[i]!='\0');
			
			
			_chdir(buffer);//改变当前工作路径到输入的文件路径下
			if(access(filename,0)==-1)//判断文件名是否存在!
				{
					Auto_Save(filename);
					break;
				}
				else
				{
					Empty(2,21,70,21);//若存在则判断是否要覆盖!
					printf("the file is exist! Do you want to overwrite the file?[y/n]:");
					Exit_Judge();
					if(key=='Y'||key=='y')
					{
						Auto_Save(filename);
						break;
					}
					else if(key=='N'||key=='n')
					{
						Empty(2,21,70,21);
						printf("No overwrite! please input again!!");					
						continue;
					}
				}
			
		}while(1);
		isSave=1;//保存标签!
		return 0;
	
}
//================================读取不同工作目录的文件函数===================================//
int Load_As()
{
	int n=0;
	char filename[20];
	int x,y;
	char str[7]={'*','|',':','?','\"','<','>'};//文件名不能包括的七种字符,其中对于':'在输入合法路径名前三位中的':'是合法的!
	int old_Drive,new_Drive,len,i=0,j=0;
	char buffer[_MAX_PATH];//	_MAX_PATH为最大路径名长度, buffer为接收路径名的字符数组名!
	char tempfile[_MAX_PATH];
	old_Drive=_getdrive();//得到当前工作盘符!
	_getdcwd(old_Drive,buffer,_MAX_PATH);//保存当前工作路径!
	GoToXY(2,18);
	printf("example as e:/ye/ye.txt  e:\\e\\ye.txt");//例子:对于'/'或'\'都是合法的!
	GoToXY(2,20);
	printf("Please input the path name to load:");
	WhereXY(&x,&y);
	do
	{
		Empty(x,y,70,20);
		GoToXY(x,y);
		GetStr(filename,20,2);
		if(filename[0]==27)//按ESC返回-1!
		{
			return -1;
		}
		len=strlen(filename);
		if(len==0)//文件名为空!
		{
			Empty(2,21,70,21);
			printf("file is null! please input again!!");
			continue;
		}
		for(i=len-1;len>8&&i>len-9;i--)//判断文件名称不能超过8位!
			{
				if(filename[i]=='\\'||filename[i]=='/')
				{
					break;
				}
			}
		if(i==len-9)
		{
			Empty(2,21,70,21);
			printf("input error!the file is out of lenght!please input again!!");
			continue;
		}
		Deal_Space(filename);//去除左空格!
		//测文件名第一个是不是字母,并且第二个是:,并且第三个是\\或/  ( 如果满足这些条件是合法的路径写法)!
		//分别对于有无输入路径时判断文件名是否包含非法字符!
		if(isalpha(filename[0]) && filename[1]==':' && (filename[2]=='\\' ||filename[2]=='/'))
		{ 
			for(i=0;i<7;i++)
			{
				if(strchr(filename+3,str[i])!=NULL)
				{
					n=1;
					Empty(2,21,70,21);
					printf("input error!the file is include '%c' please input again!!",str[i]);
						break;
				}
			}
			if(n==i+1)
					continue;


			new_Drive=toupper(filename[0])-'A'+1;//得到新路径的盘符编号! 
			if(_chdrive(new_Drive))//_chdrive(new_Drive)为真说明盘符不存在!
			{
				Empty(2,21,70,21);
				printf("_Drive is not exist! please input again!!");
				continue;
			}
			else
			{
				_chdir("\\");//改变工作路径!
  				strcpy(tempfile,filename+3);//否则如果存在则把字符copy到tempfile中!
				if(strlen(tempfile)==0)//例如只输入 E:/ 提示出错!
						{
							Empty(2,21,70,21);
							printf("the file is null! please input again!");
							continue;
						}
			}
		}
		else
			{
				for(i=0;i<7;i++)
				{
					if(strchr(filename,str[i])!=NULL)
					{
						n=1;
						Empty(2,21,70,21);
						printf("input error!the file is include '%c' please input again!!",str[i]);
							break;
					}
				}
				if(n==i+1)
						continue;
				strcpy(tempfile,filename);//如果没有输入路径则直接copy!
			}
		_chdir(buffer);
		if(access(filename,0)==-1)//判断文件名是否存在!
			{
				Empty(2,21,70,21);
				printf("the file is not exist! please input any key to continue!");
				getch();
				continue;
			}
			else
			{
				Empty(2,21,70,21);//若存在则是否要 Load!
				printf("the file is exist! Do you want to continue load the file?[y/n]:");
				Exit_Judge();
				if(key=='Y'||key=='y')
				{
					Auto_Load(filename);
					break;
				}
				else if(key=='N'||key=='n')
					continue;
			}

	}while(1);
	return 0;
}
//================================判断函数===================================//
void Exit_Judge()
{      
	do{
		key=getch();
		if(key=='Y'||key=='y'||key=='N'||key=='n')
			{  
				break;
			}
		else 
			{
				Empty(2,21,60,21);
				printf("you must input Y[y] or N[n]:");
				continue;
			}
	}while(1);
}
//================================自动生成学号===================================//
int AutomaticSno()
{
	int i;
	LinkList *q;
	for(i=1;i<=100;i++)
			{
				q=head;
				while(q!=NULL)
				{
					if(q->data.sno==i)
						break;
					q=q->next;
				}
				if(q==NULL)
					break;
			}
	return i;
			
} 	
//================================修改函数===================================//

void Modify_Function()//修改查询到的一条学生记录!
{
	LinkList *p=temphead,*q=head;
	char m[6],ch;
	if(p->next!=NULL)
	{
		Empty(2,20,70,21);
		printf("please input a sno you want to modify:");
		Sno_Judge(m);
		while(p!=NULL)
		{
			if(p->data .sno ==atoi(m))
			{
				break;
			}
			p=p->next;
		}
		if(p==NULL)
		{
			Empty(2,21,70,21);
			printf("not find the sno !! please input any key to return!");
			getch();
			return;
		}
		while(q!=NULL)
		{
			if(q->data .sno==atoi(m))
				break;
			q=q->next;
		}
	}
	GoToXY(34,3);
	Empty(32,3,44,3);
	printf("Modify Menu");
	Empty(2,17,77,18);
	printf("[0]return;[1]name;[2]age;[3]chin;[4]engl;[5]math;[6]phys; [7]chemi");
	do
	{
		Empty(60,5,75,5);
		Empty(5,6,75,15);
		printf("%03d %-15s %4d %5.1f% 5.1f %5.1f %5.1f %6.1f\n",p->data.sno ,p->data.name ,p->data.age  , p->data.score [0]  ,p->data.score [1]  ,p->data.score [2] ,p->data.score [3]  ,p->data.score [4]);
		ch=Personalized_Tips(26,16,7);
		switch(ch)//菜单选择!
		{
			case '1':
				Empty(2,20,70,20);
				printf("please input a new name you want to modify:");
				Name_Judge(p->data.name);
				q->data =p->data ;
				Empty(2,21,70,21);
				printf("modify success!please input any key to continue!");
				getch();
				Empty(2,20,70,21);
				break;
			case '2':
				Empty(2,20,70,20);
				printf("please input a new age you want to modify:");
				p->data.age=Age_Judge(m);
				q->data =p->data ;
				Empty(2,21,70,21);
				printf("modify success!please input any key to continue!");
				getch();
				Empty(2,20,70,21);
				break;
			case '3':
				Empty(2,20,70,20);
				printf("please input a new chin you want to modify:");
				p->data.score[0]=Score_Judge(m,20);
				q->data =p->data ;
				Empty(2,21,70,21);
				printf("modify success!please input any key to continue!");
				getch();
				Empty(2,20,70,21);
				break;
			case '4':
				Empty(2,20,70,20);
				printf("please input a new engl you want to modify:");
				p->data.score[1]=Score_Judge(m,20);
				q->data =p->data ;
				Empty(2,21,70,21);
				printf("modify success!please input any key to continue!");
				getch();
				Empty(2,20,70,21);
				break;
			case '5':
				Empty(2,20,70,20);
				printf("please input a new math you want to modify:");
				p->data.score[2]=Score_Judge(m,20);
				q->data =p->data ;
				Empty(2,21,70,21);
				printf("modify success!please input any key to continue!");
				getch();
				Empty(2,20,70,21);
				break;
			case '6':
				Empty(2,20,70,20);
				printf("please input a new phys you want to modify:");
				p->data.score[3]=Score_Judge(m,20);
				q->data =p->data ;
				Empty(2,21,70,21);
				printf("modify success!please input any key to continue!");
				getch();
				Empty(2,20,70,21);
				break;
			case '7':
				Empty(2,20,70,20);
				printf("please input a new chemi you want to modify:");
				p->data.score[4]=Score_Judge(m,20);
				q->data =p->data ;
				Empty(2,21,70,21);
				printf("modify success!please input any key to continue!");
				getch();
				Empty(2,20,70,21);
				break;
			case '0':
				return;
		}	
}while(1);

}


⌨️ 快捷键说明

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