Advertisement
Nayeemzaman

Project

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