学生信息管理系统C语言(实现学生信息的查询、删除、修改等功能)

学生信息管理系统

本系统主要用于学生通讯录管理与查询,主要功能包括学生信息数据的录入、读取、显示、删除、查找、修改。主要使用人群:全学院全体学生。每个学生的信息为:学号、姓名、性别、班级 住址、手机号码、QQ号、邮箱等。

#include 
#include
#include
#include
#include
#define MAX_LEN 20 
#define STU_NUM 200
#define MAX_ADD 20
#define N 30
typedef struct Student
{
	long long  id; //学号
	char name[MAX_LEN];   //姓名
	char sex[8];  //性别
	int  age;  //年龄
	int Class;  //班级
	char add[MAX_ADD];  //地址
	long long num;  //手机号码
	long  long int QQ;  //QQ号码
	char email[N];  //邮箱
}STU;
STU   stu[STU_NUM];
int ch = -1;
int   Menu(void);
int   n = 0;  /* 学生人数为n */

int Menu(); //主菜单
void choose(int ch); //选择
void ReadData();  //读入数据
void Searchbyid();  //通过学号搜索信息
void SortByid();  //按学号从小到大排序
void Modifydata();  //修改信息
void Deletedatd();  //删除信息

void main()
{
	printf("Input student number(n<=200):\n");
	scanf("%d", &n);
	while (1) {
		ch = Menu();
		choose(ch);
		ch = -1;
	}
}




int Menu()
{
	int ch;
	printf("**********************┍ -----------------------┑ *********************\n");
	printf("********************** 欢迎使用学生通信管理系统  *********************\n");
	printf("**********************┕------------------------┙ *********************\n");
	printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx菜单xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
	printf("======================================================================\n");
	printf(".......       1.录入信息        .....          2.查询信息      .......\n");
	printf(".......       3.排序功能        .....          4.删除信息      .......\n");
	printf(".......       5.修改数据        .....          0.退出系统      .......\n");

	printf("Please Input your choice:\n");
	scanf("%d", &ch);
	return ch;
}

void choose(int ch)
{
	switch (ch)
	{
	case 1:
		printf("Input id,name,sex,age,Class,num,QQ,email(Pause:0):\n");
		ReadData();
		break;
	case 2:
		printf("Input the number you want to search : \n");
		Searchbyid();
		break;
	case 3:
		SortByid();
		break;
	case 4:
		Modifydata();
		break;
	case 5:
		Deletedatd();
		break;
	case 0:
		printf("End of program!");
		exit(0);
	default: printf("Input error!\n");
	}
}

void ReadData() //读入数据
{
	int i;
	for (i = 0; i < n; i++)
	{
		printf("id:");
		scanf("%lld", &stu[i].id);
		if (stu[i].id == 0)break;
		getchar();
		printf("name:");
		gets(stu[i].name);
		printf("sex:");
		scanf("%s", &stu[i].sex);
		getchar();
		printf("age:");
		scanf("%d", &stu[i].age);
		printf("Class:");
		scanf("%d", &stu[i].Class);
		printf("address:");
		scanf("%s", &stu[i].add);
		getchar();
		printf("num:");
		scanf("%lld", &stu[i].num);
		printf("QQ:");
		scanf("%lld", &stu[i].QQ);
		printf("email:");
		scanf("%s", &stu[i].email);
		getchar();
		printf("\n");
	}
}


void Searchbyid()  //2.查找
{
	long long int term = -1;
	int i;
	scanf("%lld", &term);
	for (i = 0; i < n; i++)
	{
		if (term == stu[i].id)
		{
			printf("id:%lld\n", stu[i].id);
			printf("name:%s\n", stu[i].name);
			printf("sex:%s\n", stu[i].sex);
			printf("age:%d\n", stu[i].age);
			printf("Class:%d\n", stu[i].Class);
			printf("address:%s\n", stu[i].add);
			printf("phone number:%lld\n", stu[i].num);
			printf("QQ:%lld\n", stu[i].QQ);
			printf("email:%s\n", stu[i].email);
			term = -2;
		}
	}
	if (term != -2)
	{
		printf("Not found!\n");
	}
	getch();
}


void SortByid()  //3.排序
{
	STU temp1 = { 0 };
	int i, j;
	for (i = 0; i < n - 1; i++)
	{
		if (stu[i].id > stu[i + 1].id)
		{
			temp1 = stu[i];
			stu[i] = stu[i + 1];
			stu[i + 1] = temp1;
		}
	}
	for (j = 0; j < n; j++)
	{
		printf("id:%lld\n", stu[j].id);
		printf("name:%s\n", stu[j].name);
		printf("sex:%s\n", stu[j].sex);
		printf("age:%d\n", stu[j].age);
		printf("Class:%d\n", stu[j].Class);
		printf("address:%s\n", stu[j].add);
		printf("phone number:%lld\n", stu[j].num);
		printf("QQ:%lld\n", stu[j].QQ);
		printf("email:%s\n", stu[j].email);
		printf("\n");
	}
	getch();
}


void Deletedatd()//4.删除信息
{
	int i, j, flag = 0;
	long long  id1;
	printf("Please input the id:\n");
	scanf("%lld", &id1);
	for (i = 0; i < n; i++)
	{
		if (stu[i].id == id1)
		{
			flag = 1;
			for (j = i; j < n - 1; j++)
			{
				stu[j] = stu[j + 1];
			}

		}
	}
	getch();
}


void Modifydata()  //5.修改信息
{

	int i, item, j = -1;
	long long s1;
	printf("Please input the id:\n");
	scanf("%lld", &s1);
	for (i = 0; i < n; i++)
	{
		if (stu[i].id == s1)
		{
			j = i;
			printf("1.Modify the name:\n");
			printf("2.Modify the gender:\n");
			printf("3.Modify the age:\n");
			printf("4.Modify the class:\n");
			printf("5.Modify the address:\n");
			printf("6.Modify the phone number:\n");
			printf("7.Modify the QQ:\n");
			printf("8.Modify the email\n");
			printf("0.End of program!\n");
			while (1)
			{
				printf("please choose:");
				scanf("%d", &item);
				switch (item)
				{
				case 1:
					printf("Please input new name:\n");
					scanf("%s", &stu[j].name);
					break;
				case 2:
					printf("Please input gender:\n ");
					scanf("%s", &stu[j].sex);
					break;
				case 3:
					printf("Please input new age:\n");
					scanf("%d", &stu[j].age);
					break;
				case 4:
					printf("Please input new Class:\n");
					scanf("%d", &stu[j].Class);
					break;
				case 5:
					printf("Please input new address:\n");
					scanf("%s", &stu[j].add);
					break;
				case 6:
					printf("Please input new phone number:\n");
					scanf("%lld", &stu[j].num);
					break;
				case 7:
					printf("Please input new QQ:\n ");
					scanf("%lld", &stu[j].QQ);
					break;
				case 8:
					printf("Please input new email:\n");
					scanf("%s", &stu[j].email);
					break;
				default: printf("Input error!\n");
				}
				if (item == 0)
					break;
			}
		}
	}
	getch();
} 

你可能感兴趣的:(大一笔记,c语言,编程语言)