[C] 学生成绩管理系统 C语言版 →→→→→进入此内容的聊天室

来自 , 2019-08-25, 写在 C, 查看 107 次.
URL http://www.code666.cn/view/a554f89d
  1. #include"stdio.h"
  2. #include"stddef.h"
  3. #include"stddef.h"
  4. #include"string.h"
  5. #define MAX 10
  6. typedef struct student {
  7.     char name[MAX];
  8.     int num[MAX];
  9.     char sex[MAX];
  10.     int chinese;
  11.     int mathematic;
  12.     int english;
  13.     int computer;
  14.     struct student *next;
  15. } stu;
  16. stu *head;
  17. void print() {
  18.     system("cls");
  19.     printf("\t\t\tScore Manage System\n");
  20.     printf("<1>Enter Record\t");
  21.     printf("<2>Display\t");
  22.     printf("<3>Insert\t");
  23.     printf("<4>Quest\t");
  24.     printf("<5>Update\t");
  25.     printf("<6>Save\t");
  26.     printf("<7>Fresh\t");
  27.     printf("<8>Chinese Average\t");
  28.     printf("<9>Math Average\t");
  29.     printf("<10>English Average\t");
  30.     printf("<11>Computer Average\t");
  31.     printf("<12>Quit\t\n");
  32. }
  33.  
  34. void cin(stu *p1) {
  35.     printf("Enter name:\n");
  36.     scanf("%s", &p1->name);
  37.     printf("Enter num:\n");
  38.     scanf("%d", &p1->num);
  39.     printf("Enter sex:\n");
  40.     scanf("%s", &p1->sex);
  41.     printf("Enter score:\n");
  42.     printf("Enter chinese:\n");
  43.     scanf("%d", &p1->chinese);
  44.     printf("Enter math:\n");
  45.     scanf("%d", &p1->mathematic);
  46.     printf("Enter English:\n");
  47.     scanf("%d", &p1->english);
  48.     printf("Enter Computer:\n");
  49.     scanf("%d", &p1->computer);
  50. }
  51. stu *cindata() {
  52.     stu *p1, *p2;
  53.     int i = 1;
  54.     char ch;
  55.     p1 = (stu *)malloc(sizeof(stu));
  56.     head = p1;
  57.     while(i) {
  58.         cin(p1);
  59.         printf("Do you Want to Continue?yes or no");
  60.         ch = getchar();
  61.         ch = getchar();
  62.         if(ch == 'n' || ch == 'N') {
  63.             i = 0;
  64.             p1->next = NULL;
  65.         } else {
  66.             p2 = p1;
  67.             p1 = (stu *)malloc(sizeof(stu));
  68.             p2->next = p1;
  69.         }
  70.     }
  71.     return(p1->next);
  72. }
  73.  
  74.  
  75. void lookdata(stu *p1) {
  76.     while(p1 != NULL) {
  77.         printf("Num:%d\t", p1->num);
  78.         printf("Name:%s\t", p1->name);
  79.         printf("Sex:%s\t", p1->sex);
  80.         printf("\n");
  81.         printf("Chinese:%d\t", p1->chinese);
  82.         printf("Math:%d\t", p1->mathematic);
  83.         printf("English:%d\t", p1->english);
  84.         printf("Computer:%d\t", p1->computer);
  85.         printf("\n");
  86.         p1 = p1->next;
  87.     }
  88.  
  89. }
  90.  
  91.  
  92.  
  93. void insert(stu *p2) {
  94.     stu *p1, *p3;
  95.     char ch;
  96.     int i = 1;
  97.     p3 = (stu *)malloc(sizeof(stu));
  98.     p1 = p2;
  99.     while(i) {
  100.         cin(p3);
  101.         printf("Enter again?yes or no");
  102.         ch = getchar();
  103.         ch = getchar();
  104.         if(ch == 'n' || ch == 'N') {
  105.             i = 0;
  106.             p3->next = NULL;
  107.         } else {
  108.             while(p1 != NULL)
  109.                 p1 = p1->next;
  110.             p3 = (stu *)malloc(sizeof(stu));
  111.             p1->next = p3;
  112.         }
  113.     }
  114.  
  115. }
  116.  
  117.  
  118.  
  119. find(stu *p2) {
  120.     char name[20];
  121.     int b = 0;
  122.     printf("Enter the name of the student you want to find:");
  123.     scanf("%s", name);
  124.     while(p2 != NULL) {
  125.         if(strcmp(name, p2->name) == 0) {
  126.             printf("The data you want has be found\n");
  127.             printf(" Name:%s\t", p2->name);
  128.             printf("Num:%d\t", p2->num);
  129.             printf("sex%s\t", p2->sex);
  130.             printf("\n");
  131.             printf("Chinese:%d\t", p2->chinese);
  132.             printf("Math:%d\t", p2->mathematic);
  133.             printf("English:%d\t", p2->english);
  134.             printf("Computer:%d\t", p2->computer);
  135.             printf("\n");
  136.  
  137.             b = 1;
  138.         } else if(b == 0)
  139.             printf("对不起,没有找到你要找的数据");
  140.         p2 = p2->next;
  141.     }
  142.  
  143.     if(b == 1) {
  144.         print();
  145.         printf("Find one\n");
  146.     } else {
  147.         print();
  148.         printf("Not find\n");
  149.  
  150.     }
  151. }
  152.  
  153.  
  154. void caverage(stu *p2) {
  155.     stu *p1;
  156.     int i;
  157.     float max = 0.0, min = 200.0;
  158.     float sum = 0.0, aver = 0;
  159.     p1 = p2;
  160.     if(p1 == NULL)
  161.         printf("not data!");
  162.     else
  163.         for(i = 0; p1 != NULL; i++, p1 = p1->next)
  164.             sum += p1->chinese;
  165.     aver /= i;
  166.     for(i = 0; p1 != NULL; i++, p1 = p1->next)
  167.         if(max < p1->chinese)
  168.             max = p1->chinese;
  169.     for(i = 0; p1 != NULL; i++, p1 = p1->next)
  170.         if(min < p1->chinese)
  171.             min = p1->chinese;
  172.     printf("Chinese Average:%f", aver);
  173.     printf("Chinese Max:%f", max);
  174.     printf("Chinese Min:%f", min);
  175. }
  176.  
  177.  
  178.  
  179.  
  180. void maverage(stu *p2) {
  181.     stu *p1;
  182.     int i;
  183.     float max = 0.0, min = 200.0;
  184.     float sum = 0.0, aver = 0;
  185.     p1 = p2;
  186.     if(p1 == NULL)
  187.         printf("not data!");
  188.     else
  189.         for(i = 0; p1 != NULL; i++, p1 = p1->next)
  190.             sum += p1->mathematic;
  191.     aver /= i;
  192.     for(i = 0; p1 != NULL; i++, p1 = p1->next)
  193.         if(max < p1->mathematic)
  194.             max = p1->mathematic;
  195.     for(i = 0; p1 != NULL; i++, p1 = p1->next)
  196.         if(min < p1->mathematic)
  197.             min = p1->mathematic;
  198.     printf("Math Average:%f", aver);
  199.     printf("Math Max:%f", max);
  200.     printf("Math Min:%f", min);
  201. }
  202.  
  203.  
  204. void eaverage(stu *p2) {
  205.     stu *p1;
  206.     int i;
  207.     float max = 0.0, min = 200.0;
  208.     float sum = 0.0, aver = 0;
  209.     p1 = p2;
  210.     if(p1 == NULL)
  211.         printf("not data!");
  212.     else
  213.         for(i = 0; p1 != NULL; i++, p1 = p1->next)
  214.             sum += p1->english;
  215.     aver /= i;
  216.     for(i = 0; p1 != NULL; i++, p1 = p1->next)
  217.         if(max < p1->english)
  218.             max = p1->english;
  219.     for(i = 0; p1 != NULL; i++, p1 = p1->next)
  220.         if(min < p1->english)
  221.             min = p1->english;
  222.     printf("English avergre:%f", aver);
  223.     printf("English Max:%f", max);
  224.     printf("English Min:%f", min);
  225. }
  226.  
  227.  
  228. void comaverage(stu *p2) {
  229.     stu *p1;
  230.     int i;
  231.     float max = 0.0, min = 200.0;
  232.     float sum = 0.0, aver = 0;
  233.     p1 = p2;
  234.     if(p1 == NULL)
  235.         printf("not data!");
  236.     else
  237.         for(i = 0; p1 != NULL; i++, p1 = p1->next)
  238.             sum += p1->computer;
  239.     aver /= i;
  240.     for(i = 0; p1 != NULL; i++, p1 = p1->next)
  241.         if(max < p1->computer)
  242.             max = p1->computer;
  243.     for(i = 0; p1 != NULL; i++, p1 = p1->next)
  244.         if(min < p1->computer)
  245.             min = p1->computer;
  246.     printf("Computer Averger:%f", aver);
  247.     printf("Computer Max:%f", max);
  248.     printf("Computer Min:%f", min);
  249. }
  250.  
  251.  
  252. update(stu *p2) {
  253.     char name[10];
  254.     int b = 0;
  255.     printf("Enter The Name");
  256.     scanf("%s", name);
  257.  
  258.     while(p2 != NULL) {
  259.         if(strcmp(name, p2->name) == 0) {
  260.             printf("Find you data\n");
  261.             scanf("Name:%s", p2->name);
  262.             scanf("Num:%s", p2->num);
  263.             scanf("Sex:%s", p2->sex);
  264.             scanf("Chinese:%d", p2->chinese);
  265.             scanf("Math:%d", p2->mathematic);
  266.             scanf("english:%d", p2->english);
  267.             scanf("Computer:%d", p2->computer);
  268.             printf("Success!");
  269.  
  270.             b = 1;
  271.         } else if(b == 0)
  272.             printf("Sorry not Find data!");
  273.         p2 = p2->next;
  274.     }
  275.     if(b == 0) {
  276.         print();
  277.         printf("Sorry not Find data!");
  278.     } else {
  279.         print();
  280.         printf("Finish!");
  281.     }
  282. }
  283.  
  284.  
  285.  
  286. save(stu *p2) {
  287.     FILE *fp;
  288.     char file[10];
  289.     printf("Enter file name");
  290.     scanf("%s", file);
  291.     fp = fopen(file, "w");
  292.     while(p2 != NULL) {
  293.         fprintf(fp, "%s", p2->name);
  294.         fprintf(fp, "%s", p2->num);
  295.         fprintf(fp, "%s", p2->sex);
  296.         fprintf(fp, "%d", p2->chinese);
  297.         fprintf(fp, "%d", p2->mathematic);
  298.         fprintf(fp, "%d", p2->english);
  299.         fprintf(fp, "%d", p2->computer);
  300.         p2 = p2->next;
  301.     }
  302.     fclose(fp);
  303. }
  304.  
  305.  
  306. char password[7] = "123456";
  307.  
  308.  
  309. void main() {
  310.     int choice;
  311.     stu *p2;
  312.     char s[8];
  313.     int flag = 0, i;
  314.     int n = 3;
  315.     do {
  316.         printf("Enter password:\n");
  317.         scanf("%s", s);
  318.         if(!strcmp(s, password)) {
  319.             printf("PASS\n\n\n");
  320.             flag = 1;
  321.             break;
  322.         } else {
  323.             printf("Error Enter again:\n");
  324.             n--;
  325.         }
  326.     } while(n > 0);
  327.     if(!flag) {
  328.         printf("you have Enter 3 times!");
  329.         exit(0);
  330.     }
  331.  
  332.  
  333.     printf("~~~~~~~~~~\t\t\t~~~~~~~~~~~~\n");
  334.     printf("\t\tWelcom to the Mis\n");
  335.     printf("Author:-----\tClass:------\tNum:------\n");
  336.     printf("Adress:HG\n");
  337.     printf("%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
  338.     printf("\t\tEnter OP:\n");
  339.     printf("\n\n\n\n");
  340.     printf("==============\t\t==============\n");
  341.     printf("==============\t\t==============\n");
  342.     printf("\t\tEnter the MIS yes or no\n");
  343.  
  344.     scanf("%d", &choice);
  345.     if(choice == 'n' || choice == 'N')
  346.         exit(1);
  347.  
  348.     print();
  349.     while(1) {
  350.         printf("Enter choice:");
  351.         scanf("%d", &i);
  352.         if(i < 1 || i > 8) {
  353.             printf("Enter num from 1 to 8:\n");
  354.             exit(1);
  355.         }
  356.  
  357.         switch(i) {
  358.         case 1:
  359.             p2 = cindata();
  360.             break;
  361.         case 2:
  362.             lookdata(head);
  363.             break;
  364.         case 3:
  365.             insert(p2);
  366.             break;
  367.         case 4:
  368.             find(head);
  369.             break;
  370.         case 5:
  371.             update(head);
  372.             break;
  373.         case 6:
  374.             save(head);
  375.             break;
  376.         case 7:
  377.             print();
  378.             break;
  379.         case 8:
  380.             caverage(head);
  381.             break;
  382.         case 9:
  383.             maverage(head);
  384.             break;
  385.         case 10:
  386.             eaverage(head);
  387.             break;
  388.         case 11:
  389.             comaverage(head);
  390.             break;
  391.         case 12:
  392.             ;
  393.         case 13:
  394.             exit(1);
  395.             break;
  396.  
  397.         }
  398.         scanf("%d", &i);
  399.     }
  400.  
  401.  
  402.  
  403. }
  404.  

回复 "学生成绩管理系统 C语言版"

这儿你可以回复上面这条便签

captcha