Wednesday, 19 October 2011

"C program for Student Database from linked list"

/*PROBLEM DEFINATION : Implement the Mini Project of Student Database using Linked list for following requirements:
    a. Creation of Student Database in memory containing student ID, Name, Name
        Initials, Address, Contact No and Date of Birth .
    b. Insertion, Deletion, Modification of student record for a given student ID.
    c. Sorting on name initials and searching a particular student record on name initials
  */

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<dos.h>

struct stud
{
 int rn,id,ph;
 char add[30],na[20],d[15],in[5];
 struct stud *next;
}*h=NULL,*p,*q,*t;

void add()
{
  clrscr();
  p =(stud *)malloc(sizeof(stud));
  printf("\nEnter the Initials of Student : ");
  scanf("%s",&p->in);
  printf("\nEnter the Last Name of Student : ");
  scanf("%s",&p->na);
  printf("\nEnter the ID of Student : ");
  scanf("%d",&p->id);
  printf("\nEnter the Roll No. of Student : ");
  scanf("%d",&p->rn);
  printf("\nEnter the Ph No. of Student : ");
  scanf("%d",&p->ph);
  printf("\nEnter the Address of Student : ");
  scanf("%s",&p->add);
  printf("\nEnter the D.O.B. of Student(dd/mm/yyyy) : ");
  scanf("%s",&p->d);

  p->next=NULL;

  if(h==NULL)
  {
   h=p;
  }
  else
  {
    q=h;
    while(q->next!=NULL)
    q=q->next;
    q->next=p;
  }
  ts++;
}

void addAt(int r)
{
 q=h;
 while(q->rn!=r || q==NULL)
  q=q->next;
 if(q->rn==r)
 {
  clrscr();
  p =(stud *)malloc(sizeof(stud));
  printf("\nEnter the Initials of Student : ");
  scanf("%s",&p->in);
  printf("\nEnter the Last Name of Student : ");
  scanf("%s",&p->na);
  printf("\nEnter the ID of Student : ");
  scanf("%d",&p->id);
  printf("\nEnter the Roll No. of Student : ");
  scanf("%d",&p->rn);
  printf("\nEnter the Ph No. of Student : ");
  scanf("%d",&p->ph);
  printf("\nEnter the Address of Student : ");
  scanf("%s",&p->add);
  printf("\nEnter the D.O.B. of Student(dd/mm/yyyy) : ");
  scanf("%s",&p->d);
  p->next=q->next;
  q->next=p;
  ts++;
 }
 else
 {
  printf("\n\nRecord Not Found.");
 }
}


void delAt(int r)
{
 q=h;
 while((q->next)->rn!=r || q==NULL)
  q=q->next;
 if((q->next)->rn==r)
 {
  q->next=(q->next)->next;
  printf("\n\nRecord Deleted.");
  ts--;
 }
 else
  printf("\n\nRecord Not Found.");
}

void modAt(int id)
{
 q=h;
 int ch;
 while(q->id!=id && q!=NULL)
  q=q->next;
 if(q->id==id)
 {
  clrscr();
  printf("******* MODIFY *******\n1.Name Initials\n2.Last Name");
  printf("\n3.Roll No.\n4.Phone\n5.Add\n6.D.O.B.:\nEnter choice: ");
  scanf("%d",&ch);
  switch(ch)
  {
  case 1 :  printf("\n\nEnter the Initials of Student : ");
          scanf("%s",&q->in);break;
  case 2 :  printf("\nEnter the Last Name of Student : ");
          scanf("%s",&q->na);break;
  case 3 :  printf("\nEnter the Roll No. of Student : ");
          scanf("%d",&q->rn);break;
  case 4 :  printf("\nEnter the Ph No. of Student : ");
          scanf("%d",&q->ph);break;
  case 5 :  printf("\nEnter the Address of Student : ");
          scanf("%s",&q->add);break;
  case 6 :  printf("\nEnter the D.O.B. of Student(dd/mm/yyyy) : ");
          scanf("%s",&q->d);break;
  }
 }
 else
  printf("\nRecord not Found.");
}

void search(char ni[5])
{
 int flag=0;
 q=h;
 clrscr();
 while(q!=NULL)
 {
  if(stricmp(q->in,ni)==0)
  {
  flag=1;
  printf("\n\nInitals of Student :   %s ",q->in);
  printf("\n\nLast Name of Student : %s ",q->na);
  printf("\n\nID of Student :        %d ",q->id);
  printf("\n\nRoll No. of Student :  %d",q->rn);
  printf("\n\nPh No. of Student :    %d",q->ph);
  printf("\n\nAddress of Student :   %s",q->add);
  printf("\n\nD.O.B. of Student :    %s",q->d);
  printf("\n\n\n");
  }
  q=q->next;
 }
 if(flag==0)
  printf("\n\nNo Match Found.");
}

void sort()
{
 p=h;
 while(p!=NULL)
 {
  q=h;
  while(q!=NULL)
  {
   if(stricmp(q->in,(q->next)->in)>0)
   {
    strcpy(t->in,q->in);
    strcpy(t->na,q->na);
    t->id=q->id;
    t->rn=q->rn;
    t->ph=q->ph;
    strcpy(t->add,q->add);
    strcpy(t->d,q->d);


    strcpy(q->in,(q->next)->in);
    strcpy(q->na,(q->next)->na);
    q->id=  (q->next)->id;
    q->rn=  (q->next)->rn;
    q->ph=  (q->next)->ph;
    strcpy(q->add,(q->next)->add);
    strcpy(q->d,(q->next)->d);

    strcpy((q->next)->in,t->in);
    strcpy((q->next)->na,t->na);
    (q->next)->id = t->id;
    (q->next)->rn = t->rn;
    (q->next)->ph = t->ph;
    strcpy((q->next)->add,t->add);
    strcpy((q->next)->d,t->d);

   }
   q=q->next;
  }
  p=p->next;
 }

}

void disp()
{
 p=h;
 clrscr();
 while(p!=NULL)
 {
  printf("\nInitals of Student :   %s ",p->in);
  printf("\nName of Student :      %s ",p->na);
  printf("\nID of Student :        %d ",p->id);
  printf("\nRoll No. of Student :  %d",p->rn);
  printf("\nPh No. of Student :    %d",p->ph);
  printf("\nAddress of Student :   %s",p->add);
  printf("\nD.O.B. of Student :    %s",p->d);
  printf("\n\n");
  p=p->next;
 }
}

void main()
{
 int ch=0,r;
 char ni[5];
 clrscr();
 while(ch!=8)
 {
  clrscr();
  printf("1.Add the Record.\n\n2.Add Record at Locn.\n\n3.Delete Record.");
  printf("\n\n4.Modify Record.\n\n5.Search Record.\n\n6.Sort Records.");
  printf("\n\n7.Display\n\n8.Exit");
  printf("\n\nEnter the Choice: ");
  scanf("%d",&ch);
   switch(ch)
   {
    case 1:
    add();
    break;

    case 2:
    printf("\nEnter the Roll No. : ");
    scanf("%d",&r);
    addAt(r);
    break;

    case 3:
    printf("\nEnter the Roll No. : ");
    scanf("%d",&r);
    delAt(r);
    break;

    case 4:
    printf("\nEnter the ID : ");
    scanf("%d",&r);
    modAt(r);
    break;

    case 5:
    printf("\nEnter the Initials : ");
    scanf("%s",&ni);
    search(ni);
    break;

    case 6:
    sort();
    printf("\n\nSorted");
    break;
    case 7:
    disp();
    break;
   }
 getch();
 }
 getch();
}
*/
OUTPUT :
==========

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 1
Enter the Initials of Student : T.T.
Enter the Last Name of Student : MOJAD
Enter the ID of Student : 001
Enter the Roll No. of Student : 1
Enter the Ph No. of Student : 1234
Enter the Address of Student : qwer
Enter the D.O.B. of Student(dd/mm/yyyy) :10/12/1988

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 7
Initals of Student :   T.T.
Name of Student :      MOJAD
ID of Student :        1
Roll No. of Student :  1
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1988

Initals of Student :   A.M.
Name of Student :      Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    12345
Address of Student :   abde
D.O.B. of Student :    10/12/1990

Initals of Student :   S.M.
Name of Student :      Mane
ID of Student :        3
Roll No. of Student :  3
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    12/12/1989

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 2
Enter the Roll No. : 2
Enter the Initials of Student : Z.Z.
Enter the Last Name of Student : Shaikh
Enter the ID of Student : 005
Enter the Roll No. of Student : 4
Enter the Ph No. of Student : 1234
Enter the Address of Student : qwer
Enter the D.O.B. of Student(dd/mm/yyyy) : 14/3/1991

Initals of Student :   T.T.
Name of Student :      MOJAD
ID of Student :        1
Roll No. of Student :  1
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1988

Initals of Student :   A.M.
Name of Student :      Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1990

Initals of Student :   Z.Z.
Name of Student :      Shaikh
ID of Student :        5
Roll No. of Student :  4
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :   14/3/1991

Initals of Student :   S.M.
Name of Student :      Mane
ID of Student :        3
Roll No. of Student :  3
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    12/12/1989

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 5
Enter the Initials : a.m.

Initals of Student :   A.M.
Last Name of Student : Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1990

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 4
Enter the ID : 001

******* MODIFY *******
1.Name Initials
2.Last Name
3.Roll No.
4.Phone
5.Add
6.D.O.B.:
Enter choice: 1

Enter the Initials of Student : T.D.

Initals of Student :   T.D.
Name of Student :      MOJAD
ID of Student :        1
Roll No. of Student :  1
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1988

Initals of Student :   A.M.
Name of Student :      Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1990

Initals of Student :   Z.Z.
Name of Student :      Shaikh
ID of Student :        5
Roll No. of Student :  4
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    14/3/1991

Initals of Student :   S.M.
Name of Student :      Mane
ID of Student :        3
Roll No. of Student :  3
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    12/12/1989

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 6
Sorted
Initals of Student :   A.M.
Name of Student :      Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1990

Initals of Student :   S.M.
Name of Student :      Mane
ID of Student :        3
Roll No. of Student :  3
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    12/12/1989

Initals of Student :   T.D.
Name of Student :      MOJAD
ID of Student :        1
Roll No. of Student :  1
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1988

Initals of Student :   Z.Z.
Name of Student :      Shaikh
ID of Student :        5
Roll No. of Student :  4
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    14/3/1991
*/

4 comments:

Few Linux App & commands which is going to used to Build AOSP(Android Open Source Project) Source Code

1. sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32n...