学生信息系统简单实现C语言

/*
 * name:Student_information.cpp
 * author:xdc
 * time:2013年3月31日15:58:58
 *
 * 问题描述:
 * 	学籍管理问题中的数据元素包括学号、姓名、性别、出生日期、政治面貌和家庭住址等数据项。
 * 功能要求:
 * 	⑴ 插入:将某学生的基本信息插入到登记表中;
 *	⑵ 删除:将满足条件的基本信息删除;
 * 	⑶ 修改:对基本信息的数据项进行修改;
 *	⑷ 查询:查找满足条件的学生;
 *	⑸ 输出:将登记表中的全部(或满足条件)基本信息输出。
 *
 *实现要点:
 *	对学籍登记表采用顺序存储结构(也可以采用其他存储结构),在建立表时,由登记表的书写形式转化顺序表存储结构,还要把学生的书面形式转化为具体的类。
 *
 *以上功能是基本内容,可以自行扩展。如:
 *  (1)排序或找前3名;
 *  (2)用文件来存储数据。
 */

# include <stdio.h>
# include <malloc.h>	//包含了malloc函数
# include <stdlib.h>	//包含了exit函数
# include <string.h>	//包含strcpy函数
# include <time.h>		//测试运行时间

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//学生基本信息
typedef struct Student
{
	char name[21];					//姓名
	//__int64 sid;					//学号,主键
	long sid;						//学号,主键
	char ssex[3];					//性别
	char nation[11];				//民族
	//__int64 date_of_birth;		//生日
	long date_of_birth;				//生日
	char poli_sta[11];				//政治面貌
	char addr[101];					//家庭住址
	char depart[21];				//院系
	char major[21];					//专业

	//更多信息操作相同
}* PSTU, STU;


//用于操作学生信息集
struct Stu_ctrl
{
	PSTU pBase;				//存储的是数组第一个元素的地址
	long len;				//数组所能容纳的最大元素的个数
	long cnt;				//当前数组有效元素的个数
};

void init_stu(struct Stu_ctrl * pStu, long length);						//初始化
bool append_stu(struct Stu_ctrl * pStu, STU val);						//追加,追加和插入构成输入
bool insert_stu(struct Stu_ctrl * pStu, long pos, STU val);				//按位置插入,pos的值从1开始
bool delete_stu_pos(struct Stu_ctrl * pStu, long pos, PSTU pVal);		//按位置删除
bool delete_stu_val(struct Stu_ctrl * pStu, char * prop, char * val);	//按值删除
long get(struct Stu_ctrl * pStu);										//获取总人数
long find(struct Stu_ctrl * pStu, char * prop, char * val);				//按值查找并输出
bool revise_stu(struct Stu_ctrl * pStu, char * prop, char * be_val, char * aft_val);	//修改
bool is_empty(struct Stu_ctrl * pStu);									//判断是否为空
bool is_full(struct Stu_ctrl * pStu);									//判断是否为满
void sort_stu_id(struct Stu_ctrl * pStu);								//按学号排序
void show_stu(struct Stu_ctrl * pStu);									//整体输出
void show_stu_one(struct Stu_ctrl * pStu, long pos);					//单个输出
void inversion_stu(struct Stu_ctrl * pStu);								//逆置
bool BF(char * S, char * T);											//字符串匹配
bool is_string(char * A, char * B);										//判断字符串相等
void input_stu(PSTU val);												//信息输入
bool top_n_stu(struct Stu_ctrl * pStu, /*char * prop,*/ long n);		//前n名
void add_arr_stu(struct Stu_ctrl * pStu);								//添加学生信息
bool revise_all_stu(struct Stu_ctrl * pStu, char * prop);				//更据姓名或学号修改学生所有信息
void run_stu_infor_test(struct Stu_ctrl * pStu);						//测试函数

/

//主函数,程序入口
int main(void)
{
	double t;
	char ch;
	struct Stu_ctrl sdu_stu;
	//STU val = {"xdc", 2010, "男", "汉", 1990, "党员", "山东省济南市山大南路27号", "数学学院", "信息安全"};

	//init_stu(&sdu_stu, 10000);	//假设用于存储10000个学生的信息

	printf("欢迎试用山东大学数学学院学生信息管理系统!\n\n");

	t=clock();

	run_stu_infor_test(&sdu_stu);	//测试函数

	//测试时间
    printf("耗时%f毫秒!(含信息输入时间)\n", (clock()-t)); 
    scanf("%c", &ch);

	//system("Student_information4.1.exe>1.txt");

	return (0);
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

/*************************************测试函数*************************************************************/
void run_stu_infor_test(struct Stu_ctrl * pStu)
{
	STU val = {"xdc", 2010, "男", "汉", 1990, "党员", "山东省济南市山大南路27号", "数学学院", "信息安全"};

	init_stu(pStu, 10000);				//假设用于存储10000个学生的信息

	printf("您还没有学生信息\n");

	append_stu(pStu, val);				//添加初始信息

	add_arr_stu(pStu);					//添加信息
	//input_stu(&val);
	//append_stu(pStu, val);			//追加

	printf("插入信息\n\n");
	insert_stu(pStu, 2, val);			//插入

	printf("排序\n\n");
	sort_stu_id(pStu);					//按学号排序

	show_stu(pStu);						//输出

	printf("删除信息\n\n");
	delete_stu_pos(pStu, 1, &val);		//删除

	show_stu(pStu);	//输出

//	if (BF("abbdsdh", "a"))
//		printf("suc\n");

	append_stu(pStu, val);	//添加初始信息
	append_stu(pStu, val);	//添加初始信息
	append_stu(pStu, val);	//添加初始信息
	append_stu(pStu, val);	//添加初始信息


	printf("查找信息\n\n");
	find(pStu, "name=", "xdc");

//	show_stu_one(pStu, 1);

	printf("删除信息\n\n");
	delete_stu_val(pStu, "name=", "x");	//按值删除

//	if (is_string("qw ", "qw "))
//		printf("su213\n");

	printf("前n名\n\n");
	top_n_stu(pStu, 2);

//	free(sdu_stu);

	//system("Student_information4.1.exe>1.txt");
}


/*************************************信息表初始化*************************************************************/
void init_stu(struct Stu_ctrl * pStu, long length)
{
	pStu->pBase = (PSTU)malloc(sizeof(STU) * length);
	if (NULL == pStu->pBase)
	{
		printf("动态内存分配失败!\n");
		exit(-1); //终止整个程序
	}
	else
	{
		pStu->len = length;
		pStu->cnt = 0;
	}

	return;
}


/********************************判断是否为空*********************************************************/
bool is_empty(struct Stu_ctrl * pStu)
{
	if (0 == pStu->cnt)
		return true;
	else
		return false;		
}


/*******************************判断是否为满***********************************************************************/
bool is_full(struct Stu_ctrl * pStu)
{
	if (pStu->cnt == pStu->len)
		return true;
	else
		return false;
}


/*******************************输出信息***********************************************************************/
void show_stu(struct Stu_ctrl * pStu)
{
	printf("姓名\t学号\t性别\t民族\t出生日期\t政治面貌\t家庭住址\t院系\t专业\n");

	if ( is_empty(pStu) )   
	{
		printf("学生信息表为空!\n");
	}
	else
	{
		for (long i=0; i < pStu->cnt; ++i)
		{
			//姓名
			printf("%s\t", pStu->pBase[i].name);
			//学号
			printf("%ld\t", pStu->pBase[i].sid); 
			//性别
			printf("%s\t", pStu->pBase[i].ssex); 
			//民族
			printf("%s\t", pStu->pBase[i].nation); 
			//出生日期
			printf("%ld\t", pStu->pBase[i].date_of_birth); 
			//政治面貌
			printf("%s\t", pStu->pBase[i].poli_sta); 
			//家庭住址
			printf("%s\t", pStu->pBase[i].addr); 
			//院系
			printf("%s\t", pStu->pBase[i].depart); 
			//专业
			printf("%s\n", pStu->pBase[i].major); 
		}
	}
}


/*******************************追加***********************************************************************/
bool append_stu(struct Stu_ctrl * pStu, STU val)
{
	//满是返回false
	if ( is_full(pStu) )
		return false;

	
	//不满时追加
	pStu->pBase[pStu->cnt] = val;

	(pStu->cnt)++;

	return true;
}


/*******************************按位置插入***********************************************************************/
bool insert_stu(struct Stu_ctrl * pStu, long pos, STU val)
{
	long i;

	if (is_full(pStu))
		return false;

	if (pos<1 || pos>pStu->cnt+1)  //
		return false;

	for (i=pStu->cnt-1; i>=pos-1; --i)
	{
		pStu->pBase[i+1] = pStu->pBase[i];
	}
	pStu->pBase[pos-1] = val;
	(pStu->cnt)++;

	return true;
}


/*******************************按位置删除**********************************************************************/
bool delete_stu_pos(struct Stu_ctrl * pStu, long pos, PSTU pVal)
{
	int i;

	if ( is_empty(pStu) )
		return false;
	if (pos<1 || pos>pStu->cnt)
		return false;

	*pVal = pStu->pBase[pos-1];
	for (i=pos; i<pStu->cnt; ++i)
	{
		pStu->pBase[i-1] = pStu->pBase[i];
	}
	pStu->cnt--;

	return true;
}


/*******************************逆置***********************************************************************/
void inversion_stu(struct Stu_ctrl * pStu)
{
	int i = 0;
	int j = pStu->cnt-1;
	STU t;

	while (i < j)
	{
		t = pStu->pBase[i];
		pStu->pBase[i] = pStu->pBase[j];
		pStu->pBase[j] = t;
		++i;
		--j;
	}
	return;
}


/*******************************按学号排序***********************************************************************/

void sort_stu_id(struct Stu_ctrl * pStu)
{
	long i, j;
	STU t;

	for (i=0; i<pStu->cnt; ++i)
	{
		for (j=i+1; j<pStu->cnt; ++j)
		{
			if (pStu->pBase[i].sid > pStu->pBase[j].sid)
			{
				t = pStu->pBase[i];
				pStu->pBase[i] = pStu->pBase[j];
				pStu->pBase[j] = t;
			}
		}
	}
}



/*******************************按值查找并输出******************************************************/
long find(struct Stu_ctrl * pStu, char * prop, char * val)
{
	long i;
	long sum = 0;
	int temp = 0;

	if (is_string(prop, "name="))
		temp = 1;
	else if (is_string(prop, "sid="))
		temp = 2;
	else if (is_string(prop, "ssex="))
		temp = 3;
	else if (is_string(prop, "nation="))
		temp = 4;
	else if (is_string(prop, "date_of_birth="))
		temp = 5;
	else if (is_string(prop, "poli_sta="))
		temp = 6;
	else if (is_string(prop, "addr="))
		temp = 7;
	else if (is_string(prop, "depart="))
		temp = 8;
	else if (is_string(prop, "major="))
		temp = 9;
	else 
		temp = 0;
	//printf("temp = %d", temp);

	printf("姓名\t学号\t性别\t民族\t出生日期\t政治面貌\t家庭住址\t院系\t专业\n");

	switch (temp)
	{
		case 1:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].name, val))
				{
					show_stu_one(pStu, i);
					sum++;
				}
			}
			break;
		case 2:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF((char *)pStu->pBase[i].sid, val))
				{
					show_stu_one(pStu, i);
					sum++;
				}
			}
			break;
		case 3:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].ssex, val))
				{
					show_stu_one(pStu, i);
					sum++;
				}
			}
			break;
			case 4:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].nation, val))
				{
					show_stu_one(pStu, i);
					sum++;
				}
			}
			break;
			case 5:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF((char *)pStu->pBase[i].date_of_birth, val))
				{
					show_stu_one(pStu, i);
					sum++;
				}
			}
			break;
			case 6:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].poli_sta, val))
				{
					show_stu_one(pStu, i);
					sum++;
				}
			}
			break;
			case 7:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].addr, val))
				{
					show_stu_one(pStu, i);
					sum++;
				}
			}
			break;
			case 8:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].depart, val))
				{
					show_stu_one(pStu, i);
					sum++;
				}
			}
			break;
			case 9:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].major, val))
				{
					show_stu_one(pStu, i);
					sum++;
				}
			}
			break;
		default :
			printf("属性输入有误!\n");
	}

	printf("以上为您找到%ld条结果!\n", sum);

	return sum;
}


/*******************************字符串匹配*********************************************************************/
bool BF(char * S, char * T)
{
	if (strstr(S, T))
		return (true);
	else
		return (false);
	
	/*int i = 0, j = 0;

	while ((S[i] != '\0') && (T[j] != '\0'))
	{
		if (S[i] == T[j])
		{
			i++;
			j++;
		}
		else
		{
			i = i-j+1;
			j = 0;
		}
	}

	if (T[j] == '\0')
		return (true);
	else
		return (false);
	*/
}


/*******************************输出单个信息************************************************************/
void show_stu_one(struct Stu_ctrl * pStu, long pos)
{
//	printf("姓名\t学号\t性别\t民族\t出生日期\t政治面貌\t家庭住址\t院系\t专业\n");

	//姓名
	printf("%s\t", pStu->pBase[pos].name);
	//学号
	printf("%ld\t", pStu->pBase[pos].sid); 
	//性别
	printf("%s\t", pStu->pBase[pos].ssex); 
	//民族
	printf("%s\t", pStu->pBase[pos].nation); 
	//出生日期
	printf("%ld\t", pStu->pBase[pos].date_of_birth); 
	//政治面貌
	printf("%s\t", pStu->pBase[pos].poli_sta); 
	//家庭住址
	printf("%s\t", pStu->pBase[pos].addr); 
	//院系
	printf("%s\t", pStu->pBase[pos].depart); 
	//专业
	printf("%s\n", pStu->pBase[pos].major); 
}


/*******************************判断字符串是否相等**********************************************/
bool is_string(char * A, char * B)
{
	unsigned int i = strlen(A);
	unsigned int sum = 0;

	if (i != strlen(B))
		return (false);

	for (unsigned int j=0; j<i; j++)
	{
		if (A[j] == B[j])
			sum++;
	}

	if (sum == i)
		return (true);
	else
		return (false);
}


/*******************************按值删除********************************************************/
bool delete_stu_val(struct Stu_ctrl * pStu, char * prop, char * val)
{
	long i;
	long sum = 0;
	int temp = 0;
	PSTU pval = pStu->pBase;	//存储删除的值

	if (is_string(prop, "name="))
		temp = 1;
	else if (is_string(prop, "sid="))
		temp = 2;
	else if (is_string(prop, "ssex="))
		temp = 3;
	else if (is_string(prop, "nation="))
		temp = 4;
	else if (is_string(prop, "date_of_birth="))
		temp = 5;
	else if (is_string(prop, "poli_sta="))
		temp = 6;
	else if (is_string(prop, "addr="))
		temp = 7;
	else if (is_string(prop, "depart="))
		temp = 8;
	else if (is_string(prop, "major="))
		temp = 9;
	else 
		temp = 0;
	//printf("temp = %d", temp);

	switch (temp)
	{
		case 1:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].name, val))
				{
					delete_stu_pos(pStu, i, pval);
					sum++;
				}
			}
			break;
		case 2:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF((char *)pStu->pBase[i].sid, val))
				{
					delete_stu_pos(pStu, i, pval);
					sum++;
				}
			}
			break;
		case 3:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].ssex, val))
				{
					delete_stu_pos(pStu, i, pval);
					sum++;
				}
			}
			break;
			case 4:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].nation, val))
				{
					delete_stu_pos(pStu, i, pval);
					sum++;
				}
			}
			break;
			case 5:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF((char *)pStu->pBase[i].date_of_birth, val))
				{
					delete_stu_pos(pStu, i, pval);
					sum++;
				}
			}
			break;
			case 6:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].poli_sta, val))
				{
					delete_stu_pos(pStu, i, pval);
					sum++;
				}
			}
			break;
			case 7:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].addr, val))
				{
					delete_stu_pos(pStu, i, pval);
					sum++;
				}
			}
			break;
			case 8:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].depart, val))
				{
					delete_stu_pos(pStu, i, pval);
					sum++;
				}
			}
			break;
			case 9:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].major, val))
				{
					delete_stu_pos(pStu, i, pval);
					sum++;
				}
			}
			break;
		default :
			printf("属性输入有误!\n");
	}

	printf("为您找到%ld条结果.\n", sum);
	printf("已为您删除成功!\n");

	return (true);
}

/*******************************按值修改********************************************************/
bool revise_stu(struct Stu_ctrl * pStu, char * prop, char * be_val, char * aft_val)
{
	long i;
	int temp = 0;

	if (is_string(prop, "name="))
		temp = 1;
	else if (is_string(prop, "sid="))
		temp = 2;
	else if (is_string(prop, "ssex="))
		temp = 3;
	else if (is_string(prop, "nation="))
		temp = 4;
	else if (is_string(prop, "date_of_birth="))
		temp = 5;
	else if (is_string(prop, "poli_sta="))
		temp = 6;
	else if (is_string(prop, "addr="))
		temp = 7;
	else if (is_string(prop, "depart="))
		temp = 8;
	else if (is_string(prop, "major="))
		temp = 9;
	else 
		temp = 0;
	//printf("temp = %d", temp);

	switch (temp)
	{
		case 1:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].name, be_val))
				{
					strcpy(pStu->pBase[i].name, aft_val);
				}
			}
			break;
		case 2:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF((char *)pStu->pBase[i].sid, be_val))
				{
					strcpy((char *)pStu->pBase[i].sid, aft_val);
				}
			}
			break;
		case 3:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].ssex, be_val))
				{
					strcpy(pStu->pBase[i].ssex, aft_val);
				}
			}
			break;
		case 4:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].nation, be_val))
				{
					strcpy(pStu->pBase[i].nation, aft_val);
				}
			}
			break;
		case 5:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF((char *)pStu->pBase[i].date_of_birth, be_val))
				{
					strcpy((char *)pStu->pBase[i].date_of_birth, aft_val);
				}
			}
			break;
		case 6:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].poli_sta, be_val))
				{
					strcpy(pStu->pBase[i].poli_sta, aft_val);
				}
			}
			break;
		case 7:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].addr, be_val))
				{
					strcpy(pStu->pBase[i].addr, aft_val);
				}
			}
			break;
		case 8:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].depart, be_val))
				{
					strcpy(pStu->pBase[i].depart, aft_val);
				}
			}
			break;
		case 9:
			for (i=0; i<pStu->cnt; i++)
			{
				//模式匹配
				if (BF(pStu->pBase[i].major, be_val))
				{
					strcpy(pStu->pBase[i].major, aft_val);
				}
			}
			break;
		default :
			printf("属性输入有误!\n");
			return (false);
	}

	printf("修改成功!\n");

	return (true);
}

/**********************************基本信息输入****************************************************/
void input_stu(PSTU val)
{
	int i=1;

	printf("请输入姓名(10个字以内):");
	i = 1;
	while (i)
	{
		scanf("%s", &(val->name));
		if (strlen(val->name) > 20)
		{
			printf("10字以内!请重新输入!\n");
			setbuf(stdin, NULL);	//清空缓存
			getchar();
			i = 1;
		}
		else
			i = 0;
	}

	//printf("您的输入是:%s\n", val->name);	//test

	printf("请输入学号(10位以内):");
	i = 1;
	while (i)
	{
		scanf("%ld", &(val->sid));
		//需判断输入是否为数字
		if (val->sid >= 4000000000 || val->sid <0)
		{
			printf("19位以内纯数字!请重新输入!\n");
			setbuf(stdin, NULL);	//清空缓存
			getchar();
			i = 1;
		}
		else
			i = 0;
	}

	//printf("您的输入是:%ld\n", val->sid);	//test

	printf("请输入性别(1个字):");
	i = 1;
	while (i)
	{
		scanf("%s", &(val->ssex));
		if (strlen(val->ssex) > 2)
		{
			printf("1个字!请重新输入!\n");
			setbuf(stdin, NULL);	//清空缓存
			i = 1;
		}
		else
			i = 0;
	}

	//printf("您的输入是:%s\n", val->ssex);	//test

	printf("请输入民族(10个字以内):");
	i = 1;
	while (i)
	{
		scanf("%s", &(val->nation));
		if (strlen(val->nation) > 20)
		{
			printf("10字以内!请重新输入!\n");
			setbuf(stdin, NULL);	//清空缓存
			getchar();
			i = 1;
		}
		else
			i = 0;
	}

	//printf("您的输入是:%s\n", val->nation);	//test

	printf("请输入出生日期(8位数字):");
	i = 1;
	//此处反复出错,究其原因是__int64在.cpp文件中会出问题,.c文件正常
	while (i)
	{
		getchar();
		scanf("%ld", &(val->date_of_birth));

		//printf("您的输入是:%ld\n", val->date_of_birth);	//test

		//测试中整型变量接收字符后会crash
		if (((val->date_of_birth) > 99999999) || ((val->date_of_birth) < 10000000))
		//if (strlen((char * )val->date_of_birth) != 8 )
		{
			printf("8位数字!请重新输入!\n");
			setbuf(stdin, NULL);	//清空缓存
			i = 1;
		}
		else
			i = 0;
	}

	printf("请输入政治面貌(10字以内):");
	i = 1;
	while (i)
	{
		scanf("%s", &(val->poli_sta));
		if (strlen(val->poli_sta) > 20)
		{
			printf("10字以内!请重新输入!\n");
			setbuf(stdin, NULL);	//清空缓存
			i = 1;
		}
		else
			i = 0;
	}

	printf("请输入家庭住址(50字以内):");
	i = 1;
	while (i)
	{
		scanf("%s", &(val->addr));
		if (strlen(val->addr) > 100)
		{
			printf("50字以内!请重新输入!\n");
			setbuf(stdin, NULL);	//清空缓存
			i = 1;
		}
		else
			i = 0;
	}

	printf("请输入院系(10字以内):");
	i = 1;
	while (i)
	{
		scanf("%s", &(val->depart));
		if (strlen(val->depart) > 20)
		{
			printf("10字以内!请重新输入!\n");
			setbuf(stdin, NULL);	//清空缓存
			i = 1;
		}
		else
			i = 0;
	}

	printf("请输入专业(10字以内):");
	i = 1;
	while (i)
	{
		scanf("%s", &(val->major));
		if (strlen(val->major) > 20)
		{
			printf("10字以内!请重新输入!\n");
			setbuf(stdin, NULL);	//清空缓存
			i = 1;
		}
		else
			i = 0;
	}
}

/**********************************输出前n名****************************************************/
bool top_n_stu(struct Stu_ctrl * pStu /*, char * prop*/, long n)
{
	sort_stu_id(pStu);

	if (pStu->cnt < n)
	{
		printf("学生不足%ld, 为你输出%ld条信息.\n", n, pStu->cnt);
		show_stu(pStu);
		return (true);
	}
	else
	{
		printf("排名前%ld的学生是:\n", n);
		for (long i=0; i<n; i++)
		show_stu_one(pStu, i);
		return (true);
	}
}

/**********************************添加学生信息****************************************************/
void add_arr_stu(struct Stu_ctrl * pStu)
{
	char choice = 'y';
	int temp = 1;
	STU val;

	setbuf(stdin, NULL);	//清空缓存
	printf("添加学生信息?y/n\n");
	scanf("%c", &choice);
	setbuf(stdin, NULL);	//清空缓存

	if (choice == 'y')
		temp = 1;
	else
		temp = 0;

	while (temp)
	{
		input_stu(&val);
		if (append_stu(pStu, val))
		{
			printf("信息添加成功。是否继续添加?y/n\n");
			getchar();	//用于提取"\n",以便继续添加
			scanf("%c", &choice);
			setbuf(stdin, NULL);	//清空缓存
		}
		else
		{
			printf("糟糕!信息添加好像不成功。是否重新添加?y/n\n");
			getchar();
			scanf("%c", &choice);
			setbuf(stdin, NULL);	//清空缓存
		}

		if (choice == 'y')
			temp = 1;
		else
			temp = 0;
	}
}

/**********************************修改学生信息****************************************************/
//待完善
bool revise_all_stu(struct Stu_ctrl * pStu, char * prop)
{

	return (true);
}

/**********************************获取总人数****************************************************/
long get(struct Stu_ctrl * pStu)
{
	return (pStu->cnt);
}

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值