欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語(yǔ)言單鏈表實(shí)現(xiàn)學(xué)生管理系統(tǒng)

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

本文實(shí)例為大家分享了C語(yǔ)言單鏈表實(shí)現(xiàn)學(xué)生管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

代碼:

#include<stdio.h>
#include<stdlib.h>
#include <string.h>
#include <malloc.h>
struct Student
{
 int num;//學(xué)號(hào)
 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); //刪除 指定內(nèi)容
void modify(struct Student **head); // 修改內(nèi)容
void find(struct Student *head); //查找學(xué)生信息
int modify_menu();
int main()
{
 struct Student *head = NULL;
 int x;
 do
 {
 printf("------------------------------------------\n");
 printf("    學(xué)生管理系統(tǒng)     \n"); 
 printf("           \n");
 printf(" 1 增加學(xué)生   2 刪除學(xué)生  \n");
 printf("           \n");
 printf(" 3 修改資料   4 查找學(xué)生  \n"); 
 printf("           \n"); 
 printf(" 5 顯示所有學(xué)生  0 退出系統(tǒng)  \n");
 printf("           \n");
 printf("------------------------------------------\n");
 printf("請(qǐng)輸入你需要使用的功能\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 ("選擇錯(cuò)誤?。。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("學(xué)號(hào)  名字  性別 年齡 \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;//指向要?jiǎng)h除的前一個(gè)結(jié)點(diǎn)
 struct Student *p2 = *head;//指向要?jiǎng)h除的結(jié)點(diǎn)
 printf("請(qǐng)輸入要?jiǎng)h除的學(xué)生\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("請(qǐng)輸入需要修改資料的名字\n");
 scanf("%s",arr);
 while(p!=NULL)
 {
 if(strcmp(arr,p->name) ==0)
 {
 printf("請(qǐng)選擇修改的內(nèi)容\n");
 x = modify_menu();
 printf("請(qǐng)輸入新的內(nèi)容\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 ("選擇錯(cuò)誤?。?!\n");
  break;
 }
 print(*head);
 break ;
 } 
 p=p->next;
 }
}
int modify_menu() //修改的菜單 
{
 int choose = 0;
 printf ("-----------------------------------\n");
 printf ("* 1 學(xué)號(hào)  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("請(qǐng)輸入學(xué)生姓名\n");
 scanf("%s",arr);
 while(head!=NULL)
 {
 if(strcmp(arr,head->name)==0)
 {
 printf("學(xué)號(hào)  名字  性別 年齡 \n");
 printf("%5d %10s  %s  %d\n",head->num,head->name,head->sex,head->age);
 }
 head=head->next;
 }
}

推薦幾篇文章:

C++實(shí)現(xiàn)簡(jiǎn)單的圖書管理系統(tǒng)

C++實(shí)現(xiàn)簡(jiǎn)單的職工信息管理系統(tǒng)

C++基礎(chǔ)學(xué)生管理系統(tǒng)

關(guān)于管理系統(tǒng)的更多內(nèi)容請(qǐng)點(diǎn)擊《管理系統(tǒng)專題》進(jìn)行學(xué)習(xí)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論