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

📄 stu_info_7.8.c

📁 linux 下的学生管理系统 非常值得学习的不可或缺的资源!!!!
💻 C
📖 第 1 页 / 共 4 页
字号:
				save_flag=1;
				break;
			}
			else if(ch=='D' || ch=='d')
			{
				DeleteData(num,x,y);
				save_flag=1;
				break;
			}
			else if(ch=='Y' || ch=='y')
			{
				Gotoxy(0,5);
				for(i=5;i<18;i++)  //清除5-17行
					printf("%*s",80," ");
				break;
			}
			else if(ch==27)
			{
				break;
			}
			else
			{
				InputError(x,y,ch);
			}
		}while(1);
	}while(ch=='Y' || ch=='y');
}
/*****************************************************************
***函数名:UpdateData
***参数:int num    (ID) x,y光标
***功能:修改数据
***返回值:无
*****************************************************************/	
void UpdateData(int num,int x,int y)
{
	int i;
	char ch;
	char *NewAddInfo[]=
	{
		"            Name *:",
		"             Age *:",
		"         Chinese *:",
		"         English *:",
		"            Math *:",
		"         Physics *:",
		"       Chemistry *:"
	};
	do
	{	
		ClearMessage();
		Gotoxy(0,19);
		printf("Are you continue Update Data(Y/N)?");
		ch=getche();
		getch();
		if(ch=='Y' || ch=='y')
		{
			Gotoxy(0,6);
			for(i=6;i<18;i++)  //清除5-17行
				printf("%*s",80," ");
			fflush(stdin);
			Gotoxy(26,3);
			printf(UPDATE);	
			Gotoxy(35,7);//学号
			printf("SNO: %s\n",stu[num-1].sno);
			strcpy(data.sno,stu[num-1].sno);
			for(i=0;i<7;i++) //打印菜单
			{
				Gotoxy(20,8+i);
				printf("%s\n",NewAddInfo[i]);
			}
			AddName();
			AddAge();
			AddScore();
			//数据保存
			stu[num-1]=data;
			ClearMessage();
			Gotoxy(0,19);
			printf("Date Update success!");
			getch();
			Gotoxy(0,20);
			printf("Pleased key to continue ...");
			getch();
			return;			
		}
		else if(ch=='N' || ch=='n')
		{
			return ;
		}
		else
		{
			InputError(x,y,ch);
		}
	}while(!(ch=='Y' || ch=='y' || ch=='N' || ch=='n' ));
}
/*****************************************************************
***函数名:DeleteData
***参数:int num    (ID)x,y光标
***功能:删除数据
***返回值:无
*****************************************************************/	
void DeleteData(int num,int x,int y)
{
	int i;
	char ch;
	do
	{	
		ClearMessage();
		Gotoxy(0,19);
		printf("Are you continue Delete Data(Y/N)?");
		ch=getche();
		getch();
		if(ch=='Y' || ch=='y')
		{
			fflush(stdin);
			count--;
			for(i=num-1;i<count;i++)
				stu[i]=stu[i+1];
			sno[num-1]=0;
			ClearMessage();
			Gotoxy(0,19);
			printf("Date Delete success!Pleased key to continue ...");
			getch();
			return;	
			break;
		}
		else if(ch=='N' || ch=='n')
		{
			return ;
			break;
		}
		else
		{
			InputError(x,y,ch);
		}
	}while(1);
}
/*****************************************************************
***函数名:SearchName
***参数:无
***功能:实现姓名精确、模糊查询
***返回值:无
*****************************************************************/	
void SearchName()
{
	int x,y,i,j,flag,k,index=0; //flag找到记录数 k为光标移动	
	int num,len;// 记录SNO;
	char tempname[21];
	STU temp;
	Gotoxy(0,5);
	for(i=5;i<18;i++)  //清除5-17行
		printf("%*s",80," ");
	do
	{
		k=0;
		flag=0;
		Gotoxy(20,10);
		printf("Please Input select name:");
		Getxy(&x,&y);
		ClearMessage();
		Gotoxy(0,19);
		printf("Please Input a-z or A-Z len=1-20 alpha. <example:zhang san>");		
		Gotoxy(x,y);
		gets(tempname);
		Left_Right(tempname); //左右空处理
		len = strlen(tempname);
		if(len==0)
		{
			ClearMessage();
			Gotoxy(0,19);
			printf("Error NULL!Please enter again!");
			getch();
			continue;
		}	
		Gotoxy(20,10);
		printf("Please wait!The system is searching...");
		Sleep(300);
		Gotoxy(0,5);
		for(i=5;i<18;i++)  //清除5-17行
			printf("%*s",80," ");	
		for(j=0;j<count;j++)
		{
			temp=stu[j];
			if(!(strstr(strlwr(temp.name),strlwr(tempname))==NULL))  //找到记录
			{
				flag=1;
				num=atoi(temp.sno);  //把SNO转化为INT型
				Gotoxy(0,5);
				total[j]=stu[j].score[0]+stu[j].score[1]+stu[j].score[2]+stu[j].score[3]+stu[j].score[4];
				avg[j]=(double)total[j]/5.0;
				printf("%-4s%-21s%-4s%-8s%-8s%-5s%-8s%-10s%-6s%-4s\n",
					"sno","name","age","chinese","english","math","physics","chemistry","total","avg");
				Gotoxy(0,6+k);
				printf("%-4s%-21s%-5d%-8.1f%-7.1f%-7.1f%-8.1f%-8.1f%-6.1f%-4.1lf\n",stu[j].sno,stu[j].name,stu[j].age,
					stu[j].score[0],stu[j].score[1],stu[j].score[2],stu[j].score[3],stu[j].score[4],total[j],avg[j]);			
				k++;
				index++;
				if(k%10==0)
				{
					printf("Pleased key to continue ...");
					getch();
					Gotoxy(0,6);
					for(i=6;i<18;i++)  //清除5-17行
					printf("%*s",80," ");
					k=0;
				}
			}
			else  //没有找到记录
			{
				continue;
			}
			if(j>=count)
					break;
		}
		if(!flag)
		{
			ClearMessage();
			Gotoxy(0,19);
			printf("sorry!not record!Pleased key to continue ...");
			getch();
			break;
		}
		else
		{
			ClearMessage();
			Gotoxy(0,19);
			printf("select KeyWords:%-4s success! Counts=%d",tempname,index);
		}
		do
		{
			Gotoxy(16,17);
			printf("The default delete, update the last record!");
			Gotoxy(8,16);
			printf("Press [U/u] Update  [D/d] Delete  [Y/y] Continue  [Esc] Back:");
			Getxy(&x,&y);
			//[U]/[u] 85/117 [D]/[d] 68/100
			ch=getche();
			Gotoxy(0,20);
			printf("%*s",80," ");
			if(ch=='U' || ch=='u')
			{
				UpdateData(num,x,y);
				save_flag=1;
				break;
			}
			else if(ch=='D' || ch=='d')
			{
				DeleteData(num,x,y);
				save_flag=1;
				break;
			}
			else if(ch=='Y' || ch=='y')
			{
				Gotoxy(0,5);
				for(i=5;i<18;i++)  //清除5-17行
					printf("%*s",80," ");
				break;
			}
			else if(ch==27)
			{
				break;
			}
			else
			{
				InputError(x,y,ch);
			}
		}while(1);
	}while(ch=='Y' || ch=='y');
}
/*****************************************************************
***函数名:SortData
***参数:无
***功能:实现学号、姓名升序、降序
***返回值:无
*****************************************************************/		
void SortData()
{
	int s, i,x,y;
	char *Sort[]=
	{	"1.sno ASC:",
		"2.sno DESC:",
		"3.name ASC:",
		"4.name DESC:",
		"5.score ASC",
		"6.score DESC",
		"0.return MenuList:"
	};
	system("cls");
	Gotoxy(33,3);
	printf(SORTDATA);	
	MakeMenuInfo();	
	Gotoxy(0,6);
	s=JuZhong(Sort,7);	//菜单项--居中显示
	for(i=0;i<=6;i++)    //打印菜单项
		printf("%*s%s\n",s," ",Sort[i]);
	Gotoxy(0,0);
	Gotoxy(26,14);
	printf("Please Make a choices[0-6]:");
	Getxy(&x,&y);
	if(count==0)
	{
		ClearMessage();
		Gotoxy(0,19);
		printf("Error!Data is NULL.");
		printf("Pleased key to continue ...");
		fflush(stdin);
		getch();
		return;
	}
	do
	{
		fflush(stdin);
		ch=getche();
		getch();
		switch(ch)
		{
			case '1':SortSnoAsc();SortData();break;
			case '2':SortSnoDesc();SortData();break;
			case '3':SortNameAsc();SortData();break;
			case '4':SortNameDesc();SortData();break;
			case '5':SortTotalAsc();SortData();break;
			case '6':SortTotalDesc();SortData();break;
			case '0':return;break;
			default:InputError(x,y,ch);break;
		}
	}while(!(ch>='0' && ch<='6'));

}
/*****************************************************************
***函数名:Sort_Print_Message
***参数:无
***功能:实现5-17行清空,相关信息打印
***返回值:无
*****************************************************************/
void Sort_Print_Message()
{
	int i;
	Gotoxy(0,5);
	for(i=5;i<18;i++)  //清除5-17行
		printf("%*s",80," ");
	ClearMessage();
	Gotoxy(0,19);
	printf("Please wait!The system is Sorting...");
	Sleep(300);
}
/*****************************************************************
***函数名:SortSnoAsc
***参数:无
***功能:实现学号升序 ----冒泡
***返回值:无
*****************************************************************/
void SortSnoAsc() 
{
	int i,j,r,k;
	STU temp;
	Sort_Print_Message();
	for(i=1,r=count-1,k=count;i<=r;r=k-1)
	{
		for(j=r;j>=i;j--)  //上浮
		{
			if(strcmp(stu[j-1].sno,stu[j].sno)>0) 
			{
				temp=stu[j];
				stu[j]=stu[j-1];
				stu[j-1]=temp;
				k=j;
			}
		}
		for(j=k+1,i=k+1;j<=r;j++) //下沉
		{
			if(strcmp(stu[j-1].sno,stu[j].sno)>0) 
			{
				temp=stu[j];
				stu[j]=stu[j-1];
				stu[j-1]=temp;
				k=j;
			}
		}
	}
	PrintData();
}
/*****************************************************************
***函数名:SortSnoDesc
***参数:无
***功能:实现学号降序----冒泡(上浮/下沉)
***返回值:无
*****************************************************************/
void SortSnoDesc() 
{
	int i,j,r,k;
	STU temp;
	Sort_Print_Message();
	for(i=1,r=count-1,k=count;i<=r;r=k-1)
	{
		for(j=count-1;j>=i;j--)  //上浮
		{
			if(strcmp(stu[j-1].sno,stu[j].sno)<0) 
			{
				temp=stu[j];
				stu[j]=stu[j-1];
				stu[j-1]=temp;
				k=j;
			}
		}
		for(j=k+1,i=k+1;j<=r;j++) //下沉
		{
			if(strcmp(stu[j-1].sno,stu[j].sno)<0) 
			{
				temp=stu[j];
				stu[j]=stu[j-1];
				stu[j-1]=temp;
				k=j;
			}
		}
	}
	PrintData();
}
/*****************************************************************
***函数名:SortNameAsc
***参数:无
***功能:实现姓名升序--选择
***返回值:无
*****************************************************************/
void SortNameAsc() 
{
	int i,j,k;
	STU temp; 
	Sort_Print_Message();
	for(i=0;i<count-1;i++) 
	{
		k=i;
		for(j=i+1;j<count;j++)
		{
			if(strcmp(stu[j].name,stu[k].name)<0)
				k=j;
		}
		if(k!=i)
		{
			temp=stu[k];
			stu[k]=stu[i];
			stu[i]=temp;
		}
	}
	PrintData();
}
/*****************************************************************
***函数名:SortNameDesc
***参数:无
***功能:实现姓名降序--选择
***返回值:无
*****************************************************************/
void SortNameDesc()
{
	int i,j,k;
	STU temp; 
	Sort_Print_Message();
	for(i=0;i<count-1;i++) 
	{
		k=i;
		for(j=i+1;j<count;j++)
		{
			if(strcmp(stu[j].name,stu[k].name)>0)
				k=j;
		}
		if(k!=i)
		{
			temp=stu[k];
			stu[k]=stu[i];
			stu[i]=temp;
		}
	}
	PrintData();
}
/*****************************************************************
***函数名:SortTotalAsc
***参数:无
***功能:实现总成绩升序------插入排序
***返回值:无
*****************************************************************/
void SortTotalAsc()
{
	int i,j;
	float t;
	STU temptotal;
	Sort_Print_Message();
	for(i=0;i<count;i++)
		total[i]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+stu[i].score[4];
	for(i=1;i<count;i++)
	{
		for(j=0;j<i;j++)
		{
			if(total[j]>total[i])
			{
				temptotal=stu[j];
				stu[j]=stu[i];
				stu[i]=temptotal;
				t=total[j];
				total[j]=total[i];
				total[i]=t;
			}
		}
	}
	PrintData();
}
/*****************************************************************
***函数名:SortTotalDesc
***参数:无
***功能:实现总成绩降序------插入排序
***返回值:无
*****************************************************************/
void SortTotalDesc()
{
	int i,j;
	float t;
	STU temptotal;
	Sort_Print_Message();
	for(i=0;i<count;i++)
		total[i]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+stu[i].score[4];
	for(i=1;i<count;i++)
	{
		for(j=0;j<i;j++)
		{
			if(total[j]<total[i])
			{
				temptotal=stu[j];
				stu[j]=stu[i];
				stu[i]=temptotal;
				t=total[j];
				total[j]=total[i];
				total[i]=t;
			}
		}
	}
	PrintData();
}
/*****************************************************************
***函数名:Getfilename

⌨️ 快捷键说明

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