BOOKS DETAILS USING C STRUCTURE




             To write a c program to create a collection of books using array of structure and performs the following operatons.
(i)                 Searching a book with title and author name.
(ii)               Sort the book based on title.



/*BOOKS DETAILS*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct books
{
char book[20];
char author[20];
int price;
};
int main()
{
int i,ch,j,n,flag=1;
struct books l[10];
struct books t[1];
char sbook[20],saut[20];
clrscr();
do{
clrscr();
printf("\n\t\tBOOK LIST\n\nMAIN MENU\n\n");
printf("\n1.creation\n2.search by title & author\n");
printf("3.sort by title\n4.exit\n");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
clrscr();
printf("\nEnter number of booklist:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\nBOOK LIST:%d",i);
printf("\nBOOK NAME:");
scanf("%s",l[i].book);
printf("\nAUTHOR:");
scanf("%s",l[i].author);
printf("\nPRICE");
scanf("%d",&l[i].price);
}
printf("\nBOOK LIST:");
printf("\nBOOK NAME AUTHOR PRICE\n");
for(i=1;i<=n;i++)
{
printf("\n%s\t%s\t%d",l[i].book,l[i].author,l[i].price);
}
getch();
break;
case 2:
clrscr();
flag=1;
printf("\n\tsearching \n\tEnter the book name to be searched");
scanf("%s",sbook);
printf("\nAnd Enter the author to be searched");
scanf("%s",saut);
for(i=1;i<=n;i++)
{
if((strcmp(sbook,l[i].book)==0)&&(strcmp(saut,l[i].author)==0))
{
flag=0;
printf("\nBook is available !!!");
printf("\nBook Name Author price\n");
printf("\n%s\t%s\t%d",l[i].book,l[i].author,l[i].price);
getch();
break;
}
}
if(flag==1)
{
printf("\nBook is not available!!!");
getch();
break;
}
break;
case 3:
clrscr();
printf("\n\t\tBOOK LIST\n\n");
printf("\nSorted book list\nBook Name author price\n");
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(l[i].book,l[j].book)>=1)
{
t[i]=l[i];
l[i]=l[j];
l[j]=t[i];
}
}
printf("\n%s\t%s\t%d",l[i].book,l[i].author,l[i].price);
}
getch();
break;
case 4:
printf("\nExited!!!");
exit();
break;
}
}
while(ch!=4);
getch();
}





Comments

Popular posts from this blog

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE