Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h >
- #include<string.h>
- typedef struct node
- {
- char name[20];
- char id[20];
- char dept[70];
- char designation[50];
- char phone[11];
- int batch;
- char sec[5];
- char blood[3];
- struct node *left,*right;
- }node;
- node *root_teacher=NULL,*root_student=NULL,*root_staff=NULL,*root_cr=NULL;
- int flag=0,ft=0,fs=0,fst=0,fds=0;
- void Delete() ;
- void deletet();
- void searchcr();
- void search() ;
- void bst(); //flag using search cr
- //ft using teacher display
- //fs using student display
- //fds for same department and same batch
- //fst using staff display
- void bst(node *head,node *temp) //bst for teacher
- {
- if(strcmp(head->id,temp->id)==1||strcmp(head->id,temp->id)==0)
- {
- if(head->left==NULL)
- {
- head->left=temp;
- return;
- }
- else
- {
- bst(head->left,temp);
- }
- }
- else if(strcmp(head->id,temp->id)==-1)
- {
- if(head->right==NULL)
- {
- head->right=temp;
- return;
- }
- else
- {
- bst(head->right,temp);
- }
- }
- }
- node *getSuccessor(node *n) // for teacher
- {
- if(n->left == NULL)
- {
- return n;
- }
- else
- {
- getSuccessor(n->left);
- }
- }
- node *parent(node *n , node *r) //for teacher
- {
- // we alredy checked that n is not the root and n is exist
- if(strcmp(r->id,n->id)==1||strcmp(r->id,n->id)==0)
- {
- if(strcmp(r->left->id,n->id)==0)
- {
- return r;
- }
- else
- {
- parent(n , r->left);
- }
- }
- else
- {
- if(strcmp(r->right->id,n->id)==0)
- {
- return r;
- }
- else
- {
- parent(n , r->right);
- }
- }
- }
- void deletet(node *n) // for teacher
- {
- char x[50];
- node *successor, *p;
- if(n->left != NULL && n->right != NULL)
- {
- successor = getSuccessor(n->right);
- strcpy(x,successor->id);
- deletet(successor);
- strcpy(n->id,x);
- return;
- }
- if(n->left == NULL && n->right == NULL)
- {
- if(n == root_teacher)
- {
- root_teacher = NULL;
- }
- else
- {
- p = parent(n , root_teacher);
- if(p->left == n)
- {
- p->left = NULL;
- }
- else
- {
- p->right = NULL;
- }
- }
- free(n);
- return;
- }
- if(n->left != NULL && n->right == NULL)
- {
- strcpy(x,n->left->id);
- deletet(n->left);
- strcpy(n->id,x);
- return;
- }
- if(n->left == NULL && n->right != NULL)
- {
- strcpy(x,n->right->id);
- deletet(n->right);
- strcpy(n->id,x);
- return;
- }
- }
- void searchcr(node *head,char s[],int b) //searcht=searching for teacher
- {
- if(head==NULL)
- {
- return;
- }
- searchcr(head->left,s,b);
- if(strcmp(head->sec,s)==0&&head->batch==b)
- {
- printf("\nName Of the Department:%s\n",head->dept);
- printf("Batch:%d\n",head->batch);
- printf("Name:%s\n",head->name);
- printf("Student ID:%s\n",head->id);
- printf("Section:%s\n",head->sec);
- printf("Phone No:%s\n",head->phone);
- printf("Blood Group:%s\n",head->blood);
- flag=1;
- }
- searchcr(head->right,s,b);
- return;
- }
- node *searcht(node *head,char s[]) //searcht=searching for teacher
- {
- if(head==NULL)
- {
- return NULL;
- }
- else if(strcmp(head->id,s)==0)
- {
- return head;
- }
- else if(strcmp(head->id,s)==1)
- {
- searcht(head->left,s);
- }
- else if(strcmp(head->id,s)==-1)
- {
- searcht(head->right, s);
- }
- }
- void Delete()
- {
- printf("\n1.Delete Teacher's Information\n");
- printf("2.Delete Student's Information\n");
- printf("3.Delete Staff Information\n");
- printf("4.Delete CR Information\n");
- printf("5.Menu\n");
- printf("6.Exit\n");
- int x;
- printf("Choose Any one:");
- scanf("%d",&x);
- switch(x)
- {
- case 1:
- { char temp[50];
- printf("Enter Teacher's Id:");
- scanf(" %[^\n]",temp);
- if(root_teacher==NULL)
- {
- printf("\nNO Information Available\n");
- }
- else
- {
- node *n1=searcht(root_teacher,temp);
- if(n1==NULL)
- {
- printf("NO Information Available!!\n\n");
- }
- else
- {
- deletet(n1);
- printf("\nInformation Deleted!!\n\n");
- }
- }
- printf("1.Back\n");
- printf("2.Menu\n");
- int z;
- printf("choose One:");
- scanf("%d",&z);
- if(z==1)
- {
- Delete();
- }
- else
- {
- menu();
- }
- }
- case 2:
- {
- char temp[50];
- printf("Enter Student Id:");
- scanf("%s",temp);
- if(root_student==NULL)
- {
- printf("\nNO Information Available\n");
- }
- else
- {
- node *n2=searcht(root_student,temp);
- if(n2==NULL)
- {
- printf("NO Information Available!!\n\n");
- }
- else
- {
- deletet(n2);
- printf("\nInformation Deleted!!\n\n");
- }
- }
- printf("1.Back\n");
- printf("2.Menu\n");
- int z;
- printf("choose One:");
- scanf("%d",&z);
- if(z==1)
- {
- Delete();
- }
- else
- {
- menu();
- }
- }
- case 3:
- {
- char temp[50];
- printf("Enter Staff Id:");
- scanf(" %[^\n]",temp);
- if(root_staff==NULL)
- {
- printf("\nNO Information Available\n");
- }
- else
- {
- node *n1=searcht(root_staff,temp);
- if(n1==NULL)
- {
- printf("NO Information Available!!\n\n");
- }
- else
- {
- deletet(n1);
- printf("\nInformation Deleted!!\n\n");
- }
- }
- printf("1.Back\n");
- printf("2.Menu\n");
- int z;
- printf("choose One:");
- scanf("%d",&z);
- if(z==1)
- {
- Delete();
- }
- else
- {
- menu();
- }
- }
- case 4:
- {
- char temp[50];
- printf("Enter CR Id:");
- scanf(" %[^\n]",temp);
- if(root_cr==NULL)
- {
- printf("\nNO Information Available\n");
- }
- else
- {
- node *n1=searcht(root_cr,temp);
- if(n1==NULL)
- {
- printf("NO Information Available!!\n\n");
- }
- else
- {
- deletet(n1);
- printf("\nInformation Deleted!!\n\n");
- }
- }
- printf("1.Back\n");
- printf("2.Menu\n");
- int z;
- printf("choose One:");
- scanf("%d",&z);
- if(z==1)
- {
- Delete();
- }
- else
- {
- menu();
- }
- }
- case 5:
- {
- menu();
- break;
- }
- case 6:
- {
- exit(0);
- break;
- }
- }
- }
- void search()
- {
- printf("\n1.Search Techer's Information\n");
- printf("2.Search Student's Information\n");
- printf("3.Search Staff Information\n");
- printf("4.Search CR Information\n");
- printf("5.Menu\n");
- printf("6.Exit\n");
- int x;
- printf("Choose Any one:");
- scanf("%d",&x);
- switch(x)
- {
- case 1:
- { node *n;
- char temp[20];
- printf("\nEnter Teacher's ID:");
- scanf("%s",temp);
- n=searcht(root_teacher,temp);
- if(n==NULL)
- {
- printf("\nNo Information Available!!\n");
- }
- else
- {
- printf("\nName Of the Department:%s\n",n->dept);
- printf("Teacher's Name:%s\n",n->name);
- printf("Teacher's ID:%s\n",n->id);
- printf("Phone No:%s\n",n->phone);
- printf("Designation:%s\n\n",n->designation);
- }
- printf("1.Back\n");
- printf("2.Menu\n");
- int z;
- printf("Choose any One:");
- scanf("%d",&z);
- if(z==1)
- {
- search();
- }
- else
- {
- menu();
- }
- }
- case 2:
- {node *n;
- char temp[20];
- printf("\nEnter Student ID:");
- scanf("%s",temp);
- n=searcht(root_student,temp);
- if(n==NULL)
- {
- printf("\nNo Information Available!!\n");
- }
- else
- {
- printf("\nName Of the Department:%s\n",n->dept);
- printf("Batch:%d\n",n->batch);
- printf("Name:%s\n",n->name);
- printf("Student ID:%s\n",n->id);
- printf("Section:%s\n",n->sec);
- printf("Phone No:%s\n",n->phone);
- printf("Blood Group:%s\n",n->blood);
- }
- printf("1.Back\n");
- printf("2.Menu\n");
- int z;
- printf("Choose any One:");
- scanf("%d",&z);
- if(z==1)
- {
- search();
- }
- else
- {
- menu();
- }
- }
- case 3:
- {
- node *n;
- char temp[20];
- printf("\nEnter Staff ID:");
- scanf("%s",temp);
- n=searcht(root_staff,temp);
- if(n==NULL)
- {
- printf("\nNo Information Available!!\n");
- }
- else
- {
- printf("Name:%s\n",n->name);
- printf("Staff ID:%s\n",n->id);
- printf("Phone No:%s\n",n->phone);
- printf("Blood Group:%s\n",n->blood);
- printf("Designation:%s\n\n",n->designation);
- }
- printf("1.Back\n");
- printf("2.Menu\n");
- int z;
- printf("Choose any One:");
- scanf("%d",&z);
- if(z==1)
- {
- search();
- }
- else
- {
- menu();
- }
- }
- case 4:
- {
- node *n;
- int b;
- char temp[20];
- printf("\nEnter Batch:");
- scanf("%d",&b);
- printf("Enter The Section:");
- scanf("%s",temp);
- searchcr(root_cr,temp,b);
- if(flag==0)
- {
- printf("\nNo Information Available!!\n");
- }
- else
- {
- flag=0;
- }
- printf("1.Back\n");
- printf("2.Menu\n");
- int z;
- printf("Choose any One:");
- scanf("%d",&z);
- if(z==1)
- {
- search();
- }
- else
- {
- menu();
- }
- }
- case 5:
- {
- menu();
- }
- case 6:
- {
- exit(0);
- }
- default:
- {
- printf("\nPlease Choose Correct Option!!\a");
- search();
- }
- }
- }
- void displayst(node *head)
- {
- if(head==NULL)
- {
- return;
- }
- displayst(head->left);
- printf("Name:%s\n",head->name);
- printf("Staff ID:%s\n",head->id);
- printf("Phone No:%s\n",head->phone);
- printf("Blood Group:%s\n",head->blood);
- printf("Designation:%s\n\n",head->designation);
- displayst(head->right);
- return;
- }
- void displaydb(node *head,int b,char s[])
- {
- if(head==NULL)
- {
- return;
- }
- displaydb(head->left,b,s);
- if(head->batch==b && strcmp(head->dept,s)==0)
- {
- printf("\nName Of the Department:%s\n",head->dept);
- printf("Batch:%d\n",head->batch);
- printf("Name:%s\n",head->name);
- printf("Student ID:%s\n",head->id);
- printf("Section:%s\n",head->sec);
- printf("Phone No:%s\n",head->phone);
- printf("Blood Group:%s\n\n",head->blood);
- fds=1;
- }
- displaydb(head->right,b,s);
- return;
- }
- void displayb(node *head,int b) //display for all same batch Student
- {
- if(head==NULL)
- {
- return;
- }
- displayb(head->left,b);
- if(head->batch==b)
- {
- printf("\nName Of the Department:%s\n",head->dept);
- printf("Batch:%d\n",head->batch);
- printf("Name:%s\n",head->name);
- printf("Student ID:%s\n",head->id);
- printf("Section:%s\n",head->sec);
- printf("Phone No:%s\n",head->phone);
- printf("Blood Group:%s\n\n",head->blood);
- fs=1;
- }
- displayb(head->right,b);
- return;
- }
- void displays(node *head) //display all student information
- {
- if (head==NULL)
- {
- return;
- }
- displays(head->left);
- printf("\nName Of the Department:%s\n",head->dept);
- printf("Batch:%d\n",head->batch);
- printf("Name:%s\n",head->name);
- printf("Student ID:%s\n",head->id);
- printf("Section:%s\n",head->sec);
- printf("Phone No:%s\n",head->phone);
- printf("Blood Group:%s\n\n",head->blood);
- displays(head->right);
- return;
- }
- void displayt(node *head) //display for teacher.
- {
- if(head==NULL)
- {
- return;
- }
- displayt(head->left);
- printf("\nName Of the Department:%s\n",head->dept);
- printf("Teacher's Name:%s\n",head->name);
- printf("Teacher's ID:%s\n",head->id);
- printf("Phone No:%s\n",head->phone);
- printf("Designation:%s\n\n",head->designation);
- displayt(head->right);
- return;
- }
- void displayd(node *head,char s[]) //display departmentwise for teacher
- {
- if(head==NULL)
- {
- return;
- }
- displayd(head->left,s);
- if(strcmp(head->dept,s)==0)
- {
- printf("\nName Of the Department:%s\n",head->dept);
- printf("Teacher's Name:%s\n",head->name);
- printf("Teacher's ID:%s\n",head->id);
- printf("Phone No:%s\n",head->phone);
- printf("Designation:%s\n\n",head->designation);
- ft=1;
- }
- displayd(head->right,s);
- return;
- }
- void display()
- {
- printf("\n1.Display Teacher Information\n");
- printf("2.Display Student Information\n");
- printf("3.display Staff Information\n");
- printf("4.Menu\n");
- printf("5.Exit\n");
- int x;
- printf("Choose Any One:");
- scanf("%d",&x);
- switch(x)
- {
- case 1:
- {
- printf("\n1.Display All Teacher Information\n");
- printf("2.Display Department Teacher Information\n");
- int d;
- printf("Choose One:");
- scanf("%d",&d);
- {
- if(d==1)
- {
- if(root_teacher==NULL)
- {
- printf("\nNo Teacher Information Available!!\n");
- }
- else
- {
- displayt(root_teacher);
- }
- }
- else if(d==2)
- {
- if(root_teacher==NULL)
- {
- printf("\nNo Teacher Information Available!!\n");
- }
- else
- { printf("Enter Department:");
- char temp[70];
- scanf(" %[^\n]",temp);
- displayd(root_teacher,temp);
- if(ft==0)
- {
- printf("\nNo Information Available!!\n");
- }
- else
- {
- ft=0;
- }
- }
- }
- else
- {
- printf("Choose Correct Option!!!\a");
- display();
- }
- }
- printf("\n1.Back\n");
- printf("\n2.Menu\n");
- int y;
- printf("Choose any One:");
- scanf("%d",&y);
- if(y==1)
- {
- display();
- }
- else
- {
- menu();
- }
- }
- case 2:
- {
- printf("\n1.Display All Student Information\n");
- printf("2.Display Same Batch Student\n");
- printf("3.Display Same Batch And Same Department Student\n");
- printf("Choose One:");
- int s;
- scanf("%d",&s);
- if(root_student==NULL)
- {
- printf("\nNo Student Information available!!!\n");
- }
- else if(s==1)
- {
- displays(root_student); //displays=display student.
- }
- else if(s==2)
- {
- printf("Enter Student Batch:");
- int batch;
- scanf("%d",&batch);
- displayb(root_student,batch);
- if(fs==0)
- {
- printf("\nNo Student Information Available!!\n\n");
- }
- else
- {
- fs=0;
- }
- }
- else if(s==3)
- {
- printf("Enter Department:");
- char d[70];
- int batch;
- scanf(" %[^\n]",d);
- printf("Enter the Batch:");
- scanf("%d",&batch);
- displaydb(root_student,batch,d);
- if(fds==0)
- {
- printf("\nNo Information Available!!!\n\n");
- }
- else
- {
- fds=0;
- }
- }
- else
- {
- printf("Please Choose Correct option!!!\a");
- display();
- }
- printf("\n1.Back\n");
- printf("\n2.Menu\n");
- int y;
- printf("Choose any One:");
- scanf("%d",&y);
- if(y==1)
- {
- display();
- }
- else
- {
- menu();
- }
- }
- case 3:
- {
- if(root_staff==NULL)
- {
- printf("\nNo Staff Information Available\n\n");
- }
- displayst(root_staff); //displayst=display staff information
- printf("\n1.Back\n");
- printf("\n2.Menu\n");
- int y;
- printf("Choose any One:");
- scanf("%d",&y);
- if(y==1)
- {
- display();
- }
- else
- {
- menu();
- }
- }
- case 4:
- {
- menu();
- }
- case 5:
- {
- exit(0);
- break;
- }
- default:
- {
- printf("Choose Correct Option:");
- display();
- }
- }
- }
- void addcr() //for CR
- {
- node *newnode=(node*)malloc(sizeof(node));
- newnode->left=NULL;
- newnode->right=NULL;
- printf("Name Of the Department:");
- scanf(" %[^\n]",newnode->dept);
- printf("Student Name:");
- scanf(" %[^\n]",newnode->name);
- printf("Student ID:");
- scanf(" %s",newnode->id);
- printf("Section:");
- scanf(" %s",newnode->sec);
- printf("Phone No:");
- scanf(" %[^\n]",newnode->phone);
- printf("Batch:");
- scanf(" %d",&newnode->batch);
- printf("Blood Group:");
- scanf(" %s",newnode->blood);
- if(root_cr==NULL)
- {
- root_cr=newnode;
- }
- else
- {
- bst(root_cr,newnode); //bst=binary search tree
- }
- printf("\n\n1.back\n");
- printf("2.menu\n");
- printf("Choose Any One:");
- int x;
- scanf("%d",&x);
- if(x==1)
- {
- add();
- }
- else if(x==2)
- {
- menu();
- }
- else
- {
- printf("Please Choose Correct Option!!\n\n");
- menu();
- }
- }
- void adds() // for student
- {
- node *newnode=(node*)malloc(sizeof(node));
- newnode->left=NULL;
- newnode->right=NULL;
- printf("Name Of the Department:");
- scanf(" %[^\n]",newnode->dept);
- printf("Student Name:");
- scanf(" %[^\n]",newnode->name);
- printf("Student ID:");
- scanf(" %s",newnode->id);
- printf("Section:");
- scanf(" %s",newnode->sec);
- printf("Phone No:");
- scanf(" %[^\n]",newnode->phone);
- printf("Batch:");
- scanf("%d",&newnode->batch);
- printf("Blood Group:");
- scanf(" %s",newnode->blood);
- if(root_student==NULL)
- {
- root_student=newnode;
- }
- else
- {
- bst(root_student,newnode); //bst=binary search tree
- }
- printf("\n\n1.back\n");
- printf("2.menu\n");
- printf("Choose Any One:");
- int x;
- scanf("%d",&x);
- if(x==1)
- {
- add();
- }
- else if(x==2)
- {
- menu();
- }
- else
- {
- printf("Please Choose Correct Option!!\n\n");
- menu();
- }
- }
- void addst() //for staff information
- {
- node *newnode=(node*)malloc(sizeof(node));
- newnode->left=NULL;
- newnode->right=NULL;
- printf("Staff Name:");
- scanf(" %[^\n]",newnode->name);
- printf("Staff ID:");
- scanf(" %s",newnode->id);
- printf("Phone No:");
- scanf(" %[^\n]",newnode->phone);
- printf("Designation:");
- scanf(" %[^\n]",newnode->designation);
- printf("Blood Group:");
- scanf(" %s",newnode->blood);
- if(root_staff==NULL)
- {
- root_staff=newnode;
- }
- else
- {
- bst(root_staff,newnode); //bst=binary search tree
- }
- printf("\n\n1.back\n");
- printf("2.menu\n");
- printf("Choose Any One:");
- int x;
- scanf("%d",&x);
- if(x==1)
- {
- add();
- }
- else if(x==2)
- {
- menu();
- }
- else
- {
- printf("Please Choose Correct Option!!\n\n");
- menu();
- }
- }
- void addt()
- { node *newnode=(node*)malloc(sizeof(node));
- newnode->left=NULL;
- newnode->right=NULL;
- printf("Name Of the Department:");
- scanf(" %[^\n]",newnode->dept);
- printf("Teacher's Name:");
- scanf(" %[^\n]",newnode->name);
- printf("Teacher's ID:");
- scanf(" %s",newnode->id);
- printf("Phone No:");
- scanf(" %[^\n]",newnode->phone);
- printf("Designation:");
- scanf(" %[^\n]",newnode->designation);
- if(root_teacher==NULL)
- {
- root_teacher=newnode;
- }
- else
- {
- bst(root_teacher,newnode); //bst=binary search tree
- }
- printf("\n\n1.back\n");
- printf("2.menu\n");
- printf("Choose Any One:");
- int x;
- scanf("%d",&x);
- if(x==1)
- {
- add();
- }
- else if(x==2)
- {
- menu();
- }
- else
- {
- printf("Please Choose Correct Option!!\n\n");
- menu();
- }
- }
- void add()
- {
- printf("\n1.ADD TEACHER INFORMAION\n");
- printf("2.ADD STUDENT INFORMATION\n");
- printf("3.ADD STAFF INFORMATION\n");
- printf("4.ADD CR INFORMATION\n");
- printf("5.MENU\n");
- printf("6.Exit\n");
- int x;
- printf("\nChoose Any One:");;
- scanf("%d",&x);
- switch(x)
- {
- case 1:
- {
- addt(); //addt()=add teacher information
- break;
- }
- case 2:
- {
- adds(); //adds()=add student information
- break;
- }
- case 3:
- {
- addst(); //addst=add staff information
- break;
- }
- case 4:
- {
- addcr(); //addcr=add cr information
- break;
- }
- case 5:
- {
- menu();
- }
- case 6:
- {
- exit(0);
- break;
- }
- default:
- {
- printf("\nPlease choose Correct Option!!\a\n ");
- add();
- }
- }
- return;
- }
- void menu()
- {
- printf("\n 1.ADD INFORMATION");
- printf(" 2.SEARCH INFORMATION");
- printf("\n 3.DELETE INFORMATION");
- printf("\n 4.DISPLAY INFORMATION");
- printf(" 5.EXIT");
- int x;
- printf("\nChoose Any One:");
- scanf("%d",&x);
- switch(x)
- {
- case 1:
- {
- add();
- break;
- }
- case 2:
- {
- search();
- break;
- }
- case 3:
- {
- Delete();
- break;
- }
- case 4:
- {
- display();
- menu();
- break;
- }
- case 5:
- {
- exit(0);
- break;
- }
- default:
- {
- printf("\nPlease Choose Correct Option!!\a\n");
- menu();
- }
- }
- }
- int main()
- {
- printf(" WELCOME TO FACULTY OF SCIENCE AND INFORMATION TECHNOLOGY\n");
- printf(" ___________________________________________________________\n\n");
- menu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement