C語言單鏈表實現(xiàn)學生管理系統(tǒng)
更新時間:2020年12月10日 16:41:11 作者:weixin_44859250
這篇文章主要為大家詳細介紹了C語言單鏈表實現(xiàn)學生管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C語言單鏈表實現(xiàn)學生管理系統(tǒng)的具體代碼,供大家參考,具體內容如下

代碼:
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include <malloc.h>
struct Student
{
int num;//學號
char name[20];//名字
char sex[2];
int age;
struct Student *next;
};
void insert(struct Student **head); //插入
void print(struct Student *head); //遍歷所有鏈表
void dele(struct Student **head); //刪除 指定內容
void modify(struct Student **head); // 修改內容
void find(struct Student *head); //查找學生信息
int modify_menu();
int main()
{
struct Student *head = NULL;
int x;
do
{
printf("------------------------------------------\n");
printf(" 學生管理系統(tǒng) \n");
printf(" \n");
printf(" 1 增加學生 2 刪除學生 \n");
printf(" \n");
printf(" 3 修改資料 4 查找學生 \n");
printf(" \n");
printf(" 5 顯示所有學生 0 退出系統(tǒng) \n");
printf(" \n");
printf("------------------------------------------\n");
printf("請輸入你需要使用的功能\n");
scanf("%d",&x);
switch(x)
{
case 0 : break;
case 1 :
insert(&head);
break;
case 2 :
dele(&head);
break;
case 3 :
modify(&head);
break;
case 4 :
find(head);
break;
case 5 :
print(head);
break;
default :
printf ("選擇錯誤!??!\n");
break;
}
}while(x);
}
void insert(struct Student **head)
{
struct Student *p = (struct Student*)malloc(sizeof(struct Student));
struct Student *stu=NULL;
printf("num:");
scanf("%d",&(p->num));
printf("name:");
scanf("%s",(p->name));
printf("sex:");
scanf("%s",p->sex);
printf("age:");
scanf("%d",&p->age);
p->next=NULL;
if(*head == NULL)
{
*head = p;
}
else
{
stu = *head;
while(stu->next != NULL)
{
stu = stu->next;
}
stu->next = p;
}
}
void print(struct Student *head)
{
printf("學號 名字 性別 年齡 \n");
while(head != NULL)
{
printf("%5d %10s %s %d\n",head->num,head->name,head->sex,head->age);
head=head->next;
}
}
void dele(struct Student **head)
{
char arr1[20];
struct Student *p1 = NULL;//指向要刪除的前一個結點
struct Student *p2 = *head;//指向要刪除的結點
printf("請輸入要刪除的學生\n");
scanf("%s",arr1);
while(p2 != NULL)
{
if(p1==NULL&&strcmp(arr1,p2->name)==0)
{
*head = p2->next;
free(p2);
break ;
}
else if(strcmp(arr1,p2->name)==0)
{
p1->next = p2->next;
free(p2);
break ;
}
p1=p2;
p2=p2->next;
}
print(*head);
}
void modify(struct Student **head) //修改
{
char arr[20];
int x = 0;
struct Student *p = *head;
printf("請輸入需要修改資料的名字\n");
scanf("%s",arr);
while(p!=NULL)
{
if(strcmp(arr,p->name) ==0)
{
printf("請選擇修改的內容\n");
x = modify_menu();
printf("請輸入新的內容\n");
switch(x)
{
case 1 :
scanf("%d",&p->num);
break;
case 2 :
scanf("%s",p->name);
break;
case 3 :
scanf("%s",p->sex);
break;
case 4:
scanf("%d",&p->age);
break;
default :
printf ("選擇錯誤?。?!\n");
break;
}
print(*head);
break ;
}
p=p->next;
}
}
int modify_menu() //修改的菜單
{
int choose = 0;
printf ("-----------------------------------\n");
printf ("* 1 學號 2 姓名 *\n");
printf ("* 3 性別 4 年齡 *\n");
printf ("* 0 取消修改 *\n");
printf ("-----------------------------------\n");
scanf ("%d", &choose);
return choose;
}
void find(struct Student *head)
{
char arr[20];
printf("請輸入學生姓名\n");
scanf("%s",arr);
while(head!=NULL)
{
if(strcmp(arr,head->name)==0)
{
printf("學號 名字 性別 年齡 \n");
printf("%5d %10s %s %d\n",head->num,head->name,head->sex,head->age);
}
head=head->next;
}
}
推薦幾篇文章:
關于管理系統(tǒng)的更多內容請點擊《管理系統(tǒng)專題》進行學習
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Qt串口通信開發(fā)之QSerialPort模塊簡單使用方法與實例
這篇文章主要介紹了Qt串口通信開發(fā)之QSerialPort模塊簡單使用方法與實例,需要的朋友可以參考下2020-03-03

