zoukankan      html  css  js  c++  java
  • C语言 数据结构学生管理系统

      1 #include<stdio.h>
      2 #include<stdlib.h>
      3 #include<string.h>
      4 
      5 
      6 
      7 struct student{
      8     char name [20];
      9     char num[10];
     10     int age ;
     11 
     12 };
     13 
     14 struct Node{
     15     struct student data;
     16     struct Node *next;
     17 };
     18 
     19 //创造一个链表 
     20 struct Node* createList(struct student data){
     21     struct Node* newNode =(struct Node*)malloc(sizeof(struct Node));
     22     newNode->data= data;
     23     newNode->next= NULL;
     24     return newNode ;
     25         
     26 }
     27 
     28 //插入链表,插入数据 :录入信息 
     29 void insertNodeByHead(struct Node* listHeadNode,struct student data){
     30     struct Node* newNode;
     31     newNode->next=listHeadNode->next; 
     32     listHeadNode->next=newNode;
     33 
     34 }
     35 
     36 //删除 
     37 void deleteNodeByAppoinName(struct Node* listHeadNode,char * name){
     38     struct Node* posFrontNode = listHeadNode;
     39     struct Node* posNode = listHeadNode->next;
     40     if(posNode==NULL){
     41         printf("无相关内容
    ");
     42         return;
     43     }else{
     44     while(strcmp(posNode->data.name,name)){
     45         posFrontNode =posNode;
     46         posNode =posFrontNode->next;
     47             if(posNode==NULL){
     48                 printf("错误
    ");
     49                 return;
     50             }
     51         }
     52         posFrontNode->next= posNode->next;
     53         free(posNode);
     54     } 
     55 } 
     56 
     57 //查找
     58 struct Node* searchNodeByAppoinNum(struct Node* listHeadNode,char*num){
     59     struct Node* pMove =listHeadNode->next;
     60     if(pMove==NULL)
     61         return pMove;
     62     else{
     63         while(strcmp(pMove->data.num,num)){
     64             pMove = pMove->next;
     65                 if(pMove=NULL)
     66                     break; 
     67         }
     68         return pMove;
     69     }
     70 }
     71  
     72 //打印当前结点 
     73 void printNode(struct Node* curNode){
     74         printf("姓名	学号	年龄	");
     75         printf("%s	%s	%d	
    ",curNode->data.name,curNode->data.num,curNode->data.age);
     76 }
     77 
     78 //打印 2,浏览信息
     79 void  printList(struct Node*listHeadNode){
     80     struct Node* pMove = listHeadNode->next;
     81     printf("姓名	学号	年龄	");
     82     while(pMove){
     83         printf("%s	%s	%d	
    ",pMove->data.name,pMove->data.num,pMove->data.age);
     84         pMove = pMove->next;
     85     }
     86     printf("
    ");
     87 }
     88 
     89  void systemMenu(){
     90       //菜单,用函数来完成
     91      printf("============================================
    ");
     92      printf("	学生成绩管理系统欢迎你
    "); 
     93      printf("	0.退出系统
    "); 
     94      printf("	1.插入信息
    "); 
     95      printf("	2.浏览信息
    "); 
     96      printf("	3.删除信息
    "); 
     97      printf("	4.修改信息
    ");
     98      printf("	5.查找信息
    ");
     99      printf("============================================
    ");
    100      printf("请输入0~5   
    ");
    101  }
    102  void keyDown(){
    103      struct Node*list =NULL;
    104      int useKey;
    105      struct student tempData;
    106      scanf("%d",&useKey);
    107      switch(useKey){
    108          case 0:
    109              printf("	[退出系统]
    "); 
    110              system("pause");
    111             exit(0);
    112              break;
    113          case 1:
    114              printf("	[插入信息]
    ");
    115              printf("请输入姓名,学号,年龄");
    116             scanf("%s%s%d",tempData.name,tempData.num,&tempData.age);
    117             insertNodeByHead(list,tempData);
    118              break;
    119          case 2:
    120              printf("	[浏览信息]
    ");
    121              printList(list);
    122              break;
    123          case 3:
    124              printf("	[删除信息]
    ");
    125              printf("请输入要删除的学生姓名");
    126             scanf("%s",tempData.name);
    127             deleteNodeByAppoinName(list,tempData.name);
    128              break;
    129          case 4:
    130              printf("	[修改信息]
    ");
    131              printf("请输入要修改的学生的学号"); 
    132             scanf("%s",tempData.num);
    133             if(searchNodeByAppoinNum(list,tempData.num)==NULL){
    134                 printf("未找到相关信息"); 
    135             } 
    136             else{
    137                 printf("请输入新的学生信息:姓名,学号,年纪");
    138             }
    139              break;
    140         case  5:
    141             printf("	[查找信息]
    ");
    142             printf("请输入查找的学号:");
    143             scanf("%s",tempData.num);
    144             if(searchNodeByAppoinNum(list,tempData.num)==NULL){
    145                 printf("未找到相关信息");
    146             }
    147             else{
    148                 printNode(searchNodeByAppoinNum(list,tempData.num));
    149             }
    150             break;
    151         default:
    152             printf("输出错误,请输出0~5"); 
    153      }
    154  }
    155  int main (){
    156      
    157      while(1){
    158          systemMenu();
    159          keyDown();
    160          system("pause");
    161          system("cls");
    162      }
    163      return 0;
    164  }
  • 相关阅读:
    codeforces_1075_C. The Tower is Going Home
    leetcode_Stone Game_dp_思维
    leetcode_Counting Bits_dp
    Divide and Conquer_1.最大连续子数组
    python_MachineLearning_感知机PLA
    IIS中启用gzip压缩(网站优化)
    asp.net运行机制图
    asp.net 的那点事(2、浏览器和一般处理程序)
    asp.net 的那点事(1、当用户在浏览器地址栏输入了网址后,发生了什么?)
    android环境搭配 运行android sdk manager时出现错误问题解决
  • 原文地址:https://www.cnblogs.com/Ssinoo/p/11044184.html
Copyright © 2011-2022 走看看