c语言学生信息管理系统(巨简单)

偶然翻看自己的优盘,看到了自己一年前写的一个大一时候的大作业,学生信息管理系统,决定分享出来,为大家做一个参考。接下来就是代码了。以下代码只包含了增删查改排序统计的功能。希望对大家有所帮助。

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
struct date {
	int y;
	int m;
	int d;
};
typedef struct student {
	char name[20];
	char sex[6];
	char major[20];
	struct date birth;
	char address[20];
	int grade;
	struct student *next;
} stu;
void add(struct student *head) {
	stu *q=(stu*)malloc(sizeof(stu));
	q->next=NULL;
	stu *p;
	p=head;
	//q=(stu*)malloc(sizeof(stu));
	printf("请输入学生名字\n");
	scanf("%s",q->name);
	printf("请输入学生性别\n");
	scanf("%s",q->sex);
	printf("请输入学生专业\n");
	scanf("%s",q->major);
	printf("请输入学生生日的年月日\n");
	scanf("%d%d%d",&q->birth.y,&q->birth.m,&q->birth.d);
	printf("请输入学生地址\n");
	scanf("%s",q->address);
	printf("请输入学生英语成绩\n");
	scanf("%d",&q->grade);
	while(p->next!=NULL) {
		p=p->next;
	}
	p->next=q;
	p=q;
}
void paixv(struct student *head) {  //case 6排序
	int b=1;
	if(head->next==NULL) {
		b=0;
	}
	if(b==0) {
		printf("当前无数据/n");
	}
	if(b==1) {
		stu *p,*q;
		p=q=(stu*)malloc(sizeof(stu));
		struct date birth1,birth2;
		char name1[20];
		char sex1[6];
		char major1[20];
		char address1[20];
		int grade1;

		char name2[20];
		char sex2[6];
		char major2[20];
		char address2[20];
		int grade2;

		 
		for(p=head->next; p!=NULL; p=p->next) {
			for(q=p->next; q!=NULL; q=q->next) {
				if(p->grade<q->grade) {
					strcpy(name1,p->name);
					strcpy(sex1,p->sex);
					strcpy(major1,p->major);
					birth1.y=p->birth.y;
					birth1.m=p->birth.m;
					birth1.d=p->birth.d;
					strcpy(address1,p->address);
					grade1=p->grade;

					strcpy(name2,q->name);
					strcpy(sex2,q->sex);
					strcpy(major2,q->major);;
					birth1=q->birth;
					strcpy(address2,q->address);
					grade2=q->grade;

					strcpy(p->name,name2);
					strcpy(p->sex,sex2);
					strcpy(p->major,major2);
					p->birth=birth2;
					strcpy(p->address,address2);
					p->grade=grade2;

					strcpy(q->name,name1);
					strcpy(q->sex,sex1);
					strcpy(q->major,major1);
					q->birth=birth1;
					strcpy(q->address,address1);
					q->grade=grade1;

				}
			}
		}
	}
}
void tongji(stu *head) {//统计 case5
	int r=0,t=0,z,u=0,i=0,o=0,a=0,s=0,d=0;
	stu *p=head;
	if(p->next==NULL) {
		printf("此时无数据");
	} else {
		int i;
		printf("请选择你想统计的类型");
		printf("**********************\n");
		printf("*****1统计性别********\n");
		printf("*****2统计年龄********\n");
		printf("*****3统计专业********\n");
		printf("**********************\n");
		scanf("%d",&i);
		switch(i) {
			case 1:
				while(p->next!=NULL) {
					if(strcmp(p->sex,"男")==0)
						r++;
					else
						t++;
					p=p->next;
				}
				printf("男生:%d\n",r);
				printf("女生:%d\n",t);
				break;
			case 2:

				while(p->next!=NULL) {
					z=p->birth.y;
					u=2018-z;
					if(u==18)
						i++;
					else
						o++;
					p=p->next;
				}
				printf("18岁:%d\n",i);
				printf("19岁:%d\n",o);
				break;
			case 3:

				while(p->next!=NULL) {
					a=strcmp(p->major,"云计算");
					if(a==0)
						s++;
					else
						d++;
					p=p->next;
				}
				printf("云计算:%d\n",s);
				printf("大数据:%d\n",d);
				break;
			default:
				printf("请重新输入");
		}
	}
}
void daoru(stu *head) { //case 3 导入
	int n;
	printf("输入想插入学生个数:\n");
	scanf("%d",&n);
	for(int x=0; x<n; x++) {
		add(head);
	}
}
void shuchu(struct student *head)
{
	stu *p;
	p=head->next;
	 
	 while (p!=NULL)
	 {
	 	printf("%s %s %s %d %d %d %s %d\n",p->name,p->sex,p->major,p->birth.y,p->birth.m,p->birth.d,p->address,p->grade);
	 	p=p->next;
	 }
	
	
}
void sousuo( stu *head) { //case 4
	int k=0;
	char name3[20];
	printf("请输入要搜所的学生的名字\n");
	scanf("%s",name3);
	stu *p;
	for(p=head->next; p!=NULL; p=p->next) {
		if(strcmp(name3,p->name)==0) {
			k=k+1;
			printf("%s %s %s %d %d %d %s %d\n",p->name,p->sex,p->major,p->birth.y,p->birth.m,p->birth.d,p->address,p->grade);
		}
		if(k==0) {
			printf("查无此人");
		}
	}
}
/*void baocun()
{
	ofstream outfile("d:\\file.txt");
	if(!outfile)
	{
		cerr<<"open error!"<<endl;
		exit(1);
	}
	Student *p=head->next;
	while(p)
	{
		outfile<<p->num<<" ";
		outfile<<p->name<<" ";
		outfile<<p->sex<<" ";
		outfile<<p->major<<" ";
		outfile<<p->born<<" ";
		outfile<<p->address<<" ";
		outfile<<p->english	<<" ";
		p=p->next;
	}
	outfile.close();
	cout<<"保存完成"<<endl;
}*/
void shanchu(stu *head) { //删除case2

	stu *p,*q;
	p=q=(student*)malloc(sizeof(student));
	p=head;
	char name3[20];
	if(p->next==NULL) {
		printf("此时无数据");
	} else {
		printf("请输入你想删除的学生的名字");
		scanf("%s",name3);
		while(p!=NULL) {
			if(strcmp(p->next->name,name3)==0) {
				q=p->next;
				p->next=p->next->next ;
				q=NULL;
				free(q);
			}
			p=p->next;
		}
	}
}
int main() {
	system("color 3F");
	int i;
	struct student *head=(student*)malloc(sizeof(student));
	head->next=NULL;
	do {
		system("date/t");
		system("time/t");
		system("color 5F");
		printf("1、新增学生信息\n");
		printf("2、删除学生信息\n");//完成
		printf("3、导入学生信息\n");//写完
		printf("4、学生信息搜索\n");//写完
		printf("5、学生信息统计\n");//写完
		printf("6、按英语成绩排序\n");//写完
		printf("7、学生信息保存\n");
		printf("8、退出\n");
		printf("请输入要实现的功能\n");
		scanf("%d",&i);
		switch(i) {

			case 1:
				system("cls");
				add(head);
				break;
			case 2:
				system("cls");
				shanchu(head);
				break;
			case 3:
				system("cls");
				daoru(head);
				break;
			case 4:
				system("cls");
				sousuo(head);
				break;
			case 5:
				system("cls");
				tongji(head);
				break;
			case 6:
				system("cls");
				paixv(head);
				shuchu(head);
				break;
				/*	case 7: system("cls");*/
			case 8:
				break;
		}
	} while(i!=8);
	printf("运行结束");
	return 0;
}
  • 96
    点赞
  • 504
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值