[text] Student Management System

Viewer

copydownloadembedprintName: Student Management System
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include <stdlib.h>   
  4. #include <time.h>
  5. #define SIZE 100
  6. #define true 0
  7. #define false 1
  8.  
  9. struct student
  10.         {
  11.                 char stdid[SIZE];
  12.                 char name[SIZE];
  13.         int  lvl;
  14.                 double sum, eng, math, sci, his, fil, genav;
  15.         };
  16.        
  17. struct student st[SIZE];
  18. int count = 0; 
  19. FILE *f;
  20.  
  21. int writefile()
  22. {
  23.     int i;
  24.     f = fopen("sms.txt", "w");  
  25.     if (f == NULL)
  26.     return -1;                    
  27.     fprintf(f, "%d\n", count);
  28.     for (i = 0; i < count; ++i) 
  29.     {
  30.         fputs(st[i].stdid, f);
  31.         fprintf(f, "\n");
  32.         fputs(st[i].name, f);
  33.         fprintf(f, "\n");
  34.         fprintf(f, "%d\n", st[i].lvl);
  35.         fprintf(f, "\n");
  36.         fprintf(f, "%.2lf\n", st[i].eng);
  37.         fprintf(f, "%.2lf\n", st[i].math);
  38.         fprintf(f, "%.2lf\n", st[i].sci);
  39.         fprintf(f, "%.2lf\n", st[i].his);
  40.         fprintf(f, "%.2lf\n", st[i].fil);
  41.     }
  42.     fclose(f);
  43.     return 0;
  44. }
  45.  
  46. int readFile() 
  47. {
  48.     int n = 0;
  49.     int i;
  50.     f = fopen("sms.txt", "r");
  51.     if (f == NULL)
  52.         return -1;
  53.     fscanf(f, "%d\n", &n);
  54.     for (i = 0; i < n; ++i)
  55.     {
  56.         fgets(st[count].stdid, SIZE, f);
  57.         st[count].stdid[strlen(st[count].stdid) - 1] = 0;
  58.         fgets(st[count].name, SIZE, f);
  59.         st[count].name[strlen(st[count].name)-1] = 0;
  60.         fscanf(f, "%d", &st[count].lvl);
  61.         fscanf(f, "%lf", &st[i].eng);
  62.         fscanf(f, "%lf", &st[i].math);
  63.         fscanf(f, "%lf", &st[i].sci);
  64.         fscanf(f, "%lf", &st[i].his);
  65.         fscanf(f, "%lf\n", &st[i].fil);
  66.     }
  67.     fclose(f);
  68.     return n;
  69. }
  70.  
  71. void delay(int number_of_seconds)
  72. {
  73.     int milli_seconds = 1000 * number_of_seconds;
  74.     clock_t start_time = clock();
  75.     while (clock() < start_time + milli_seconds);
  76. }
  77.  
  78. void deletestudent()
  79.         count=readFile();
  80.         char stdid[SIZE]; 
  81.         int i,j;
  82.         int z=false;
  83.         printf("ENTER ID YOU WANT TO DELETE: ");
  84.         fflush(stdin);
  85.         gets(stdid);
  86.  
  87.         for(i=0;i<count;i++)
  88.         {
  89.                 z=true;
  90.                 if(strcmp(st[i].stdid,stdid)==0)
  91.                         { 
  92.                                 for( j=i; j<(count-1); j++)
  93.                                 {
  94.                                         st[j]=st[j+1];
  95.                                 }
  96.                                 printf("\nSTUDENT HAS BEEN REMOVED SUCCESSFULLY!");
  97.                                 count--;
  98.                         }
  99.         }
  100.                 if(z==false)
  101.                 {
  102.                         printf("STUDENT ID NOT FOUND!");
  103.                 }
  104.         writefile();
  105. }
  106.  
  107. int IDChecker (int i, int j)
  108. {
  109.         count=readFile();
  110.     printf("\nSTUDENT ID: ");
  111.     fflush(stdin);
  112.         gets(st[count].stdid);
  113.     if (strcmp(st[i].stdid,st[j].stdid)==0)
  114.         {
  115.         printf("ID NUMBER IS ALREADY TAKEN!");
  116.         return IDChecker(i++,j--);
  117.         }
  118. }
  119.  
  120. void addnewstudent()
  121. {
  122.         readFile();
  123.       if (count>0) 
  124.                 {
  125.                   count=readFile();
  126.                       IDChecker(0,count);
  127.                 }
  128.         else
  129.                 {
  130.                         printf("\nSTUDENT ID: ");
  131.                         fflush(stdin); 
  132.                         gets(st[count].stdid);
  133.                 }
  134.                 printf("FULL NAME: ");
  135.                 gets(st[count].name);
  136.                 printf("GRADE LEVEL(1-6): ");
  137.                 scanf("%d", &(st[count].lvl));
  138.                 ++count; 
  139.         writefile();
  140. }
  141.  
  142. int checkID(char stdid[])
  143.         int i;
  144.         count=readFile();
  145.         readFile();
  146.       
  147.         for(i=0;i<count;i++)
  148.         {
  149.                  
  150.         if(strcmp(stdid,st[i].stdid)!=0)
  151.                 {
  152.                         fclose(f);
  153.                 }
  154.      return 1;
  155.       }
  156.        
  157.         fclose(f);
  158.        return 0;
  159. }
  160.  
  161. void displayallstudents()
  162. {
  163.         int i;
  164.  
  165.       count = readFile();
  166.      
  167.                 printf("\n");
  168.             printf("\n");
  169.                 printf("\n\t\t\t\t   STUDENT NAME\t-\tSTUDENT ID\t-\tGRADE LEVEL");
  170.                 printf("\n\t\t\t    ----------------------------------------------------------------------\n");
  171.                 printf("\n");
  172.                 printf("\n");
  173.  
  174.      for (i=0;i<count;i++)
  175.         {
  176.      printf("\t\t\t\t%s\t-\t%s\t-\t%d\t\n", st[i].name, st[i].stdid, st[i].lvl) ;
  177.         }
  178. }
  179.  
  180. void inputgrades()
  181. {
  182.         char stdid[SIZE];
  183.         int test;
  184.         int i;
  185.         int choice;
  186.       printf("ENTER STUDENT ID: ");
  187.         fflush(stdin);
  188.         gets(stdid);
  189.         test=checkID(stdid);
  190.     if (test == 0)
  191.         {
  192.               printf("STUDENT ID NOT FOUND");
  193.        }
  194.        else
  195.        {
  196.                readFile();
  197.               {
  198.                         for(i=0;i<count;i++)
  199.                         {
  200.                                 if(strcmp(stdid,st[i].stdid)!=0)
  201.                                 writefile();
  202.                      else
  203.                              {
  204.                                      printf("\nFULL NAME: %s", st[i].name);
  205.                                         printf("\nSTUDENT ID: %s", st[i].stdid);
  206.                                         printf("\nGRADE LEVEL: %d", st[i].lvl);
  207.                                      printf("\n\nREPORT CARD:\n\n");
  208.                                         printf("ENGLISH:\t");
  209.                                     scanf("%lf", &(st[i].eng));
  210.                                     printf("MATH:\t\t");
  211.                                     scanf("%lf", &(st[i].math));
  212.                                     printf("SCIENCE:\t");
  213.                                     scanf("%lf", &(st[i].sci));
  214.                                     printf("HISTORY:\t");
  215.                                     scanf("%lf", &(st[i].his));
  216.                                     printf("FILIPINO:\t");
  217.                                     scanf("%lf", &(st[i].fil));
  218.                                 }
  219.                                 writefile();
  220.                         }
  221.                 }
  222.         }
  223.                 fclose(f); 
  224.                 f = fopen("sms.txt", "r");
  225.                 readFile();
  226.                 {
  227.                         writefile();
  228.                 }
  229.                 fclose(f);
  230. }
  231.  
  232. void viewgrades()
  233. {
  234.         char stdid[SIZE];
  235.         int test;
  236.         int i;
  237.         int choice;
  238.       printf("ENTER STUDENT ID: ");
  239.         fflush(stdin);
  240.         gets(stdid);
  241.         test=checkID(stdid);
  242.     if (test == 0)
  243.         {
  244.               printf("STUDENT ID NOT FOUND");
  245.        }
  246.        else
  247.        {
  248.                readFile();
  249.               {
  250.                         for(i=0;i<count;i++)
  251.                         {
  252.                         if(strcmp(stdid,st[i].stdid)!=0)
  253.                                 writefile();
  254.                      else
  255.                              {
  256.                                      printf("\nWELCOME TO %s's PROFILE!\n", st[i].name);
  257.                                         printf("\nFULL NAME: %s", st[i].name);
  258.                                         printf("\nSTUDENT ID: %s", st[i].stdid);
  259.                                         printf("\nGRADE LEVEL: %d", st[i].lvl);
  260.                                         printf("\n\nREPORT CARD:\n\n");
  261.                                         printf("SUBJECT\t\t|\tGRADE\t\t|\tREMARKS");
  262.                                         printf("\n----------------------------------------------------------------------\n");
  263.                                         printf("\nENGLISH\t\t|\t%.2lf\t\t|\t", st[i].eng);
  264.                         if (st[i].eng < 75)
  265.                                 {
  266.                                         printf("FAILED\n");
  267.                                 }
  268.                         else
  269.                                 {
  270.                                         printf("PASSED\n");
  271.                                 }
  272.                 printf("MATH\t\t|\t%.2lf\t\t|\t", st[i].math);
  273.                         if (st[i].math < 75)
  274.                                 {
  275.                                         printf("FAILED\n");
  276.                                 }
  277.                         else
  278.                                 {
  279.                                         printf("PASSED\n");
  280.                                 }
  281.                 printf("SCIENCE\t\t|\t%.2lf\t\t|\t", st[i].sci);
  282.                         if (st[i].sci < 75)
  283.                                 {
  284.                                         printf("FAILED\n");
  285.                                 }
  286.                         else
  287.                                 {
  288.                                         printf("PASSED\n");
  289.                                 }
  290.                 printf("HISTORY\t\t|\t%.2lf\t\t|\t", st[i].his);
  291.                         if (st[i].his < 75)
  292.                                 {
  293.                                         printf("FAILED\n");
  294.                                 }
  295.                         else
  296.                                 {
  297.                                         printf("PASSED\n");
  298.                                 }
  299.                 printf("FILIPINO\t|\t%.2lf\t\t|\t", st[i].fil);
  300.                         if (st[i].fil < 75)
  301.                                 {
  302.                                         printf("FAILED\n");
  303.                                 }
  304.                         else
  305.                                 {
  306.                                         printf("PASSED\n");
  307.                                 }
  308.                 printf("----------------------------------------------------------------------\n");
  309.                 st[i].sum = st[i].eng + st[i].math + st[i].sci + st[i].his + st[i].fil;
  310.                 st[i].genav = st[i].sum / 5;
  311.                 printf("GENERAL AVERAGE\t|\t%.2lf\t\t|\t", st[i].genav);
  312.                         if (st[i].genav < 75)
  313.                                 {
  314.                                         printf("FAILED\n");
  315.                                 }
  316.                         else
  317.                                 {
  318.                                         printf("PASSED\n");
  319.                                 }
  320.         writefile();
  321.                                 }
  322.                                    
  323.                         }
  324.                 }
  325.                 fclose(f); 
  326.                 f = fopen("sms.txt", "r");
  327.                 readFile();
  328.                 {
  329.                         writefile();
  330.                 }
  331.                 fclose(f);
  332.         }
  333. }
  334. void editstudent()
  335. {      
  336.         char stdid[SIZE];
  337.         int test;
  338.         int i;
  339.         int choice;
  340.       printf("ENTER STUDENT ID: ");
  341.         fflush(stdin);
  342.         gets(stdid);
  343.         test=checkID(stdid);
  344.     if (test == 0)
  345.         {
  346.               printf("STUDENT ID NOT FOUND");
  347.        }
  348.        else
  349.        {
  350.                readFile();
  351.               {
  352.                         for(i=0;i<count;i++)
  353.                         {
  354.                                 if(strcmp(stdid,st[i].stdid)!=0)
  355.                                 writefile();
  356.                      else
  357.                              {
  358.                                      printf("\nWHAT DO YOU WANT TO UPDATE?\n\n");
  359.                             printf("<1> STUDENT ID\n");
  360.                                 printf("<2> FULL NAME\n");
  361.                             printf("<3> GRADE LEVEL\n");
  362.                             printf("<4> ENGLISH GRADE\n");
  363.                             printf("<5> MATH GRADE\n");
  364.                             printf("<6> SCIENCE GRADE\n");
  365.                             printf("<7> HISTORY GRADE\n");
  366.                             printf("<8> FILIPINO GRADE\n");
  367.                             printf("<9> UPDATE ALL INFORMATION OF STUDENT\n");
  368.                             printf("\nCHOOSE TASK TO PERFORM: ");
  369.                                     fflush(stdin);
  370.                                     scanf("%d", &choice);
  371.                                
  372.                                     switch (choice)
  373.                                     {
  374.                                     case 1:
  375.                                             printf("STUDENT ID: ");
  376.                                                fflush(stdin);
  377.                                         gets(st[i].stdid);
  378.                                     break;
  379.                                     case 2:
  380.                                             printf("FULL NAME: ");
  381.                                             fflush(stdin);
  382.                                         gets(st[i].name);
  383.                                     break;
  384.                                     case 3:
  385.                                             {
  386.                                                         int c=10;
  387.                                                         int lvl;
  388.                                                         while (c!=0)
  389.                                                         {
  390.                                                                 printf("\nGRADE LEVEL(1-6): ");
  391.                                                                 scanf("%d", &(st[i].lvl));
  392.                                                                                                                                                        
  393.                                                                 if ((st[i].lvl)>=1 && (st[i].lvl)<=6)
  394.                                                                         {
  395.                                                                                 c=0;
  396.                                                                         }
  397.                                                                 else
  398.                                                                         {
  399.                                                                                 printf("\nSORRY, YOU HAVE ENTERED AN INVALID NUMBER. PLEASE TRY AGAIN.\n");
  400.                                                                         }
  401.                                                                 printf("\n");
  402.                                                         }
  403.                                                 }      
  404.                                     break;
  405.                                     case 4:
  406.                                             printf("\nENGLISH GRADE: ");
  407.                                                 scanf("%lf", &(st[i].eng));
  408.                                     break;
  409.                                     case 5:
  410.                                            printf("\nMATH GRADE: ");
  411.                                                 scanf("%lf", &(st[i].math));
  412.                                         break;
  413.                                         case 6:
  414.                                            printf("\nSCIENCE GRADE: ");
  415.                                                 scanf("%lf", &(st[i].sci));
  416.                                         break;
  417.                                         case 7:
  418.                                            printf("\nHISTORY GRADE: ");
  419.                                                 scanf("%lf", &(st[i].his));
  420.                                         break;
  421.                                         case 8:
  422.                                            printf("\nFILIPINO GRADE: ");
  423.                                                 scanf("%lf", &(st[i].fil));
  424.                                         break;
  425.                                     default:
  426.                                            printf("YOU HAVE ENTERED AN INVALID NUMBER.");
  427.                                     break;
  428.                                     }
  429.                                    writefile();
  430.                                 }
  431.                                    
  432.                         }
  433.                 }
  434.                 fclose(f); 
  435.                 f = fopen("sms.txt", "r");
  436.                 readFile();
  437.                 {
  438.                         writefile();
  439.                 }
  440.                 fclose(f);
  441.                 printf("PROFILE UPDATED");
  442.         }
  443. }
  444.  
  445.  
  446.  
  447.  
  448. int main ()
  449. {
  450.         int a=10;
  451.         int id;
  452.         char name[SIZE];
  453.         char pswd[SIZE];
  454.        
  455.         system("color F6");
  456.         printf("\n");
  457.         printf("\n");
  458.         printf("\n");
  459.     printf("\t\t            O==========================================================O\n");
  460.     printf("\t\t            |  OUR LADY OF FATIMA UNIVERISTY - VALENZUELA CITY CAMPUS  |\n");
  461.     printf("\t\t            |                                                          |");
  462.     printf("\n\t\t          |           WELCOME TO THE INSTRUCTOR PORTAL!            |\n");       
  463.     printf("\t\t            O==========================================================O\n");
  464.         printf("\n");
  465.         printf("\n");
  466.         printf("\n");
  467.        
  468.        
  469.         while (a!=0)
  470.         {
  471.                 char un[SIZE];
  472.                 char pswd[SIZE];
  473.                 printf("\n\t\t\t\t\t\t   USERNAME: ");
  474.                 scanf("%s", un);
  475.                 printf("\t\t\t\t\t\t   PASSWORD: ");
  476.                 scanf("%s", pswd);
  477.  
  478.                 if (strcmp(un, "olfu") == 0 && strcmp(pswd, "ccs") == 0)
  479.                 {
  480.                         printf("\n\t\t\t\t\tLOGIN SUCCESSFUL! PLEASE WAIT A MOMENT...");
  481.                         a=0;
  482.                         delay(2);
  483.                         system("cls");
  484.                 }
  485.                 else
  486.                 {
  487.                         printf("\n\t\t\t  THE USERNAME AND/OR PASSWORD IS INCORRECT. PLEASE TRY AGAIN IN 3 SECONDS.");
  488.                         delay(3);
  489.                         system("cls");
  490.                 }
  491.                 printf("\n");
  492.         }
  493.              int choice;
  494.                 while (1) 
  495.                 {
  496.                                 printf("\n");
  497.                                 printf("\n");
  498.                         printf("\n\t\t          O==================STUDENT MANAGEMENT SYSTEM==================O");
  499.                         printf("\n\t\t\t\t|                                                           |");
  500.                                 printf("\n\t\t\t\t|             <1> ADD A NEW STUDENT\t\t\t      |\n");
  501.                                 printf("\t\t\t\t|               <2> SHOW STUDENT LIST\t\t\t      |\n");
  502.                                 printf("\t\t\t\t|               <3> INPUT STUDENT'S GRADES\t\t      |\n");
  503.                                 printf("\t\t\t\t|               <4> VIEW STUDENT'S GRADES\t\t      |\n");
  504.                                 printf("\t\t\t\t|               <5> EDIT STUDENT PROFILE\t\t      |\n");
  505.                                 printf("\t\t\t\t|               <6> DELETE A STUDENT\t\t\t      |\n");
  506.                                 printf("\t\t\t\t|               <7> EXIT\t\t\t\t      |");
  507.                                 printf("\n\t\t\t\t|                                                           |");
  508.                                 printf("\n\t\t          O=============================================================O\n");
  509.                                 printf("\n");
  510.                                 printf("\n");
  511.                                 printf("\n\t\t\t\t\t      CHOOSE A TASK TO PERFORM (1-7): ");
  512.                                
  513.                                 scanf("%d", &choice);
  514.                                     switch(choice)
  515.                                         {
  516.                                 case 1: addnewstudent();
  517.                                         break;
  518.                                 case 2: displayallstudents();
  519.                                                         break;
  520.                                         case 3: inputgrades();
  521.                                                         break;
  522.                                 case 4: viewgrades();
  523.                                         break;
  524.                                  case 5:        editstudent();
  525.                                                        break;
  526.                                      case 6:        deletestudent();
  527.                                                        break;
  528.                                         case 7:        exit(1);
  529.                                                      break;
  530.                                         default:
  531.                                     printf("YOU HAVE ENTERED AN INVALID VALUE");
  532.                                     break;
  533.                               }
  534.   }
  535.   while(choice!=8);
  536. }

Editor

You can edit this paste and save as new:


File Description
  • Student Management System
  • Paste Code
  • 02 Dec-2022
  • 11.67 Kb
You can Share it: