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

📄 mis_sms(finish).c

📁 学生信息管理系统 代码量在3000左右。原创作品。(内附程序流程图)
💻 C
📖 第 1 页 / 共 5 页
字号:
		printf("[1] .save data to \"%s\"",loadfilename);
		GoToXY(28,11);
		printf("[2] .save as new file");
		GoToXY(28,12);
		printf("[0] .cancel back to menu");
		GoToXY(28,14);
		printf("Please make a choise[0-2]");
		do {
			key = GetchKey();
		}while (!(key == _0 || key == _1 || key == _2 || key == _ESC));
		if (key == _0 || key == _ESC)
			return -1;
		if (key == _1)
		{
			WriteData(loadfilename);
			return -1;
		}
	     ClearAll();
	}
    GoToXY(24,10);
	printf("Please Input file name:");		
	while (1)		//外层
	{	
		if (GetString(fn,8)==-1)
		return -1;		
		strcpy(fn,Del_LeftRightSpace(fn));
		filename=IsValidFileName(fn);
		if (filename == ISVALID_FILENAME_ERROR)
		{
			ClearAll();
			GoToXY(1,19);		
			printf("Error, The File name can't contain character [\/<>*?.']");
			GoToXY(1,20);
			printf("Press any key to continue");
			GetchKey();
			Clear(1,19);
			Clear(1,20);
			GoToXY(17,10);
			printf("Please input a new file name:");
		}
		if (filename == ISVALID_FILENAME_EMPTY)
		{	
			ClearAll();
			GoToXY(24,10);		
			printf("Error, File name cant empty !!!");
			GoToXY(24,12);
			printf("Please input a file name:");
		}
		if (filename == ISVALID_FILENAME_OVERFLOW)
		{
			ClearAll();
			GoToXY(17,10);		
			printf("Error, overflow, The length of file name cant over 8 bit!");
			GoToXY(17,12);
			printf("Please input a new file name:");
		}
		if (filename == ISVALID_FILENAME_ERRORDOT)
		{
			ClearAll();
			GoToXY(17,10);		
			printf("Error, position of the first dot in the file name");
			GoToXY(17,12);
			printf("Please input a new file name:");
		}
		if (filename == ISVALID_FILENAME_VALID)
		{

			if  ((fp=fopen(fn,"r"))!=NULL)  //如果有重名
				{
					while(1)  //内层
					{	
						ClearAll();
						if (label == 0)	
						{
							GoToXY(20,7);
							printf("File name also existed,Would you cover it ?? ");
						}
						else 
						{
							GoToXY(24,7);
							printf("File has existed,Would you cover it ??        ");
						}
						GoToXY(18,9);           
						printf("           [1]. yes");
						GoToXY(18,10);
						printf("           [2]. no ");
						GoToXY(18,11); 
						printf("           [0]. cancel");
						GoToXY(13,13);
						printf("           Please make a choise[0-2]");
						key = GetchKey();			
						if (key == _2)	
						{
							ClearAll();			 
							GoToXY(24,10);
							printf("Input a new file name:");
							break;	//跳出内层循环重新输入文件名
						}
						if (key == _1 || key == _0 || key == _ESC)
							break;
					}	//内层循环结束
					if (key == _1)
						break;   //跳出外层循环覆盖文件
					if (key == _0 || key == _ESC)
						return -1;//返回MENU
						label=0;
				}//end if (里面的)
			else 
				break;
		} //end if (外面的)
		savedatalabel=0;
	} //外层循环结束

	if (WriteData(fn) == -1)
	{
		strcpy(loadfilename,fn);
			return -1;
	}	
    return 0;
}

int InputName(char *sname)
{
	int len,i;
	int inputcheck;
	GoToXY(30,4);
	for (i=0;i<20;i++)
		printf(" ");
	while(1)
	{
		GoToXY(1,19); 
		printf("Please Enter Name                           ");
		GoToXY(30,4);
		inputcheck=GetString(sname,20);
		strcpy(sname,Del_LeftRightSpace(sname));
		//inputcheck=InputDataCheck(sname,20,30,4);	
		if (inputcheck == -1)
		{	
			if(p==NULL)
				return -1;
				if (atoi(p->data.sno)==1)
				head=NULL;
			return -1;
		}
		if (inputcheck==EMPTY || strcmp(sname,"")==0 )
		{
			ClearMassage();
			ErrorAlart("name","empty",30,4);			
			continue;
		}		
		len=strlen(sname);		
		for (i=0;i<len;i++)		   
		{  
/*******************************************************
		  if (sname[i]==' ' && sname[i+1]==' ')
			{
				break;
			}
*******************************************************/
			if (isalpha(sname[i]) ==0 && sname[i]!=' ')					   						   
				break;
		}		
		if (i!=len || len==0 || len > 20) //名字不合法	
		{ 
			ClearMassage();
			ErrorAlart("name","",30,4);
			continue;;//重新输入名字
		}		
		break;
	}	
	return 0;
}


char *InputAge(char age[3])
{
	int i,len;
	int inputcheck;
	GoToXY(30,5);	
		for (i=0;i<4;i++)
		{
			printf(" ");
		}
	while(1)
	{  //输入年龄
		Clear(1,19);
		GoToXY(1,19); 
		printf("Please Enter Age[10-20]");		
		GoToXY(30,5);
		inputcheck=GetString(age,2);
		//inputcheck=InputDataCheck(age,2,30,5);
		strcpy(age,Del_LeftRightSpace(age));
		strcpy(age,LeftRightZero(age));
		len=strlen(age);
		if (inputcheck == -1)
			return -1;
		if (inputcheck==EMPTY || strcmp(age,"")==0)
		{
			ClearMassage();
			ErrorAlart("age","empty",30,5);						
			continue;
		}
		
		if(	IdentifyDigit(age) && atoi(age)>=10 && atoi(age)<=20 && len!=0 && len<3 )
			return 0;//p->data.sage=atoi(age);
		else 
		{	
			ErrorAlart("age","",30,5);			
			continue;//重新输入年龄
		}
		break;
	}
	return 0;
}
/*
*************************************************************
* 函数描述:学生信息添加函数
* 输入参数:无
* 返回值  :-1 返回MENU
*************************************************************
*/
int Add()//添加学生信息
{	 	
	char sname[21],age[3],key;
    int i,j,len,point;
	int inputcheck;
	float savg,stotal;
	char stu_No[4]={'0','0','0','\0'};
	GoToXY(31,0);
	printf("Add Student's Info");		
	if (head==NULL)		//如果内存没有数据
	{
		head = tail = (Stu_Lnode *)malloc(sizeof(Stu_Lnode));  
		dataend=1;
	}
	else		
	{
		p=head->next;//p指向第一个节点	
		p->pre = head;
		while (stu_count > atoi(p->data.sno)) 
		{	
			temp=p;
			p=p->next;
			p->pre=temp;
		}
		while (stu_count == atoi(p->data.sno))	//学号与已存的冲突且不指向尾节点
		{
			if (p != tail)
			{
				stu_count++;   //学号加一
				temp = p;		//temp 指向不冲突的节点的前一个位置
				p=p->next;		//p 
				p->pre = temp;
			}
			else 
			{
				dataend=1;
				stu_count++;
				break;
			}
		}
		
		
	}
	if (stu_count <= STU_MAX)	
	{   		
		p=(Stu_Lnode *)malloc(sizeof(Stu_Lnode));
		sprintf(stu_No,"%03d",stu_count);
        
		strcpy(p->data.sno,stu_No);		
        PrintSubjectMenu(stu_No);
		
		if (InputName(sname)==-1)
			return -1;
		
		strcpy(p->data.sname,sname);
		GoToXY(30,4);
		for (i=0;i<20;i++)
		{
			printf(" ");
		}
		GoToXY(30,4);
		printf("%s",p->data.sname);		
		if(InputAge(age)==-1&& atoi(p->data.sno)==1)
		{

			head=NULL;
			return -1;
		}
		p->data.sage=atoi(age);
		GoToXY(30,5);
		for (i=0;i<20;i++)
		{
			printf(" ");
		}	  
		GoToXY(30,5);
		printf("%d",p->data.sage);		
		if(
			InputGrade(p->data.schi,  "chinese","",6)	==-1
			||		
			InputGrade(p->data.seng,  "english","",7)	==-1
			||
			InputGrade(p->data.smath,"mathematics","",8)==-1
			||
			InputGrade(p->data.spho,  "Phogric","",9)	==-1
			||
			InputGrade(p->data.sche,  "Chemical","",10)	==-1
			)
			return -1;
		
			
		
		if (dataend != 1)
		{
			if (stu_count != 1)
			{
				p->next = temp->next;
				temp->next = p;
				p->pre=temp;
			}
			else
			{
				p->next=head->next;
				head->next=p;
				p ->pre=head;
			}
		}
		else
		{
			tail->next = p;
			p->pre = tail;
			tail = p;
			tail->next = NULL;			
			dataend = 1;
		}
		
		savedatalabel=1;
		filedatachange = 1;	
		GoToXY(1,19);
		printf("Input student info successful!!!               ");
		GoToXY(2,12);
		printf("                                                ");		
		if (stu_count != 999)
		{
			Select();    //弹出选项  continue?back?					  
		}
		else 
		{
			GoToXY(18,12); 
			printf("[Report Fulled,Press Any Key Back to menu!!!]");
			GetchKey();			
			return -1;
		}		
		while (1)
		{
			Select();
			key=GetchKey();
			if (key== _1)
			{
				for (i=0;i<7;i++)
				{
					GoToXY(30,4+i);
					for (j=0;j<20;j++)
					printf(" ");
				}	
				for (i=0;i<2;i++)
				{
					GoToXY(28,12+i);
					for (j=0;j<20;j++)
					printf(" ");
				}
				break;   //继续 
			}   
			if (key == _0|| key == _ESC)
				return -1;   //返回MENU
		}		
     }//end if
		
	 else
	 {   
		 GoToXY(22,10);
		 printf("Report Fulled,Press Any Key to Back");
		 GetchKey();
		 return -1;
	 }

	 return 0;
}


/*
*************************************************************
* 函数描述:学生信息添加函数
* 输入参数:无
* 返回值  :-1 返回MENU
*************************************************************
*/
int AddInfo()
{   
	int x,y;
	int flag;
	int key;
	ClearDisplay(1,1);	
	GoToXY(31,0);
	printf("Add Student's Info");
	
	if (strlen (loadfilename) != 0)    //设变量loadfilename保存已经载入的文件名
	{									//如果不为空,表示有文件被载入
		//提示有文件被访问,新建or追加
		GoToXY(19,9);
		printf("There was a file record opened. File name : \"%s\"",loadfilename);
		GoToXY(26,11);
		printf(" [1]. make a new file");
		GoToXY(26,12);
		printf(" [2]. Add record into this file");
		GoToXY(26,13);
		printf(" [0]. cancel ,back to main menu!!");
		GoToXY(19,15);
		printf(" Please make a choise[0-2]");
		WhereXY(&x,&y);
		while(1)
		{
			key = GetchKey();
			if (key == _0|| key == _ESC)
				return -1;
			if (key == _2)
			{	
				ClearDisplay(1,1);
				do {
					 StructSort(3);
					savedatalabel = 1;
					stu_count=1;
					flag = Add();
				}while (flag != -1);
				break;
			}
			if (key == _1)
			{	
				ClearDisplay(1,1);
				loadfilename[0]='\0';
				head=NULL;			
				stu_count = 1;
				do{
					flag = Add();
				}while (flag != -1)	;
				break;
			}
			else 
			{
				GoToXY(1,19);
				printf("Alert ,please choise between [0-2]");
				GoToXY(1,20);
				printf("Press any key to continue");
				GoToXY(x,y);
				continue;
			}
		}
	}
	else 
	{
		stu_count=1;
		do{
			 StructSort(3);
			flag = Add();
		}while (flag != -1)	;
	}
	
	if (flag == -1)
		return -1;
	return 0;
	
}//end AddInfo()





int Sort(int var)//排序
{
	int count=0,key,s_x,s_y,sign=0,subgrade=3;
	Stu_Lnode *q;
	ClearDisplay(1,1);	
	q=head;
	while(q!=tail)
	{
		count++;
		q=q->next;
	}
	if(count<3)
		subgrade=count;

	if(var == 1)
	{
		PrintTitle("SORT LIST");
		GoToXY(26,8);
		printf("[1].Sort Ascending  by Score");
		GoToXY(26,9);
		printf("[2].Sort Descending by Score");
		GoToXY(26,10);
		printf("[3].Sort Ascending  by No.");
		GoToXY(26,11);
		printf("[4].Sort Descending by No.");
		GoToXY(26,12);
		printf("[0].Back to menu list");
		GoToXY(23,15);
		printf("Please make a choise [0-4]");
	}
	if (var == 2)
	{
		PrintTitle("STAT. LIST");
		PrintRectangle(28,2,"Statistic Top 3");
		GoToXY(26,7);
		printf("[1].Stat. record  by China");
		GoToXY(26,8);
		printf("[2].Stat. record  by English");
		GoToXY(26,9);
		printf("[3].Stat. record  by Math");
		GoToXY(26,10);
		printf("[4].Stat. record  by Physics");
		GoToXY(26,11);
		printf("[5].Stat. record  by Chemical");
		GoToXY(26,12);
		printf("[6].Stat. record  by Total Scorce");
		GoToXY(26,13);
		printf("[0].Back to menu list");
		GoToXY(23,15);
		printf("Please make a choise [0-6]");
	}

		WhereXY(&s_x,&s_y);
		while(1)
		{
			key = GetchKey();
			if (key == _0 || key == _1 || key == _2 || key == _3 || key == _4 || key == _ESC )
			{
				break;
			}
			
			else 
				if(var == 2 && (key == _5 || key == _6)) 
				{
					break;
				}				
				else
				{
					
					if(var==1)
						PrintAlert(4);
					else
						PrintAlert(6);
					GoToXY(s_x,s_y);
				}
			}
			
	if(subgrade==1 && key==_ESC)
	{
		return -1;
	}
			
    if(subgrade!=1)
	{
		switch(key)
			{
			case _0:
			case _ESC:
				return -1;
				break;
			case _1:
				{
					if(var==1)
					{
						sortway=1;
						StructSort(1);						
					}
					else
					{
						StatTopGrade(1,subgrade);
						sign=1;
					}
					break;
				}
			case _2:
				{
					if(var==1)
					{
						sortway=2;
						StructSort(2);						
					}
					else
					{
						StatTopGrade(2,subgrade);
						sign=2;
					}
					break;
				}
			case _3:
				{
					if(var==1)
					{
						sortway=3;
						StructSort(3);						
					}
					else
					{
						StatTopGrade(3,subgrade);
						sign=3;
						
					}
					break;
				}
			case _4:
				{
					if(var==1)
					{
						sortway=4;
						StructSort(4);						
					}
					else
					{
						StatTopGrade(4,subgrade);
						sign=4;
					}
					break;
				}
			case _5:	
				{
					StatTopGrade(5,subgrade);
					sign=5;
					break;
				}
			case _6:	
				{	StatTopGrade(6,subgrade);
					sign=6;

⌨️ 快捷键说明

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