学生管理系统

##代码过于简单,

##作者新手,勿喷;

#include
#include
#include
#include
typedef long long datestr;
using namespace std;
typedef struct student {//结构体创建
	char name[40];
	datestr id;
	char sex;
	char major[40];
	/*struct grade gradex;*/
	student* next;
}student, * stup;
struct grade {//成绩结构体创建
	int c_language;
	int date_structure;
	int computer_concept;
};
void UI();
void changeUI();
void print(student* fp);
void scan(student* fp);
void help();
void show(student* p);
student* add(student* list);
student* find(student* findp, datestr idx);
student* deletelist(student* headx, datestr delid);
void amend(student* changep);
enum
{
	COMMAND_SHOW = 1,
	COMMAND_ADD,
	COMMAND_DELETE,
	COMMAND_CHANGE,
	COMMAND_SEARCH,
	OMMAND_HELP,
	COMMAND_QUIT
};
void UI()//下一步提示
{
	cout << "请选择下一步操作" << endl;
}
void changeUI()
{
	printf("<><><><><><><><><><><><><><>\n");
	printf("$$$$输入【1】修改学生学号$$$$\n");
	printf("%%%%%%%%输入【2】修改学生姓名%%%%%%%%\n");
	printf("@@@@输入【3】修改学生性别@@@@\n");
	printf("&&&&输入【4】修改学生专业&&&&\n");
	printf("####输入【5】修改完成----####\n");
	printf("<><><><><><><><><><><><><><>\n");
}
void print(student* fp)//打印学生信息函数
{
	/*cout << "name is " << p.name << " id is " << p.id << " sex is " << p.sex << " major is " << p.major << endl;/*| c-language:%4d
	| date-structure:%4d | computer-concept:%4d*/
	printf("name: %8s | id: %15lld | sex:%3c | major:%10s \n",
		fp->name, fp->id, fp->sex, fp->major/*,fp->gradex.c_language,fp->gradex.date_structure,fp->gradex.computer_concept*/);
}
void scan(student* fp)//输入数据函数;
{
	printf("请输入学生的名字\n");
	scanf(" %s", &(fp->name));
	printf("请输入学生的学号\n");
	scanf("%lld", &(fp->id));
	printf("请输入学生的性别\n");
	scanf(" %c", &(fp->sex));
	printf("请输入学生的专业\n");
	scanf(" %s", &(fp->major));
}
void help()//菜单m
{
	printf("---------------------------------\n");
	printf("|---输入【1】显示所有学生信息---|\n");
	printf("|---输入【2】添加一个学生信息---|\n");
	printf("|---输入【3】删除一个学生信息---|\n");
	printf("|---输入【4】修改一个学生信息---|\n");
	printf("|---输入【5】查找一个学生信息---|\n");
	printf("|---输入【6】显示帮助*******----|\n");
	printf("|---输入【7】退出***********----|\n");
	cout << "_________________________________\n" << endl;

}
void show(student* p)//显示学生信息
{
	while (p != NULL)
	{
		print(p);
		p = p->next;
	}
}
student* find(student* findp, datestr idx)//查找学生信息
{
	while (findp != NULL)
	{
		if (findp->id == idx)
		{
			return findp;
			break;
		}
		findp = findp->next;
	}
	if (findp == NULL)
	{
		return NULL;
	}
}
student* deletelist(student* headx, datestr delid)
{
	student* fdelp = headx;
	student* delp = fdelp->next;
	while (delp != NULL)
	{
		if (delp->id == delid)
		{
			return fdelp;
		}
		fdelp = fdelp->next;
		delp = delp->next;
	}
	//cout << "没有查找到此学生,请重新输入" << endl;
	return NULL;

}
void amend(student* changep)
{
	changeUI();
	int x, breakx = 0;
	while (breakx == 0)
	{
		scanf("%d", &x);
		switch (x)
		{
		case 1:
		{
			printf("请输入修改后的学号\n");
			scanf("%lld", &changep->id);
			printf("修改成功\n");
			break;

		}
		case 2:
		{
			cout << "请输入修改后的名字" << endl;
			scanf(" %s", &changep->name);
			printf("修改成功\n");
			break;
		}
		case 3:
		{
			cout << "请输入修改后的性别" << endl;
			scanf(" %c", &changep->sex);
			printf("修改成功\n");
			break;
		}
		case 4:
		{
			cout << "请输入修改后的专业" << endl;
			scanf(" %s", &changep->major);
			printf("修改成功\n");
			break;
		}
		case 5:
		{
			printf("已结束全部修改\n");
			print(changep);
			breakx = 1;
			break;
		}
		default: {
			printf("输入错误!!!\n请重新输入\n");
			break;
		}
		}
	}
}
student* add(student* endlist)
{
	student* nowlist;
	nowlist = (student*)malloc(sizeof(student));
	endlist->next = nowlist;
	scan(nowlist);
	nowlist->next = NULL;
	return nowlist;
}
int main()
{
	int a = 10;
	int scanfx = 0;//输入选择
	help();//显示菜单

	student head, stu1, stu2, stu3, stu4, stu5, stu6, stu7, stu8, stu9, stu10;
	{
		head = { NULL,NULL,NULL,NULL };
		head.next = &stu1;
		stu1 = { "Aeneas",23016020532,'f',"c语言" };
		stu1.next = &stu2;
		stu2 = { "Alan",23016020533,'f',"电音" };
		stu2.next = &stu3;
		stu3 = { "彭于晏",23016020534,'f',"励志领域知名人物" };
		stu3.next = &stu4;
		stu4 = { "里斯",23016020535,'f',"未知" };
		stu4.next = &stu5;
		stu5 = { "马斯克",23016020536,'f',"企业家" };
		stu5.next = &stu6;
		stu6 = { "普京",23016020537,'f',"俄罗斯" };
		stu6.next = &stu7;
		stu7 = { "特朗普",23016020538,'f',"上任总统" };
		stu7.next = &stu8;
		stu8 = { "川普",23016020539,'f',"未知" };
		stu8.next = &stu9;
		stu9 = { "张译",23016020540,'f',"演员" };
		stu9.next = &stu10;
		stu10 = { "谭松韵",23016020541,'m',"演员" };
		stu10.next = NULL;
	}
	//链表初始化内容
	student* endlist;
	endlist = &stu10;
	endlist->next = NULL;

	while (scanfx != 7)
	{
		scanf("%d", &scanfx);
		switch (scanfx)
		{
		case COMMAND_SHOW://1显示学生信息
		{
			show(head.next);
			UI();
			break;
			system("pause");
		}//(1)完成
		case COMMAND_ADD://2添加学生信息
		{
			printf("请输入需要添加学生的信息\n");
			endlist = add(endlist);
			cout << "添加成功" << endl;
			UI();
			break;
		}//(2)完成
		case COMMAND_DELETE://3删除学生信息
		{
			cout << "请输入需要删除学生的信息" << endl;
			datestr delid;
			student* ffp;
			cin >> delid;
			ffp = deletelist(&head, delid);
			if (ffp != NULL)
			{
				ffp->next = ffp->next->next;
				//free(ffp->next);
				cout << "删除成功" << endl;
			}
			else cout << "没有查找到此学生,请重新输入" << endl;
			UI();
			break;
		}
		case COMMAND_CHANGE://4修改学生信息
		{
			int a = 0;
			while (a == 0)
			{
				printf("请输入需要修改学生的学号\n");
				datestr idx;
				scanf("%lld", &idx);
				student* changep;
				changep = find(&stu1, idx);
				printf("请输入需要修改学生的信息\n");
				if (changep != NULL) {
					print(changep);
					amend(changep);
					a = 1;
				}
				else {
					printf("没有此学生,请重新输入\n");
					a = 0;
				}
			}

			UI();
			break;
		}//(4)完成
		case COMMAND_SEARCH://查找学生信息
		{
			datestr idx;
			cout << "请输入需要查找学生的学号" << endl;
			scanf("%lld", &idx);
			student* ffp;
			ffp = find(&head, idx);
			if (ffp != NULL)
			{
				print(ffp);
				/*printf("name: % 6s | id : % 12lld | sex : % c |
				major : % 8s \n", ffp->name, ffp->id, ffp->sex, ffp->major);*/
			}
			else
			{
				printf("没有此学生,请重新输入\n");
			}
			UI();
			break;
		}//(5)完成
		case OMMAND_HELP://查看帮助
		{
			help();
			UI();
			break;
		}//(6)完成
		case COMMAND_QUIT://退出
		{
			UI();
			break;
			system("pause");
		}//退出完成
		default:
		{
			printf("输入错误,请重新输入\n");
			UI();
		}//完成

		}
	}
	return 0;
}

你可能感兴趣的:(c语言,c++)