728x90 AdSpace

  • Latest News

    বুধবার, ১৯ আগস্ট, ২০১৫

    Student Information System Using Link List in C Language

     #include <stdio.h>
    struct node
    {
        char name[10];
        int id;
        float point ;
        int age;
        char dept[5];
        struct node*s;
    };
    typedef struct node NODE;
    NODE*H=NULL;
    NODE*N1=NULL;
    NODE*N2=NULL;
    NODE*N3=NULL;
    NODE*N4=NULL;
    NODE*N5=NULL;
    NODE*N6=NULL;
    NODE*N7=NULL;
    NODE*N8=NULL;
    NODE*N9=NULL;
    NODE*N10=NULL;
    NODE *prev = NULL;

    void create_nodes()
    {
        N1 = (NODE*)malloc(sizeof(NODE));
        N2 = (NODE*)malloc(sizeof(NODE));
        N3 = (NODE*)malloc(sizeof(NODE));
         N4 = (NODE*)malloc(sizeof(NODE));
          N5 = (NODE*)malloc(sizeof(NODE));
           N6 = (NODE*)malloc(sizeof(NODE));
            N7 = (NODE*)malloc(sizeof(NODE));
             N8 = (NODE*)malloc(sizeof(NODE));
             N9 = (NODE*)malloc(sizeof(NODE));
              N10 = (NODE*)malloc(sizeof(NODE));

              strcpy(N1->name,"Raju");N1->id=14315173;N1->point=3.63;N1->age=19;strcpy(N1->dept,"CSE");
              strcpy(N2->name,"Roni");N2->id=14315174;N2->point=2.63;N2->age=19;strcpy(N2->dept,"EEE");
              strcpy(N3->name,"Rabbi");N3->id=14315175;N3->point=3.03;N3->age=20;strcpy(N3->dept,"CSE");
              strcpy(N4->name,"Rifat");N4->id=14315176;N4->point=3.83;N4->age=22;strcpy(N4->dept,"CSE");
              strcpy(N5->name,"Rajon");N5->id=14315177;N5->point=3.23;N5->age=19;strcpy(N5->dept,"CSE");
              strcpy(N6->name,"Rubi");N6->id=14315178;N6->point=2.83;N6->age=24;strcpy(N6->dept,"CSE");
              strcpy(N7->name,"Ruma");N7->id=14315179;N7->point=3.93;N7->age=19;strcpy(N7->dept,"CSE");
              strcpy(N8->name,"Ronju");N8->id=14315180;N8->point=4.00;N8->age=19;strcpy(N8->dept,"CSE");
              strcpy(N9->name,"Rubel");N9->id=14315181;N9->point=3.63;N9->age=19;strcpy(N9->dept,"CSE");
              strcpy(N10->name,"Rumpa");N10->id=14315182;N10->point=3.63;N10->age=19;strcpy(N10->dept,"CSE");


        H = N1;
        N1->s = N2;
        N2->s = N3;
        N3->s=N4;
        N4->s=N5;
        N5->s=N6;
        N6->s=N7;
        N7->s=N8;
        N8->s=N9;
        N9->s=N10;
        N10->s = NULL;

    }
     NODE*searchItem()
    {
       NODE*ptr = H;
    int item;
    printf("Enter the ID number:");
       scanf("%d",&item);
        while(ptr != NULL){
            if(item == ptr->id){
                printf("\nID FOUND\n");
                printf("Name:%s\nID:%d\nCGPA:%.2f\nAge:%d\nDept:%s\n",ptr->name, ptr->id, ptr->point,ptr->age,ptr->dept);
                return ptr;
                break;
            }else{
                  prev = ptr;
                  ptr = ptr->s;
            }
        }

        if(ptr==NULL)printf("\nID not found\n");
        return NULL;

    }
     NODE*search()
    {
      NODE*ptr = H;
    int item;
    printf("\nEnter the ID number:");
       scanf("%d",&item);
        while(ptr != NULL){
            if(item == ptr->id){
                printf("\nID FOUND\n");
                return ptr;
                break;
            }else{
                  prev = ptr;
                  ptr = ptr->s;
            }
        }

        if(ptr==NULL)printf("\nID not found\n");
        return NULL;

    }
    void deleteNode()
    { displayNodes();
        NODE*ptr = NULL;
      ptr = search();

      if (ptr == NULL){
        printf("\n\nNothing to delete.\n\n");
      } else {
          if(prev == NULL){
            H = ptr->s;
            printf("Deletion completed\n");
          }else {
             prev->s = ptr->s;
             printf("Deletion completed\n");
          }
      }

    }
    void displayNodes(){
        NODE*ptr = H;int a=1;
        printf("SL\tNAME\tID\t\tCGPA\tAGE\tDEPT\n");
        while(ptr != NULL){
            printf("%d:\t%s\t%d\t%.2f\t%d\t%s\n",a, ptr->name, ptr->id, ptr->point,ptr->age,ptr->dept);
            ptr = ptr->s;
            a++;
        }
    }
    void randInsertion(){
        int a=0,b;
        displayNodes();
        printf("\nEnter the position:");
        scanf("%d",&b);
       if(b==1){insert_f();}
       else
        {
            rand(b);

       }

    }
    void rand(int d){
        char nam[10];
        int i;
        float poi;
        int ag;
        char dep[5];
        int a=0;NODE*ptr=H;
        for(a=0;a<d-2;a++)
            {ptr=ptr->s;}
     NODE *N= NULL;
     printf("Enter name: ");
     scanf("%s",nam);
     printf("Enter ID:");
     scanf("%d",&i);
     printf("Enter CGPA: ");
     scanf("%f",&poi);
     printf("Enter Age: ");
     scanf("%d",&ag);
     printf("Enter Dept:");
     scanf("%s",dep);
     N = (NODE*)malloc(sizeof(NODE));
     strcpy(N->name,nam); N->id=i;N->point=poi;N->age=ag;strcpy(N->dept,dep);
     N->s=ptr->s;
     ptr->s=N;
      printf("\nSuccessful Inserted\n");

    }
    void insert_f()
    {
        char nam[10];
        int i;
        float poi;
        int ag;
        char dep[5];
     NODE*N= NULL;
     printf("Enter name: ");
     scanf("%s",nam);
     printf("Enter ID:");
     scanf("%d",&i);
     printf("Enter CGPA: ");
     scanf("%f",&poi);
     printf("Enter Age: ");
     scanf("%d",&ag);
     printf("Enter Dept:");
     scanf("%s",dep);
     N = (NODE*)malloc(sizeof(NODE));
     strcpy(N->name,nam); N->id=i;N->point=poi;N->age=ag;strcpy(N->dept,dep);
        N->s=H;
        H=N;


        printf("\nSuccessful Inserted\n");

    }



    int menu1()
    {
        int j;
        printf("\nPress 1 for Insertion >> ");
        printf("\nPress 2 for Display >> ");
        printf("\nPress 3 for Delete >> ");
        printf("\nPress 4 for Searching >> ");
        printf("\nPress 5 for Updated>> ");
        printf("\nPress 0 for exit >> \n");
        scanf("%d",&j);
       //getch(j);
        return j;
    system("cls");

    }
    int updated()
    {
        char nam[10];
        int i;
        float poi;
        int ag;
        char dep[10];
      displayNodes();
        NODE*ptr = NULL;
      ptr = search();
     NODE *N= NULL;
     printf("Enter Name: ");
     scanf("%s",nam);
     printf("Enter ID:");
     scanf("%d",&i);
     printf("Enter CGPA: ");
     scanf("%f",&poi);
     printf("Enter Age: ");
     scanf("%d",&ag);
     printf("Enter Dept:");
     scanf("%s",dep);
     N = (NODE*)malloc(sizeof(NODE));
     strcpy(N->name,nam); N->id=i;N->point=poi;N->age=ag;strcpy(N->dept,dep);
     N->s=ptr->s;
     ptr->s=N;

          if(prev == NULL){

                H = ptr->s;
          }else {


             prev->s = ptr->s;
          }

       printf("\nSuccessful Updated \n");
    }
    int main()
    {

      system("color 3b");
        int a;

        create_nodes();

    printf("*************////// DIU SIUDENT INFORMATION \\\\\\\\****************\n");
    a=menu1();
    create_nodes();
    system("cls");
        while (a!=0)
        {

            switch (a)
            {


                case 1:randInsertion();break;
                case 2:displayNodes();break;
                case 3: deleteNode();break;
                case 4: searchItem();break;
                case 5:updated();break;
                default : printf("Invalid input");
            }
            printf("\n\nEnter any key to continue ");
            getch();
             a=menu1();
            system("cls");



        }

    }

    • Blogger Comments
    • Facebook Comments

    0 মন্তব্য(গুলি):

    একটি মন্তব্য পোস্ট করুন

    Item Reviewed: Student Information System Using Link List in C Language Rating: 5 Reviewed By: Unknown
    Scroll to Top