Pages

Monday, 5 March 2012

student details by using data structures

code:




//**********************************//
//student details-created by shakeer//
//**********************************//


#include<alloc.h>
#include<process.h>
struct student
{
  char name[15];
  int id;
  int age;
  int marks;

};
typedef struct student STD;
STD getdata()
{
  STD ts;
  start:
  printf("\nENTER NAME  :");
  flushall();
  gets(ts.name);
  printf("\nENTER ID    :");
  scanf("%d",&ts.id);
  printf("\nENTER AGE   :");
  scanf("%d",&ts.age);
  printf("\nENTER MARKS :");
  scanf("%d",&ts.marks);
  if(ts.marks>100 || ts.marks<0)
  {
  printf("\nINVALID MARKS.....");
  goto start;
  }
  return ts;
}
void showdata(STD ts)
{
  printf("\nSTUDENT NAME  :",ts.name);
  printf("\nSTUDENT ID    :",ts.id);
  printf("\nSTUDENT AGE   :",ts.age);
  printf("\nSTUDENT MARKS :",ts.marks);
}
struct link
{
  struct link *pre;
  STD data;
  struct link *next;
};
typedef struct link LINK;
LINK *head=NULL;
void create()
{
  LINK *th;
  char ch;
  if(head==NULL)
  {
    head=(LINK*)malloc(sizeof(LINK));
    head->pre=head;
    head->data=getdata();
    head->next=NULL;
    printf("\nDO YOU WANT TO ENTER ONE MORE Y/N:");
    flushall();
    ch=getchar();
    if(ch!='y'&& ch!='Y')
    return;
  }
  th=head->pre;
  do
  {
  th->next=(LINK*)malloc(sizeof(LINK));
  th=th->next;
  th->pre=head->pre;
  th->data=getdata();
  th->next=head;
  head->pre=th;
  printf("\nDO YOU WANT TO ENTER ONE MORE Y/N:");
  ch=getchar();
 }while(ch=='y'||ch=='Y');
}
void display()
{
  LINK *th;
  if(head==NULL)
  {
   printf("LIST EMTY:");
   return;
  }
  th=head->pre;
  do
  {
    showdata(th->data);
    th=th->pre;
  }while(th!=head->pre);
}
int noofstd()
{
  LINK *th;
  int no_std;
  if(head==NULL)
  {
  printf("LIST EMTY");
  return 0;
  }
  th=head;
  do
  {
    no_std++;
    th=th->next;
  }while(th!=head);
  return no_std;
}
void main()
{
  int flag;
  clrscr();
  while(1)
  {
    printf("\nFOR NEW STUDENT      1:");
    printf("\nFOR DISPLAY STUDENTS 2:");
    printf("\nFOR NO. OF STUDENTS  3:");
    printf("\nFOR EXIT ENTER ANY.....");
    scanf("%d",&flag);
    switch(flag)
    {
      case 1:create();
          break;
      case 2:display();
          break;
      case 3:noofstd();
          break;
      default:exit(1);
    }
  }
}

//contact me at sk.shakeer1990@gmail.com

0 comments:

Post a Comment