Advertisement
Nayeemzaman

Lab Final Project

Apr 10th, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 13.72 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include <stdlib.h>
  5.  
  6. typedef struct Node
  7. {
  8.     char id[20];
  9.     char phone[20];
  10.     char dept[20];
  11.     char bg[5];
  12.     char adress[20];
  13.     char name[20];
  14.     struct Node *next;
  15. } node;
  16.  
  17. void insert_after(node *p,char name[20], char id[20], char dept[20], char bg[5], char cont[20])
  18. {
  19.     while(p->next != NULL)
  20.     {
  21.         p = p->next;
  22.     }
  23.     p->next = (node *)malloc(sizeof(node));
  24.  
  25.     strcpy(p->next->name,name);
  26.     strcpy(p->next->id,id);
  27.     strcpy(p->next->dept,dept);
  28.     strcpy(p->next->bg,bg);
  29.     strcpy(p->next->phone,cont);
  30.     p->next->next = NULL;
  31. }
  32. void insert_first(node *p,char name[20], char id[20], char dept[20], char bg[5], char cont[20])
  33. {
  34.     node *temp;
  35.     temp = (node *)malloc(sizeof(node));
  36.  
  37.     strcpy(temp->name,name);
  38.     strcpy(temp->id,id);
  39.     strcpy(temp->dept,dept);
  40.     strcpy(temp->bg,bg);
  41.     strcpy(temp->phone,cont);
  42.  
  43.     temp->next = p->next;
  44.     p->next = temp;
  45. }
  46. void edit_data(node *p,char id[])
  47. {
  48.     int n,ct=0;
  49.     char name1[20];
  50.     char id1[20];
  51.     char dept1[20];
  52.     char bg1[20];
  53.     char phone1[20];
  54.     //node *temp = search(p,id);
  55.     p = p->next;
  56.     while(p != NULL)
  57.     {
  58.         if(strcmp(p->id,id) == 0)
  59.         {
  60.             printf("\n---------------------------------------------------------------\n");
  61.             printf("                 ****Student's Data To Edit****                 ");
  62.             printf("\n---------------------------------------------------------------\n");
  63.  
  64.             printf("1.Student name       : %s\n", p->name);
  65.             printf("2.Student ID         : %s\n", p->id);
  66.             printf("3.Student Department : %s\n", p->dept);
  67.             printf("4.Student Blood group: %s\n", p->bg);
  68.             printf("5.Student Contact    : %s\n\n",p->phone);
  69.  
  70.             printf("Select your option to Edit: ");
  71.  
  72.             scanf("%d",&n);
  73.  
  74.             if(n == 1)
  75.             {
  76.                 printf("Enter the name: ");
  77.                 scanf(" %[^\n]s",name1);
  78.                 strcpy(p->name,name1);
  79.             }
  80.             else if(n == 2)
  81.             {
  82.                 printf("Enter the ID: ");
  83.                 scanf(" %s",id1);
  84.                 strcpy(p->id,id1);
  85.             }
  86.             else if(n == 3)
  87.             {
  88.                 printf("Enter the Department: ");
  89.                 scanf("%s",dept1);
  90.                 strcpy(p->dept,dept1);
  91.             }
  92.             else if(n == 4)
  93.             {
  94.                 printf("Enter the Blood Group: ");
  95.                 scanf("%s",bg1);
  96.                 strcpy(p->bg,bg1);
  97.             }
  98.             else if(n == 5)
  99.             {
  100.                 printf("Enter the Contact: ");
  101.                 scanf("%s",phone1);
  102.                 strcpy(p->phone,phone1);
  103.             }
  104.             else
  105.             {
  106.                 printf("\nError Selection!!\n");
  107.             }
  108.         }
  109.         ct++;
  110.         p = p -> next;
  111.     }
  112.     if(ct == 0)
  113.         printf("\nElement not Found!\n");
  114.  
  115. }
  116.  
  117. int search(node *p, char id[20])
  118. {
  119.     p = p->next;
  120.     while(p != NULL)
  121.     {
  122.         if(strcmp(p->id,id) == 0)
  123.         {
  124.             printf("\n---------------------------------------------------------------\n");
  125.             printf("            ****Displaying Searched Information****              ");
  126.             printf("\n---------------------------------------------------------------\n");
  127.  
  128.             printf("Student name       : %s\n", p->name);
  129.             printf("Student ID         : %s\n", p->id);
  130.             printf("Student Department : %s\n", p->dept);
  131.             printf("Student Blood group: %s\n", p->bg);
  132.             printf("Student Contact    : %s\n\n",p->phone);
  133.  
  134.             return;
  135.         }
  136.         p = p -> next;
  137.     }
  138.     printf("\nSorry!No data found.\n");
  139.     return;
  140. }
  141. void blood_grp(node *p, char bg[5])
  142. {
  143.     int ct=0;
  144.     p = p->next;
  145.     printf("\n---------------------------------------------------------------\n");
  146.     printf("            ****Information of Desired Blood Group****            ");
  147.     printf("\n---------------------------------------------------------------\n");
  148.  
  149.     while(p != NULL)
  150.     {
  151.         if(strcmp(p->bg,bg)==0)
  152.         {
  153.             ct++;
  154.             printf("\nStudent Name  : %s\n",p->name);
  155.             printf("Blood Group   : %s\n",p->bg);
  156.             printf("Contact number: %s\n",p->phone);
  157.         }
  158.         p = p->next;
  159.     }
  160.     if(ct == 0)
  161.         printf("\nNot found\n");
  162. }
  163.  
  164. void dept_search(node *p, char dept[20])
  165. {
  166.     int ct=0;
  167.     p = p->next;
  168.     printf("\n---------------------------------------------------------------\n");
  169.     printf("            ****Department Wise Student Information****            ");
  170.     printf("\n---------------------------------------------------------------\n");
  171.  
  172.     while(p != NULL)
  173.     {
  174.         if(strcmp(p->dept,dept)==0)
  175.         {
  176.             ct++;
  177.             printf("Student name       : %s\n", p->name);
  178.             printf("Student ID         : %s\n", p->id);
  179.             printf("Student Department : %s\n", p->dept);
  180.             printf("Student Blood group: %s\n", p->bg);
  181.             printf("Student Contact    : %s\n\n", p->phone);
  182.         }
  183.         p = p->next;
  184.     }
  185.     if(ct == 0)
  186.         printf("\nNot found\n");
  187. }
  188. void delete(node *p, char id[20])
  189. {
  190.     int ct=0;
  191.     node *temp;
  192.     while(p->next != NULL)
  193.     {
  194.         if(strcmp(p->next->id,id) == 0)
  195.         {
  196.             ct++;
  197.             temp = p->next;
  198.             p->next = temp->next;
  199.             free(temp);
  200.             return 0;
  201.         }
  202.         p = p->next;
  203.     }
  204.     if(ct == 0)
  205.     {
  206.         printf("Element Not Found!!\n");
  207.     }
  208. }
  209.  
  210. void display(node *p)
  211. {
  212.     while(p -> next != NULL)
  213.     {
  214.         printf("Student name       : %s\n", p->next->name);
  215.         printf("Student ID         : %s\n", p->next->id);
  216.         printf("Student Department : %s\n", p->next->dept);
  217.         printf("Student Blood group: %s\n", p->next->bg);
  218.         printf("Student Contact    : %s\n\n", p->next->phone);
  219.         //printf("Student name: %s\n", p->next->name);
  220.         p = p->next;
  221.     }
  222. }
  223. void check_id(node *p,char id[])
  224. {
  225.     while(p->next != NULL)
  226.     {
  227.         if(strcmp(p->next->id,id)==0)
  228.         {
  229.             printf("\nThis ID Already exists!\n");
  230.             printf("Enter a new ID please! :- ");
  231.             scanf("%s",id);
  232.         }
  233.         p = p->next;
  234.     }
  235. }
  236.  
  237. int main()
  238. {
  239.     system("color f0");
  240.     int s;
  241.     char q;
  242.     char name[20];
  243.     char id[20];
  244.     char dept[20];
  245.     char bg[20];
  246.     char phone[20];
  247.  
  248.     node *start = (node *)malloc(sizeof(node));
  249.     start -> next = NULL;
  250.  
  251.     while(1)
  252.     {
  253.  
  254.         printf("\n----------------------------------------------------------------------------\n");
  255.         printf("                     Welcome to Student Database Management System"                    );
  256.         printf("\n----------------------------------------------------------------------------\n");
  257.         printf("\tLog in as:\n");
  258.         printf(" \n\t\t 1. ADMIN \n\n\t\t 0. EXIT");
  259.         printf("\n----------------------------------------------------------------------------\n");
  260.         printf("                                                            "                    );
  261.         printf("\n----------------------------------------------------------------------------\n");
  262.         printf("\n\tEnter Choice:\t\t");
  263.         int choice;
  264.         scanf("%d",&choice);
  265.         switch(choice)
  266.         {
  267.         case 1:
  268.             while(1)
  269.             {
  270.                 printf("\n\n1. Insert Student Data\n");
  271.                 printf("2. Delete Student Data\n");
  272.                 printf("3. Display\n");
  273.                 printf("4. Search\n");
  274.                 printf("5. Insert at first\n");
  275.                 printf("6. Edit Student information\n");
  276.                 printf("7. Search Blood Group\n");
  277.                 printf("8. Search Department\n");
  278.                 printf("0. Exit\n");
  279.  
  280.                 printf("\nEnter your choice: ");
  281.  
  282.                 scanf(" %c",&q);
  283.  
  284.                 switch(q)
  285.                 {
  286.                 case '1':
  287.                     system("CLS");
  288.                     printf("\nIf your want to EXIT press '0' else press any key\n");
  289.                     scanf("%d",&s);
  290.  
  291.                     if(s == 0)
  292.                         break;
  293.                     else
  294.                     {
  295.                         printf("\n---------------------------------------------------------------\n");
  296.                         printf("                 Enter Student information                     ");
  297.                         printf("\n---------------------------------------------------------------\n");
  298.                         printf("Enter name: ");
  299.                         scanf(" %[^\n]s", name);
  300.                         printf("Enter ID: ");
  301.                         scanf("%s", id);
  302.                         check_id(start,id);
  303.                         printf("Enter Department: ");
  304.                         scanf(" %s", dept);
  305.                         printf("Enter Blood Group: ");
  306.                         scanf("%s", bg);
  307.                         printf("Enter contact: ");
  308.                         scanf("%s", phone);
  309.  
  310.                         insert_after(start,name,id,dept,bg,phone);
  311.                     }
  312.                     break;
  313.  
  314.                 case '2':
  315.                     system("CLS");
  316.                     printf("\nIf your want to EXIT press '0' else press any key\n");
  317.                     scanf("%d",&s);
  318.  
  319.                     if(s == 0)
  320.                         break;
  321.                     else
  322.                     {
  323.                         printf("Enter a Student's ID to Delete data: ");
  324.                         scanf("%s", id);
  325.                         delete(start,id);
  326.                     }
  327.                     break;
  328.  
  329.                 case '3':
  330.                     system("CLS");
  331.                     printf("\nIf your want to EXIT press '0' else press any key\n");
  332.                     scanf("%d",&s);
  333.  
  334.                     if(s == 0)
  335.                         break;
  336.                     else
  337.                     {
  338.                         printf("\n---------------------------------------------------------------\n");
  339.                         printf("            ****Student's personal information****                ");
  340.                         printf("\n---------------------------------------------------------------\n");
  341.                         display(start);
  342.                     }
  343.                     break;
  344.                 case '4':
  345.                     system("CLS");
  346.                     printf("\nIf your want to EXIT press '0' else press any key\n\n");
  347.                     scanf("%d",&s);
  348.  
  349.                     if(s == 0)
  350.                         break;
  351.                     else
  352.                     {
  353.                         printf("Enter the ID: ");
  354.                         scanf("%s",id);
  355.                         search(start,id);
  356.                     }
  357.                     break;
  358.                 case '5':
  359.                     system("CLS");
  360.                     printf("\nIf your want to EXIT press '0' else press any key\n");
  361.                     scanf("%d",&s);
  362.  
  363.                     if(s == 0)
  364.                         break;
  365.                     else
  366.                     {
  367.                         printf("\n\nEnter student information\n\n");
  368.                         printf("Enter name: ");
  369.                         scanf(" %[^\n]s", name);
  370.                         printf("Enter ID: ");
  371.                         scanf("%s", id);
  372.                         printf("Enter Department: ");
  373.                         scanf(" %[^\n]s", dept);
  374.                         printf("Enter Blood Group: ");
  375.                         scanf("%s", bg);
  376.                         printf("Enter contact: ");
  377.                         scanf("%s", phone);
  378.  
  379.                         insert_first(start,name,id,dept,bg,phone);
  380.                     }
  381.                     break;
  382.                 case '6':
  383.                     system("CLS");
  384.                     printf("\nIf your want to EXIT press '0' else press any key\n");
  385.                     scanf("%d",&s);
  386.  
  387.                     if(s == 0)
  388.                         break;
  389.                     else
  390.                     {
  391.                         printf("\nEnter the ID to Edit data: ");
  392.                         scanf("%s",id);
  393.                         edit_data(start,id);
  394.                     }
  395.                     break;
  396.                 case '7':
  397.                     system("CLS");
  398.                     printf("\nIf your want to EXIT press '0' else press any key\n");
  399.                     scanf("%d",&s);
  400.  
  401.                     if(s == 0)
  402.                         break;
  403.                     else
  404.                     {
  405.                         printf("\nEnter the desired Blood Group: ");
  406.                         scanf("%s",bg);
  407.                         blood_grp(start,bg);
  408.                     }
  409.                     break;
  410.                 case '8':
  411.                     system("CLS");
  412.                     printf("\nIf your want to EXIT press '0' else press any key\n");
  413.                     scanf("%d",&s);
  414.  
  415.                     if(s == 0)
  416.                         break;
  417.                     else
  418.                     {
  419.                         printf("\nEnter Department Name: ");
  420.                         scanf("%s",dept);
  421.                         dept_search(start,dept);
  422.                     }
  423.                     break;
  424.                 case '0':
  425.                     exit(0);
  426.                 default:
  427.                     system("CLS");
  428.                     printf("Invalid choice.Try again!\n");
  429.                     break;
  430.                 }
  431.             }
  432.             case 0:
  433.                 exit(0);
  434.         }
  435.  
  436.  
  437.     }
  438. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement