/* C PROGRAM FOR BOOK SEARCHING AND SORTING*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void newentry();
void sort();
void search();
void list();
struct books
{
char
authname[50];
char
title[50];
}b[10];
int c=1;
void main()
{
int k,i,ch,n;
char w[30];
clrscr();
printf("\n\t\t\tBOOK
OPERATION\n");
printf("\n\t\t\t--------------\n");
printf("\nEnter
how many book you want to enter:");
scanf("%d",&n);
for(i=0;i<n;i++)
newentry();
while(1)
{
clrscr();
printf("\nMain Menu");
printf("\n1.Newentry\n");
printf("\n2.Search");
printf("\n3.Sort");
printf("\n4.List");
printf("\n5.Exit\n");
printf("\nEnter
your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
newentry();
break;
case 2:
search();
break;
case 3:
sort();
break;
case 4:
list();
break;
case 5:
exit();
break;
}
}
}
void search()
{
char tit[44],w[22],d,authname[44];
int i,a=0,z;
clrscr();
gets(w);
printf("\nDo you want to search using author
name(Y/N)!");
scanf("%c",&d);
if(d=='y'||d=='n')
{
gets(w);
printf("\nEnter any author name you want to
search:");
gets(authname);
for(i=0;i<=c;i++)
{
z=strcmp(authname,b[i].authname);
if(z==0)
{
printf("\n\nThe book have been found");
printf("\n\nThe book title is %s",
b[i].title);
printf("\n\nThe book author name is :
%s",b[i].authname);
a=1;
}
}
if(a==0)
printf("\n\nThe book was not found:");
}
getch();
}
void sort()
{
char temp[50],t_tit[44][44];
int i,j,z;
clrscr();
printf("\nThe Sorted book are");
for(i=0;i<=c;i++)
strcpy(t_tit[i],b[i].title);
for(i=0;i<=c;i++)
{
for(j=0;j<=c;j++)
{
z=strcmp(t_tit[i],t_tit[j]);
if(z>0)
{
strcpy(temp,t_tit[i]);
strcpy(t_tit[i],t_tit[j]);
strcpy(t_tit[j],temp);
}
}
}
for(i=0;i<=c;i++)
printf("%s\n",t_tit[i]);
getch();
}
void newentry()
{
char titles[20],author[50],was[22];
clrscr();
gets(was);
c++;
printf("Enter any author:");
gets(b[c].authname);
printf("Enter any title:");
gets(b[c].title);
printf("%s",b[c].title);
printf("\n%s",b[c].authname);
printf("\n%s",b[c].authname);
getch();
}
void list()
{
int i;
clrscr();
printf("AUTHOR NAME \t\tTITLES");
for(i=0;i<=c;i++)
printf("\n\n%s\t\t%s",b[i].authname,b[i].title);
getch();
}
OUTPUT
BOOK OPERATION
Enter how many
book you want to enter: 2
Enter any
author: R.Balaguruswamy
Enter any title:
Programming in C
Programming in C
R.Balaguruswamy
Enter any
author: Morris Mano
Enter any title:
Computer System Architecture
Computer System
Architecture
Morris Mano
Main Menu
1. New entry
2. Search
3. Sort
4. List
5. Exit
Enter your
choice: 1
Enter any
author: Problem Solving Techniques
Enter any
title: R.G.Dromey
Problem Solving
Techniques
R.G.Dromey
Main Menu
1. New entry
2. Search
3. Sort
4. List
5. Exit
Enter your
choice: 2
Do you want to
search using author name(Y/N)! Y
Enter any author
name you want to search: R.Balaguruswamy
The book have
been found
The book title
is Programming in C
The book author
name is: R.Balaguruswamy
Main Menu
1. New entry
2. Search
3. Sort
4. List
5. Exit
Enter your
choice: 2
Do you want to
search using author name(Y/N)! Y
Enter any author
name you want to search: Richard hall
The book was not
found
Main Menu
1. New entry
2. Search
3. Sort
4. List
5. Exit
Enter your
choice: 3
The Sorted books
are
Programming in C
Problem Solving
Techniques
Computer System
Architecture
Main Menu
1. New entry
2. Search
3. Sort
4. List
5. Exit
Enter your
choice: 4
AUTHOR NAME TITLES
---------------------- ----------
R.Balaguruswamy Programming in C
Morris Mano Computer System
Architecture
R.G.Dromey Problem Solving
Techniques
Main Menu
1. New entry
2. Search
3. Sort
4. List
5. Exit
Enter your
choice: 5
0 comments:
Post a Comment