Advertisement
dmilicev

student_information_system_v1.c

Nov 23rd, 2019
454
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 10.06 KB
  1. /*
  2.  
  3.     student_information_system_v1.c     by Dragan Milicev
  4.  
  5.     for Ephraim Daniel Villegas
  6.  
  7.     https://web.facebook.com/eph.nyl
  8.  
  9. I don't know how old you are or how well you know the C programming language.
  10. I see that you programming on mobile phone and that is an impossible job for me.
  11. You probably can't afford a computer, so you have to do it by mobile phone.
  12. Congratulations on your hard work and persistence.
  13.  
  14.  
  15. The main problem was that you didn't use
  16. fflush(stdin);
  17. While taking an input string with spaces, the buffer does not get cleared
  18. for the next input and considers the previous input for the same.
  19. To solve this problem fflush(stdin) is used to clear the stream/buffer.
  20.  
  21. Use of fflush(stdin) in C
  22.  
  23. https://www.geeksforgeeks.org/use-fflushstdin-c/
  24.  
  25. https://stackoverflow.com/questions/2979209/using-fflushstdin
  26.  
  27. https://www.quora.com/Why-do-we-use-the-functions-fflush-stdin-and-fflush-stdout-in-c
  28.  
  29.  
  30. You didn't give clear names to the variables and that's why you got lost.
  31. I suggest you give the names of the variables much like I wrote.
  32.  
  33. You have two types of variables, int and string whose length is 20 (LEN is 20).
  34.  
  35. Modify my program according to your needs.
  36.  
  37. A lot of time is wasted entering data because there is a lot of it.
  38. It would be good to save data to a file and then read again from that file.
  39. I don't know if you can work with the files in C.
  40.  
  41. C files
  42.  
  43. https://www.tutorialspoint.com/cprogramming/c_file_io.htm
  44.  
  45. lets_learn_c_files_with_array_of_int_v1.c
  46.  
  47. https://pastebin.com/p5mZdKf2
  48.  
  49. Since more students will be introduced, it would be good
  50. to put the data on one student into one structure
  51. and then work with array of structures.
  52. I don't know how well you know the structures and pointers in C.
  53.  
  54. C structures
  55.  
  56. https://www.tutorialspoint.com/cprogramming/c_structures.htm
  57.  
  58. lets_learn_structures_in_c_v1.c
  59.  
  60. https://pastebin.com/HN1ZSQGr
  61.  
  62. For the meny, you have to know Ascii codes of keys
  63. and how to contrlol the keyboard.
  64.  
  65. http://www.asciitable.com/
  66.  
  67. key_codes_with_getch()_v1.c
  68. https://pastebin.com/CTb71BSc
  69.  
  70. keyboard_ascii_codes_with_kbhit()_v1.c
  71. https://pastebin.com/7whsRfyj
  72.  
  73.  
  74.  
  75.     You can find all my C programs at Dragan Milicev's pastebin:
  76.  
  77.     https://pastebin.com/u/dmilicev
  78.  
  79. */
  80.  
  81. #include <stdio.h>
  82.  
  83. #define LEN 20          // lenghth of all strings
  84.  
  85.  
  86. int main ()
  87. {
  88.      int end=0;         // because it is not the end, yet
  89.      int choice;        // choice from menu
  90.      int StudentsInfo;
  91.      int StudentNo;
  92.      int year;
  93.  
  94.     char name[LEN];
  95.     char DateOfRegistration[LEN];
  96.     char Surname[LEN];
  97.     char GivenName[LEN];
  98.     char MiddleName[LEN];
  99.     char Program[LEN];
  100.     char Block[LEN];
  101.     char Gender[LEN];
  102.     char CivilStatus[LEN];
  103.     char BirthDate[LEN];
  104.     char BirthPlace[LEN];
  105.     char Religion[LEN];
  106.     char PersonalContactTel[LEN];
  107.     char EmailAddress[LEN];
  108.     char Lrn[LEN];
  109.     char Address[LEN];
  110.     char FathersName[LEN];
  111.     char FathersContact[LEN];
  112.     char MothersName[LEN];
  113.     char MothersContact[LEN];
  114.     char SchoolLastAttended[LEN];
  115.     char YearLastAttended[LEN];
  116.     char GuardiansName[LEN];
  117.     char GuardiansContact[LEN];
  118.     char GuardiansAddress[LEN];
  119.     char EmergencyPersonName[LEN];
  120.     char EmergencyPersonContact[LEN];
  121.     char EmergencyPersonAddress[LEN];
  122.  
  123.     printf("\n Input your name: ");
  124.     fgets(name,LEN,stdin);
  125.  
  126.     printf("\n Hi %s welcome to Student information system \n",name);
  127.  
  128.     while(!end)
  129.     {
  130.           printf("\n Main Menu");
  131.         printf("\n\n 1. Add");
  132.           printf("\n 2. View");
  133.           printf("\n 3. Edit");
  134.           printf("\n 0. End");
  135.         printf("\n Choose operation: ");
  136.  
  137.         fflush(stdin);          // used to clear the buffer and accept the next string
  138.         scanf("%d",&choice);
  139.  
  140.         switch (choice)
  141.         {
  142.             case 1:             // Add
  143.  
  144.                 printf("\n New Student Info's Form \n");
  145.  
  146.                 printf("\n Input students Info: ");
  147.                 fflush(stdin);  // used to clear the buffer and accept the next string
  148.                 scanf("%d",&StudentsInfo);
  149.                 printf("\n Date of registration: ");
  150.                 fflush(stdin);  // used to clear the buffer and accept the next string
  151.                 fgets(DateOfRegistration,LEN,stdin);
  152.  
  153.                 printf("\n Student No. : ");
  154.                 fflush(stdin);  // used to clear the buffer and accept the next string
  155.                 scanf("%d",&StudentNo);
  156.  
  157.                 printf("\n Surname: ");
  158.                 fflush(stdin);  // used to clear the buffer and accept the next string
  159.                 fgets(Surname,LEN,stdin);
  160.  
  161.                 printf("\n Given name: ");
  162.                 fgets(GivenName,LEN,stdin);
  163.  
  164.                 printf("\n Middle name: ");
  165.                 fgets(MiddleName,LEN,stdin);
  166.  
  167.                 printf("\n Program: ");
  168.                 fgets(Program,LEN,stdin);
  169.  
  170.                 printf("\n year: ");
  171.                 fflush(stdin);  // used to clear the buffer and accept the next string
  172.                 scanf("%d",&year);
  173.  
  174.                 printf("\n Block: ");
  175.                 fflush(stdin);  // used to clear the buffer and accept the next string
  176.                 fgets(Block,LEN,stdin);
  177.  
  178.                 printf("\n Gender: ");
  179.                 fgets(Gender,LEN,stdin);
  180.  
  181.                 printf("\n Civil Status: ");
  182.                 fgets(CivilStatus,LEN,stdin);
  183.  
  184.                 printf("\n Birth Date: ");
  185.                 fgets(BirthDate,LEN,stdin);
  186.  
  187.                 printf("\n Birth Place: ");
  188.                 fgets(BirthPlace,LEN,stdin);
  189.  
  190.                 printf("\n Religion: ");
  191.                 fgets(Religion,LEN,stdin);
  192.  
  193.                 printf("\n Personal Contact/Tel : ");
  194.                 fgets(PersonalContactTel,LEN,stdin);
  195.  
  196.                 printf("\n Email address: ");
  197.                 fgets(EmailAddress,LEN,stdin);
  198.  
  199.                 printf("\n LRN: ");
  200.                 fgets(Lrn,LEN,stdin);
  201.  
  202.                 printf("\n Address: ");
  203.                 fgets(Address,LEN,stdin);
  204.  
  205.                 printf("\n Fathers name: ");
  206.                 fgets(FathersName,LEN,stdin);
  207.  
  208.                 printf("\n Fathers Contact: ");
  209.                 fgets(FathersContact,LEN,stdin);
  210.  
  211.                 printf("\n Mothers Name: ");
  212.                 fgets(MothersName,LEN,stdin);
  213.  
  214.                 printf("\n Mothers Contact: ");
  215.                 fgets(MothersContact,LEN,stdin);
  216.  
  217.                 printf("\n Guardian's Name: ");
  218.                 fgets(GuardiansName,LEN,stdin);
  219.  
  220.                 printf("\n Guardians Contact: ");
  221.                 fgets(GuardiansContact,LEN,stdin);
  222.  
  223.                 printf("\n School Last Attended: ");
  224.                 fgets(SchoolLastAttended,LEN,stdin);
  225.  
  226.                 printf("\n Year Last Attended: ");
  227.                 fgets(YearLastAttended,LEN,stdin);
  228.  
  229.                 printf("\n Person to Contact in case of Emergency \n");
  230.  
  231.                 printf("\n Guardian's Name: ");
  232.                 fgets(GuardiansName,LEN,stdin);
  233.  
  234.                 printf("\n Guardians Contact: ");
  235.                 fgets(GuardiansContact,LEN,stdin);
  236.  
  237.                 printf("\n Guardians Address: ");
  238.                 fgets(GuardiansAddress,LEN,stdin);
  239.  
  240.                 printf("\n Emergency Person Name : ");
  241.                 fgets(EmergencyPersonName,LEN,stdin);
  242.  
  243.                 printf("\n Emergency Person Contact: ");
  244.                 fgets(EmergencyPersonContact,LEN,stdin);
  245.  
  246.                 printf("\n Emergency Person Address: ");
  247.                 fgets(EmergencyPersonAddress,LEN,stdin);
  248.  
  249.                 break;
  250.  
  251.             case 2:             // View
  252.  
  253.                 printf("\n Students Information ");
  254.  
  255.                 printf("\n\n Surname: %s",Surname);
  256.                 printf("\n Given name: %s",GivenName);
  257.                 printf("\n Middle Name: %s",MiddleName);
  258.                 printf("\n Program: %s",Program);
  259.                 printf("\n Date of registration: %s",DateOfRegistration);
  260.                 printf("\n Students Info: %d \n",StudentsInfo);
  261.                 printf("\n Student No: %d \n",StudentNo);
  262.                 printf("\n Program: %s",Program);
  263.                 printf("\n Year: %d \n",year);
  264.                 printf("\n Block: %s",Block);
  265.                 printf("\n Gender: %s",Gender);
  266.                 printf("\n Civil Status: %s",CivilStatus);
  267.                 printf("\n BirthDate: %s",BirthDate);
  268.                 printf("\n BirthPlace: %s",BirthPlace);
  269.                 printf("\n Personal Cel/Tel: %s",PersonalContactTel);
  270.                 printf("\n E-mail Address: %s",EmailAddress);
  271.                 printf("\n LRN: %s",Lrn);
  272.                 printf("\n Address: %s",Address);
  273.                 printf("\n\n Father's Name: %s",FathersName);
  274.                 printf("\n Fathers Contact: %s",FathersContact);
  275.                 printf("\n\n Mother's Name: %s",MothersName);
  276.                 printf("\n Mothers Contact: %s",MothersContact);
  277.                 printf("\n\n Guardians Name: %s",GuardiansName);
  278.                 printf("\n Guardians Contact: %s",GuardiansContact);
  279.                 printf("\n\n Person to Contact in Case of Emergency: \n");
  280.                 printf("\n Emergency Person Name: %s",EmergencyPersonName);
  281.                 printf("\n Emergency Person Contact: %s",EmergencyPersonContact);
  282.                 printf("\n Emergency Person Address: %s",EmergencyPersonAddress);
  283.  
  284.                 break;
  285.             case 3:             // Edit
  286.                 // edit is like add new student or you must use C structure
  287.                 // to choose which student will be edited
  288.                 break;
  289.             case 0:             // if pressed key 0
  290.                 end=1;          // it is end now
  291.                 break;
  292.             default:
  293.                 printf("\n You have to choose numbers 0-3 ! \n");
  294.                 break;
  295.             } // switch (choice)
  296.  
  297.     } // while(!end)
  298.  
  299.     return 0;
  300. } // main()
  301.  
  302.  
  303.  
  304. /*
  305.     OUTPUT:
  306.  
  307.  
  308.  Input your name: Dragan
  309.  
  310.  Hi Dragan
  311.  welcome to Student information system
  312.  
  313.  Main Menu
  314.  
  315.  1. Add
  316.  2. View
  317.  3. Edit
  318.  0. End
  319.  Choose operation: 1
  320.  
  321.  New Student Info's Form
  322.  
  323.  Input students Info: 2
  324.  
  325.  Date of registration: 3
  326.  
  327.  Student No. : 4
  328.  
  329.  Surname: 5
  330.  
  331.  Given name: 6
  332.  
  333.  Middle name: 7
  334.  
  335.  Program: 8
  336.  
  337.  year: 9
  338.  
  339.  Block: 1
  340.  
  341.  Gender: 2
  342.  
  343.  Civil Status: 3
  344.  
  345.  Birth Date: 4
  346.  
  347.  Birth Place: 5
  348.  
  349.  Religion: 6
  350.  
  351.  Personal Contact/Tel : 7
  352.  
  353.  Email address: 8
  354.  
  355.  LRN: 9
  356.  
  357.  Address: 1
  358.  
  359.  Fathers name: 2
  360.  
  361.  Fathers Contact: 3
  362.  
  363.  Mothers Name: 4
  364.  
  365.  Mothers Contact: 5
  366.  
  367.  Guardian's Name: 6
  368.  
  369.  Guardians Contact: 7
  370.  
  371.  School Last Attended: 8
  372.  
  373.  Year Last Attended: 9
  374.  
  375.  Person to Contact in case of Emergency
  376.  
  377.  Guardian's Name: 1
  378.  
  379.  Guardians Contact: 2
  380.  
  381.  Guardians Address: 3
  382.  
  383.  Emergency Person Name : 4
  384.  
  385.  Emergency Person Contact: 5
  386.  
  387.  Emergency Person Address: 6
  388.  
  389.  Main Menu
  390.  
  391.  1. Add
  392.  2. View
  393.  3. Edit
  394.  0. End
  395.  Choose operation: 2
  396.  
  397.  Students Information
  398.  
  399.  Surname: 5
  400.  
  401.  Given name: 6
  402.  
  403.  Middle Name: 7
  404.  
  405.  Program: 8
  406.  
  407.  Date of registration: 3
  408.  
  409.  Students Info: 2
  410.  
  411.  Student No: 4
  412.  
  413.  Program: 8
  414.  
  415.  Year: 9
  416.  
  417.  Block: 1
  418.  
  419.  Gender: 2
  420.  
  421.  Civil Status: 3
  422.  
  423.  BirthDate: 4
  424.  
  425.  BirthPlace: 5
  426.  
  427.  Personal Cel/Tel: 7
  428.  
  429.  E-mail Address: 8
  430.  
  431.  LRN: 9
  432.  
  433.  Address: 1
  434.  
  435.  
  436.  Father's Name: 2
  437.  
  438.  Fathers Contact: 3
  439.  
  440.  
  441.  Mother's Name: 4
  442.  
  443.  Mothers Contact: 5
  444.  
  445.  
  446.  Guardians Name: 1
  447.  
  448.  Guardians Contact: 2
  449.  
  450.  
  451.  Person to Contact in Case of Emergency:
  452.  
  453.  Emergency Person Name: 4
  454.  
  455.  Emergency Person Contact: 5
  456.  
  457.  Emergency Person Address: 6
  458.  
  459.  Main Menu
  460.  
  461.  1. Add
  462.  2. View
  463.  3. Edit
  464.  0. End
  465.  Choose operation: 0
  466.  
  467. Process returned 0 (0x0)   execution time : 98.336 s
  468. Press any key to continue.
  469.  
  470. */
Advertisement
RAW Paste Data Copied
Advertisement