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

📄 wenjianbaocun.c

📁 自己写的简易学生信息管理系统,有很多不足,希望高手多多指教
💻 C
📖 第 1 页 / 共 3 页
字号:
	{
		GetString(name1,20);
		safe=JuadgeName(name1);
		if(safe==1)
		{
			
			if(head==NULL)//没有学生
			{
				temp[0]=NULL;
			}
			p=head;
			while(p!=NULL)//依次查找每条记录,并进行匹配
			{
				strcpy(name2,p->info.name);//先将原始的名字存入临时变量name2
				buffer1=strlwr(name1);//全部转换成小写
				buffer2=strlwr(name2);
				pdest=strstr(buffer2,buffer1);//判断输入的是否是名字的子串
				if(pdest==NULL)//不是名字子串,继续查找下一个
				{
					p=p->next;
				}
				else//是名字的子串,将该学生地址存入temp[]
				{
					
					temp[i]=p;
					p=p->next;
					i++;
					continue;	
				}
			}
			break;//查找完毕跳出
		}	
	}while(1);
	return i;
}




//----------------按学号查找学生---------------------------
/*
	function:按学号查找
	param: 
	return:返回一个学生指针 
*/
struct StudentNode*SearchByNo()
{
	char no[4];
	struct StudentNode *p=NULL;
	system("cls");
	UpdataTitle("Search Student By No");
	GoToXY(15,18);
	ShowMessage("Please Input Sno:");
	do {
		GetString(no,3);
		if(JudgeSno(no)==1)
		{	
			if(head==NULL)
			{
				return NULL;
			}
			p=head;
			while(p!=NULL)
			{
				if(atoi(p->info.sno)==atoi(no)) break;
				p = p->next;
			}
			break;
		}
		else
		{
			GoToXY(0,20);
			ShowMessage("Sno only allow digit 0-3 bit\n");
			ShowMessage("Press any key to continue");
			getch();
			ClearMessage();
			GoToXY(32,18);
			ProductSpace(3);
			GoToXY(32,18);
		}
	} while(1);
	return p;
}

//-----------------------验证学号的合法性-----------------------------
/*
	function:学号的合法验证
	param:  no[] 传入学号
	return: 合法1 ,不合法0
*/
int JudgeSno(char no[])
{
	int i,len;
	len=strlen(no);
	for(i=0;i<len;i++)
	{
		if(isdigit(no[i]))
		{
			continue;
		}
		else
		{
			return 0;
		}
	}
	if(i!=len) return 0;
	else 
	{
		if(len>0 && len<=3)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
}

/*
	function:姓名的合法验证
	param:  name[] 传入学号
	return: 合法1 ,不合法0
*/
int JuadgeName(char name[])
{
	int i,len;
	len=strlen(name);
	if(len<=0||len>20)
	{
		return 0;
	}		
	else
	{
		for(i=0;i<len;i++)
		{
			if(isalpha(name[i])||isspace(name[i]))
			{
				continue;
			}
			else
			{
				return 0;
			}
		}
		if(i!=len) return 0;
		else return 1;
	}
}
/*
	function:打印查询菜单
	param:  
	return: 
*/
void PrintSearchMenu()
{
	char SortMenuList[4][100] = {
		"1. Search student by SNO",
			"2. Search student by Name",
			"0. Return to Main Menu",
			"Please make a choice[0-2]:"
	};
	int i,len,l;
	len=strlen(SortMenuList[3]);
	l=(80-len)/2;
	for(i=0;i<4;i++)
	{
		printf("\n%*s%s",l," ",SortMenuList[i]);
	}
}
//******************排序*************************
/*
	function:学号升序排序
	param:  
	return: 
	*/
void SnoAsce()
{
	struct StudentNode *p,*q,*min;
	struct StudentData temp;
	
	for(p=head;p!=NULL;p=p->next)
	{
		min=p;
		for(q=p->next;q!=NULL;q=q->next)
		{
			if(strcmp(min->info.sno,q->info.sno)>0)
			{
				min=q;
			}	
		}
		if(min!=p)
		{
			temp=min->info;
			min->info = p->info;
			p->info=temp;
		}
	}	
}

//***********************学号插入降序****************************
void SnoDesc()
{
	struct StudentData temp;
	struct StudentNode *p,*q,*k;
	/*	p=(struct StudentNode*)malloc(sizeof(struct StudentNode));
	if(p!=NULL)
	{*/
	for(p=head->next;p!=NULL;p=p->next)
	{	
		//p=(struct StudentNode*)malloc(sizeof(struct StudentNode));
		
		for(q=head;q<p;q=q->next)
		{
			if(strcmp(q->info.sno,p->info.sno)<0)
			{
				
				temp=p->info;
				for(k=p;k>q;k=k->pre)
				{
					k->info=k->pre->info;
				}
				q->info=temp;break;
			}
		}
	}
}

//----------------------------总分选择升序---------------------------------
void TotalScoreAsce()
{
	struct StudentNode *p,*q,*min;
	struct StudentData temp;
	
	for(p=head;p!=NULL;p=p->next)
	{
		min=p;
		for(q=p->next;q!=NULL;q=q->next)
		{
			if(min->info.total > q->info.total)
			{
				min=q;
			}	
		}
		if(min!=p)
		{
			temp=min->info;
			min->info = p->info;
			p->info=temp;
		}
	}	
}

//---------------------------总分插入降序------------------------------
void TotalScoreDesc()
{
	struct StudentData temp;
	struct StudentNode *p,*q,*k;
	for(p=head->next;p!=NULL;p=p->next)
	{	
		for(q=head;q<p;q=q->next)
		{
			if(q->info.total < p->info.total)
			{	
				temp=p->info;
				for(k=p;k>q;k=k->pre)
				{
					k->info=k->pre->info;
				}
				q->info=temp;break;
			}
		}
	}
}

void PrintSortMenu()
{
	char SortMenuList[5][100] = {
		"1. Sort Ascending  by Student's No",
			"2. Sort Desc  by Student No",
			"3. Sort Ascending by Student's TotalScore",
			"4. Sort Desc by Student's TotalScore",
			"0. Return to Main Menu"
	};
	int i,len,l;
	len=strlen(SortMenuList[2]);
	l=(80-len)/2;
	for(i=0;i<=4;i++)
	{
		printf("%*s%s\n",l," ",SortMenuList[i]);
	}
}

void PrintLine()
{
	char line[10][20]=
	{
		"SNO",
			"NAME",
			"AGE",
			"CHIN",
			"ENGL",
			"MATH",
			"PHO",
			"CHE",
			"Total",
			"Avg"
	};
	printf("  -------------------------------------------------------------------------\n");
	printf("  %3s %-20s %4s %4s %4s %4s %4s %4s %5s %5s\n",line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]);	
	printf("  -------------------------------------------------------------------------\n");
	
}

int AccountTotal(struct StudentNode *temp)
{
	int total=0;
	int j;
	for(j=0;j<5;j++)
	{
		total+=temp->info.score[j];
	}
    return	total;
}

float AccountAvg(int total)
{
	float avg;
	avg=(float)total/5.0f;
	return avg;
}

int InputScore(int c)
{
	int len,i;
	char score[4];
	int grade;
	do 
	{	
		len=GetString(score,3);
		Trim(score);
		if(len==0) 
		{
			GoToXY(0,20);
			ShowMessage("Error: score only allow digit [0-100]\n");
			ShowMessage("press any key to continue");
			getch();
			ClearMessage();
			GoToXY(54,c);
			ProductSpace(3);
			GoToXY(54,c);
			continue;
		}
		for(i=0;i<len;i++)
		{	
			if(!(isdigit(score[i])))
			{		
				GoToXY(0,20);
				ShowMessage("Error: score only allow digit [0-100]\n");
				ShowMessage("press any key to continue");
				getch();
				ClearMessage();
				GoToXY(54,c);
				ProductSpace(3);
				GoToXY(54,c);
				break;
			}
		}
		if(i!=len) continue;	
		else
		{ 	
			grade=atoi(score);
			if(grade<0||grade>100)
			{
				GoToXY(0,20);
				ShowMessage("Error: score only allow digit [0-100]\n");
				ShowMessage("press any key to continue");
				getch();
				ClearMessage();
				GoToXY(54,c);
				ProductSpace(3);
				GoToXY(54,c);
			}
			else
			{
				break;
			}
		}
	} while(1);
	GoToXY(54,c);
	ProductSpace(3);
	GoToXY(54,c);
	printf("%d",grade);
	return grade;	
}

void InputAge(char *Age)
{
	int i,len;
	do{
		GoToXY(21,11);
		len=GetString(Age,2);
		for(i=0;i<len;i++)
		{
			if(!(isdigit(Age[i])))
			{
				GoToXY(0,20);
				ShowMessage("Error: age only allow input digit\n");
				ShowMessage("press any key to continue");
				getch();
				ClearMessage();
				GoToXY(21,11);
				ProductSpace (len);
				GoToXY(21,11);
				break;
			}
		}
		if(i!=len) continue;
		
		else
		{
			int age;
			age=atoi(Age);
			if(age<10||age>20)
			{
				GoToXY(0,20);
				ShowMessage("Error: age only allow input [10-20]\n");
				ShowMessage("press any key to continue");
				getch();
				ClearMessage();
				GoToXY(21,11);
				ProductSpace (len);
				GoToXY(21,11);
				continue;
			}
			else
			{
				break;
			}
		}
	}while(1);
}

void InputName(char *name)
{
	int i,len;
	do {
		GoToXY(21,9);
		GetString(name,20);
		Trim(name);
		len=strlen(name);
		if(len<=0)
		{
			GoToXY(0,20);
			ShowMessage("name length not allow null(len=0):\n");
			ShowMessage("press any key to continue");
			getch();
			ClearMessage();
			GoToXY(21,9);
			ProductSpace(len);
			GoToXY(21,9);
			continue;
		}
		else if(len>20)
		{
			GoToXY(0,20);
			ShowMessage("name length not allow overflow(len>20)\n");
			ShowMessage("press any key to continue");
			getch();
			ClearMessage();
			GoToXY(21,9);
			ProductSpace(len);
			GoToXY(21,9);
			continue;
		}
		else
		{
			for(i=0;i<len;i++)
			{
				if(isalpha(name[i])||isspace(name[i]))
				{
					continue;
				}
				else
				{
					GoToXY(0,20);
					ShowMessage("error:name merely allow letter or space:\n");
					ShowMessage("press any key to continue");
					getch();
					ClearMessage();
					GoToXY(21,9);
					ProductSpace(len);
					GoToXY(21,9);
					break;
				}
			}
			if(i!=len)
			{
				continue;
			}
			else 
			{
				break;
			}
		}	
	} while(1);
	Trim(name); //去左右空格
	GoToXY(21,9);
	ProductSpace (len);
	GoToXY(21,9);
	printf("%s",name);
}
//--------------------------------------------------------------
/*
	function:向链表中填加一个节点
	param: newData 学生的数据域
	return: 
*/
void AddNewNode(struct StudentData newData)
{
	struct StudentNode *p;
	p=(struct StudentNode*) malloc(sizeof(struct StudentNode));
	if(p!=NULL)
	{
		p->info=newData;
		p->next=p->pre=NULL;
		
		if(head==NULL)
		{
			head=last=p;
		}
		else
		{
			last->next=p;
			p->pre=last;
			last=p;
		}
	}
	else
	{
		GoToXY(0,20);
		printf("Error:Memory allocate fial\n");
	}
}

//------------------------------------------------------------------

/*
	function:自动获取学号(有补号功能)
	param: ID 学号 ,学号的整型表示(第几天记录)
	return: 
*/
void GetNO(char *ID,int num)
{
	if(USE!=0 )
	{
		if( head==NULL) //没记录时,直接把001号赋给头节点
		{
			USE=1;		//标记该号已使用
			count=0;
			strcpy(snonode.info.sno,"001");
		}
		else 
		{
			struct StudentNode *p;
			SnoAsce(head);   //有多个学生时,将学号按升序排
			if(strcmp(head->info.sno,"001")!=0)  //如果找到第一个不是001,则把001补入
			{	
				strcpy(ID,"001");
				return;
			}
			else//查找断号并补入
			{
				for(p=head->next;p!=NULL;p=p->next)
				{
					if(atoi(p->info.sno)!=atoi(p->pre->info.sno)+1)
					{
						itoa((1001+atoi(p->pre->info.sno)),ID,10);
						strcpy(ID,ID+1);
						return;
					}
				}
			}
			itoa((1000+ (++num)),ID,10);  //只删除末尾是的情况。
			strcpy(ID,ID+1);
		}
	}
	
	else//如果没有断号,直接进行加一
	{	
		itoa((1001+num),ID,10);
		strcpy(ID,ID+1);
	}
}
//=============================================================


void ShowMessage(char msg[100])
{
	printf("%s",msg);
}


void UpdataTitle(char title[])
{
	
	int i,w;
	w=strlen(title);
	printf("%25s%c"," ",218);
	for (i=0;i<28;i++)
	{
		putchar(196);
	}
	putchar(191);
	printf("\n%25s%c"," ",179);
	printf("%*s%-*s",(28-w)/2," ",28-(28-w)/2,title);
	printf("%c\n",179);
	printf("%25s%c","",192);
	for (i=0;i<28;i++)
	{
		putchar(196);
	}
	putchar(217);
	
}
//限定最大长度为Maxlen,只能是可打印字符的字符串
int GetString(char buffer[],int Maxlen)
{	
	int i=0;
	char key;
	
    while(1)
	{
		key=getch();
		if(key<0)		
		{
			getch();
			continue;
		}
		else if(key==13) //回车结束
		{
			break;
		}
		else if(key=='\b')
		{
			if(i!=0)
			{
				printf("%c%c%c",'\b',' ','\b');
				i--;
			}
		}
		else if(isprint(key))
		{
			if(i<Maxlen)
			{
				buffer[i]=key;
				i++;
				putchar(key);
			}
			
		}
	}
	buffer[i]=0;
	return i;
}
//去左空格
void LTrim(char str[100])
{
	int i,len;
	len=strlen(str);
	for(i=0;i<len;i++)
	{
		if(!(isspace(str[i])))
		{
			strcpy(str,&str[i]);                 
			break;
		}	
	}
}
//去右空格
void RTrim(char str[20])
{
	int i,len;
	
	len=strlen(str);
	for(i=len-1;i>=0;i--)
	{
		if(isspace(str[i]))
		{
			str[i+1]=0;
			continue;
		}     
		break;
	}
}
//去左右空格
void Trim(char str[20])
{
	LTrim(str);
	RTrim(str);
}

//光标定位函数
void GoToXY(int x, int y)
{
	COORD pos = {x,y};
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);	// 获取标准输出设备句柄
	
	SetConsoleCursorPosition(hOut, pos);
}

//在第x行,Y列,填充len列,COL行的空格
void FillSpace (int x,int y,int len,int col)
{
	int i,j;
	for (i=0;i<col;i++)
		
	{
		GoToXY(x,y+i);
		
		for (j=0;j<len;j++)
		{
			putchar(' ');
			
		}
	}
}

//空格填补函数 (在指定的位置填充len个空格)
void ProductSpace (int len)
{
	int i;
	for (i=0;i<len;i++)
	{
		putchar(' ');
		
	}
}

void ClearMessage()
{
	FillSpace(0,20,50,2);
}

int GetYN(char key)
{
	if(key=='y'||key=='Y'||key=='N'||key=='n')
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

⌨️ 快捷键说明

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