学生管理系统

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 50
typedef struct Student {
	int info;
	char name[MAXSIZE];
	int phone;
	struct Student* next;
}stu,*s;
s student(int info = 0, char name[MAXSIZE] = 0,int phone=0) {
	s node = new stu;
	node->info = info;
	if(name)for (int i = 0; i < MAXSIZE; i++)node->name[i] = name[i];
	node->phone = phone;
	node->next = NULL;
	return node;
}
bool warn(s head) {
	if (!head) {
		printf("链表头指针为空,无法进行操作\n");
	}
	return head;
}
void add(s head,s node,int index=0) {
	if (warn(head)) {
		while (head && head->next && index--) {
			head = head->next;
		}
		node->next = head->next;
		head->next = node;
	}
}
void del(s head, s node) {

	if (warn(head)) {
		while (head && head->next) {
			if (head->next->info == node->info) {
				s temp = head->next;
				head->next = head->next->next;
				delete temp;
				printf("删除成功\n");
				return;
			}
			head = head->next;
		}
		printf("查无此人\n");
	}
}
void chg(s head, s node) {
	if (warn(head)) {
		while (head && head->next) {
			if (head->next->info == node->info) {
				printf("原来信息:\n");
				printf("姓名:%s 学号:%d 手机号:%d\n", head->next->name, head->next->info, head->next->phone);
				printf("修改为:\n");
				printf("姓名:");
				scanf("%s", head->next->name);
				printf("学号:");
				scanf("%d", &head->next->info);
				printf("手机号:");
				scanf("%d", &head->next->phone);
				printf("修改成功\n");
				return;
			}
			head = head->next;
		}
		printf("查无此人\n");
	}
}
void srh(s head, s node) {
	if (warn(head)) {
		while (head && head->next) {
			if (head->next->info == node->info) {
				printf("姓名:%s 学号:%d 手机号:%d\n", head->next->name, head->next->info, head->next->phone);
				return;
			}
			head = head->next;
		}
		printf("查无此人\n");
	}
}
void show(s head) {
	printf("show:\n");
	if (warn(head)) {
		head->info = 0;
		printf("%10s %10s %10s\n", "name", "info", "phone");
		while (head && head->next) {
			head->info++;
			printf("%10s %10d %10d\n", head->next->name, head->next->info, head->next->phone);
			head = head->next;
		}
	}
	printf("共有学生%d名\n", head->info);
	printf("\n完毕\n");
}
int menu() {
	int choice = 0;
	while (true) {
		printf("菜单\n");
		printf("1、增加学生\n");
		printf("2、删除学生\n");
		printf("3、修改信息\n");
		printf("4、查询信息\n");
		printf("0、退出系统\n");
		printf("5、全局打印\n");
		printf("输入>");
		scanf("%d", &choice);
		system("cls");
		if (choice >= 0 && choice <= 5)
			return choice;
		else
			printf("错误的输入\n");
	}
}
int mySys() {
	s node;
	s head = student();
	int info = 0;
	int n;
	while (true) {
		switch (menu()) {
		case 0:
			exit(0);
		case 1:
			printf("插入学生数量>");
			scanf("%d", &n);
			for (int i = 0; i < n; i++) {
				printf("添加第%d个学生\n", i + 1);
				node = student();
				printf("输入学号>");
				scanf("%d", &node->info);
				printf("输入姓名>");
				scanf("%s", &node->name);
				printf("输入手机号>");
				scanf("%d", &node->phone);
				printf("指定位置(无则填0)>");
				scanf("%d", &info);
				add(head, node,info);
			}
			break;
		case 2:
			printf("输入学号>");
			scanf("%d", &info);
			node = student(info);
			del(head, node);
			break;
		case 3:
			printf("输入学号>");
			scanf("%d", &info);
			node = student(info);
			chg(head, node);
			break;
		case 4:
			printf("输入学号>");
			scanf("%d", &info);
			node = student(info);
			srh(head, node);
			break;
		case 5:
			show(head);
			break;
		}
		printf("输入回车继续工作\n");
		getchar();
		getchar();
		system("cls");
	}
}
int main(void) {
	mySys();
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

alasnot

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值