C语言学生管理系统 大作业 链表 增删查改

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student{
	int xuehao;
	char xingming[100];
	char xingbie[50];
	int year;
	int banji;
	int score1;
	int score2;
	struct student *next;
};
void fun1(struct student *head)
{
	struct student *p;struct student *o;
	o=head;
	p=(struct student*)malloc(sizeof(struct student));
	p->next=NULL;
	if(head->next!=NULL)
	{
	printf("输入学号 姓名 性别 年龄 班级 成绩1 成绩2\n");
	scanf("%d%s%s%d%d%d%d",&p->xuehao,&p->xingming,&p->xingbie,&p->year,&p->banji,&p->score1,&p->score2); 
	printf("你想加入哪个学生后面,输入学号:");
	int n;
	scanf("%d",&n); 
	while(o->next!=NULL)
	{
		o=o->next;
		if(o->xuehao==n)
		{
			n=100;break;
		}
	}
	if(n==100)
	{
		p->next=o->next;
		o->next=p;
	}
	head=head->next;
	if(n!=100)
	printf("学号错误\n");
	printf("遍历结果\n");
		while(head!=NULL)
	{
	printf("%d  %s  %s  %d  %d  %d %d\n",head->xuehao,head->xingming,head->xingbie,head->year,head->banji,head->score1,head->score2);
	head=head->next;
	}
    }
    else if(head->next==NULL)
    {
    printf("输入学号 姓名 性别 年龄 班级 成绩1 成绩2\n");
	scanf("%d%s%s%d%d%d%d",&p->xuehao,&p->xingming,&p->xingbie,&p->year,&p->banji,&p->score1,&p->score2); 
	head->next=p;
	p->next=NULL;
	head=head->next;
	printf("遍历结果\n");
	while(head!=NULL)
	{
	printf("%d  %s  %s  %d  %d  %d %d\n",head->xuehao,head->xingming,head->xingbie,head->year,head->banji,head->score1,head->score2);
	head=head->next;
	}
    }
}
void fun2(struct student *head)
{
	printf("输入你希望删除的成员学号:");
int a;struct student *p;struct student *o;
scanf("%d",&a);o=head;
while(o!=NULL)
{
	
	if(o->xuehao==a)
	{
		p->next=o->next;
		break;
	}
	p=o;
	o=o->next;
}head=head->next;
printf("遍历结果\n");
if(head!=NULL)
	{
	while(head!=NULL)
	{
	printf("%d  %s  %s  %d  %d  %d %d\n",head->xuehao,head->xingming,head->xingbie,head->year,head->banji,head->score1,head->score2);
	head=head->next;
	}}
	else
	printf("           无信息\n"); 

}
void fun3(struct student *head)
{
	int n;
	printf("输入你希望查找的成员学号:");
	scanf("%d",&n);
	printf("\n");
	while(head!=NULL)
	{
		if(head->xuehao==n)
		{
			printf("学生姓名是:%s\n",head->xingming);
		}
		head=head->next;
	}
}
void fun4(struct student *head)
{
	int n;
	printf("输入你希望修改的成员学号:");
	scanf("%d",&n);struct student *o;o=head;
	while(o!=NULL)
	{
		if(o->xuehao==n)
		{
			break;
		}
		o=o->next;
	}int x;char ace[50];
	printf("输入你希望修改的东西  学号 1;姓名 2;性别 3;年龄 4;班级 5;成绩1 6;成绩2 7;   :");
	scanf("%d",&n);
	if(n==1)
	{
		printf("输入修改后的学号  :");
		scanf("%d",&x);
		o->xuehao=x;
	}
	else if(n==3)
	{
		printf("输入修改后的性别  :");
		scanf("%s",ace);
		strcpy(o->xingbie,ace);
	}
	else if(n==2)
	{
	  printf("输入修改后的姓名  :");
	  scanf("%s",ace);
	  strcpy(o->xingming,ace);	
	}
	else if(n==4)
	{
		printf("输入修改后的年龄  :");
		scanf("%d",&x);
		o->year=x;
	}
	else if(n==5)
	{
		printf("输入修改后的班级  :");
		scanf("%d",&x);
		o->banji=x;
	}
	else if(n==6)
	{
		printf("输入修改后的成绩1 :");
		scanf("%d",&x);
		o->score1=x; 
	}
	else if(n==7)
	{
		printf("输入修改后的成绩2 :");
		scanf("%d",&x);
		o->score2=x; 
	}
	printf("遍历结果\n");
	head=head->next;
		while(head!=NULL)
	{
	printf("%d  %s  %s  %d  %d  %d %d\n",head->xuehao,head->xingming,head->xingbie,head->year,head->banji,head->score1,head->score2);
	head=head->next;
	}
}

int main()
{
	int n;
	struct student *p,*head,*q;
	printf("输入学生个数:");
	scanf("%d",&n);
	head=(struct student*)malloc(sizeof(struct student));
	head->next=NULL;
	int i;
	printf("输入学号 姓名 性别 年龄 班级 成绩1 成绩2\n");
	for(i=0;i<n;i++)
	{
		p=(struct student*)malloc(sizeof(struct student));
		scanf("%d%s%s%d%d%d%d",&p->xuehao,&p->xingming,&p->xingbie,&p->year,&p->banji,&p->score1,&p->score2); 
		if(head->next==NULL)
		{
			head->next=p;
		}
		else
		{
			q->next=p;
		}
		q=p;
	}
	q->next=NULL;
	int x=1;
	while(x)
	{
	printf("输入下一步的功能:增加 1; 删除 2; 查找 3; 修改 4; 退出:0 \n");
	scanf("%d",&x);
		switch(x)
	{
		case 1:
		fun1(head);
		break;
		case 2:
		fun2(head);
		break;
		case 3:
		fun3(head);
		break;
		case 4:
		fun4(head);
		break;
		case 0:
		break;
	}
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值