学生信息管理系统
管理系统
还好链表之类的内容没怎么忘记,重新手搓了一下
#include "Studentmanager.h"
void enter()
{
printf("******************************\n");
printf("*\t学生成绩管理系统\t*\n");
printf("******************************\n");
printf("*\t请选择你想选择的选项\t*\n");
printf("***********************\n");
printf("*\t1.录入学生信息\t*\n");
printf("*\t2.打印学生信息\t*\n");
printf("*\t3.统计学生信息\t*\n");
printf("*\t4.查找学生信息\t*\n");
printf("*\t5.修改学生信息\t*\n");
printf("*\t6.删除学生信息\t*\n");
}
void inputstudent(Node* head)
{
// 先创建一个新的节点,表示我们需要进行插入操作的节点
Node* _new = malloc(sizeof(Node));
_new->next = NULL;
printf("请输入学生的学号、姓名、成绩:");
scanf("%d %s %d", &_new->stu.number, _new->stu.name, &_new->stu.score);
// 再定义一个新节点,用来遍历插入节点的数量
// 因为你只有去遍历了才知道你在哪个节点插入
Node* _range = malloc(sizeof(Node));
_range = head;
while (_range->next != NULL)
{
_range = _range->next;
}
_range->next = _new;
system("pause");
system("cls");
}
void printstudent(Node* head)
{
Node* _new = malloc(sizeof(Node));
_new = head->next;
while (_new != NULL)
{
printf("学生的学号:%d ,学生的姓名:%s,学生的成绩:%d\n", _new->stu.number, _new->stu.name, _new->stu.score);
_new = _new->next;
}
system("pause");
}
void countstudent(Node* head)
{
int cnt = 0;
Node* _new = malloc(sizeof(Node));
_new = head;
while (_new->next != NULL)
{
cnt++;
_new = _new->next;
}
printf("学生的人数为:%d\n", cnt);
system("pause");
}
void searchstudent(Node* head)
{
int stuNum;
printf("请输入你需要查找的学生的学号:\n");
scanf("%d", &stuNum);
Node* _new = malloc(sizeof(Node));
_new = head->next;
while (_new != NULL)
{
if (stuNum == _new->stu.number)
{
printf("这个学生的学号是 %d,姓名是 %s,成绩是 %d\n", _new->stu.number, _new->stu.name, _new->stu.score);
return;
}
_new = _new->next;
}
printf("数据库中不存在这个学生的信息!\n");
system("pause");
}
void modifystudent(Node* head)
{
Node* _new = malloc(sizeof(Node));
_new = head->next;
int stuNum;
printf("请输入要访问的学生学号:");
scanf("%d", &stuNum);
while (_new != NULL)
{
if (_new->stu.number == stuNum)
{
printf("当前学生的学号是 %d ,姓名是 %s,成绩是 %d", _new->stu.number, _new->stu.name, _new->stu.score);
printf("请对当前的数据进行修改:");
scanf("%s%d", _new->stu.name, &_new->stu.score);
printf("恭喜修改成功!\n");
return;
}
_new = _new->next;
}
printf("未找到同学信息,请重试!\n");
system("pause");
}
void deletestudent(Node* head)
{
Node* _new = malloc(sizeof(Node));
_new = head; // 需要存上一个节点信息,方便删除中间节点
int stuNum;
printf("请输入你要删除的节点:");
scanf("%d", &stuNum);
while (_new->next != NULL)
{
if (_new->next->stu.number == stuNum)
{
Node* tmp = _new->next; // 存一个临时变量,记录中间节点
_new->next = _new->next->next;
free(tmp);
printf("恭喜你删除成功!\n");
return;
}
_new = _new->next;
system("pause");
}
printf("找不到该学生数据!\n");
system("pause");
}
int main()
{
Node* head = malloc(sizeof(Node));
head->next = NULL;
enter();
while (1)
{
char c = _getch();
switch (c)
{
case '1':
inputstudent(head);
break;
case '2':
printstudent(head);
break;
case '3':
countstudent(head);
break;
case '4':
searchstudent(head);
break;
case '5':
modifystudent(head);
break;
case '6':
deletestudent(head);
break;
default:
exit(0);
break;
}
}
return 0;
}
上面是源文件,下面是头文件
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
//#ifdef __linux__
//#include <termios.h>
//#include <unistd.h>
//
//int _getch(void)
//{
// struct termios oldt, newt;
// int ch;
// tcgetattr(STDIN_FILENO, &oldt);
// newt = oldt;
// newt.c_lflag &= ~(ICANON | ECHO);
// tcsetattr(STDIN_FILENO, TCSANOW, &newt);
// ch = getchar();
// tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
// return ch;
//}
//#endif
typedef struct _Student
{
int number; // 学号
char name[30]; // 姓名
int score; // 成绩
} Student;
// 节点信息
typedef struct _Node
{
Student stu;
struct _Node* next;
} Node;
void enter();
void inputstudent(Node* head);
void printstudent(Node* head);
void countstudent(Node* head);
void searchstudent(Node* head);
void modifystudent(Node* head);
void deletestudent(Node* head);
本文来自博客园,作者:Alaso_shuang,转载请注明原文链接:https://www.cnblogs.com/Alaso687/p/19213514

浙公网安备 33010602011771号