Wednesday, 18 May 2016

Write a C program which will take student info such as name, roll no., department as input and store in a structure student_details. Store information about the students library details which includes roll no. and book_id in a structure library_details. The program will be able to calculate the total number of books issued to the student of a particular department.

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <conio.h>
typedef struct student_detail{
    int roll;
    int department;
    struct student_detail *next;
}student;

typedef struct library_detail {
    int roll;
    int book_id;
    struct library_detail *next;
}library;

void print_info(){

    printf("1 . Enter Student Detail.\n");
    printf("2 . Issue Book.\n");
    printf("3 . Count Book Issued to a department.\n");
    printf("4 . Exit.\n");

}

int main()
{
    int choice=0;
    int roll,dept,book_id,bi;
    student *sstart=NULL,*stmp,*sn;
    library *lstart=NULL,*ltmp,*ln;
  //  int c=0,l=0;
    clrscr();
    print_info();

    while(choice!=4){
printf("\nEnter Your Choice : ");
scanf("%d",&choice);
   /* c=0,l=0;

stmp=sstart;
ltmp=lstart;
while(stmp!=NULL){
   c++;
   stmp=stmp->next;
}
while(ltmp!=NULL){
   l++;
   ltmp=ltmp->next;
}

printf("\n Total Entry of student and libray: %d %d\n",c,l);
    */
switch(choice){
   case 1: printf("Enter Roll and department no : ");
   scanf("%d %d",&roll,&dept);
    stmp=(student *) malloc(sizeof(student));
    stmp->roll=roll;
    stmp->department=dept;
    stmp->next=NULL;

    if(sstart==NULL)
    sstart=stmp;
    else
    {
sn=sstart;
while(sn->next!=NULL)
sn=sn->next;
sn->next=stmp;

    }
   break;
   case 2: printf("Enter Roll and book id : ");
   scanf("%d %d",&roll,&book_id);
    ltmp=(library *) malloc(sizeof(library));
    ltmp->roll=roll;
    ltmp->book_id=book_id;
    ltmp->next=NULL;


   if(lstart==NULL)
    lstart=ltmp;
    else
    {
ln=lstart;
while(ln->next!=NULL)
ln=ln->next;
ln->next=ltmp;

    }
   break;
   case 3:
   printf("Enter Department No: ");
   scanf("%d",&dept);
   bi=0;
   ln=lstart;
   while(ln!=NULL){
      roll=ln->roll;
      sn=sstart;
      while(sn!=NULL){
if(sn->roll==roll && sn->department==dept){
bi++;
break;
}
sn=sn->next;

      }
      ln=ln->next;
   }
   printf("Total Issued Book to dept id %d is %d \n.",dept,bi);
break;
   default: printf("Wrong Input!!\n\n");
    print_info();
     break;
}
}

    return 0;
}



No comments:

Post a Comment