Friday, 22 June 2012

write a c program to accept book details of n books as boo_title, author,publisher,and cost assign accession number to each book in increasing order


/*write a c program to accept book details of n books as boo_title,
author,publisher,and cost assign accession number to each book in increasing
order display these details as
1: book of a specified author
2: book of specied publisher
3: all book costing  rs.500 and above
4: all books
*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void set_book(int);
void book_author(int);
void book_pub_name(int) ;
void book_300(int);
void all_book(int);
struct book
{
char bname[20];
char author[20];
char pub_name[20];
int cost;
int acc_no;
};
struct book b[10];
void main()
{
int n;
clrscr();
printf("\nenter how many number :");
scanf("%d",&n);
set_book(n);
book_author(n);
book_pub_name(n);
book_300(n);
all_book(n);
getch();
}
void set_book(int n)
{
int i;
for(i=0;i<n;i++)
{
printf("enter the accession number");
scanf("%d",&b[i].acc_no);
printf("\nenter book name :");
flushall();
scanf("%s",&b[i].bname);
printf("\nenter author name :");
flushall();
scanf("%s",&b[i].author);
printf("\nenter publisher name :");
flushall();
scanf("%s",&b[i].pub_name);
printf("\nenter the cost :");
scanf("%d",&b[i].cost);
}
}
void book_author(int n)
{
int i,count=0;
char a[20];
printf("\nenter the name which you want to search :");
scanf("%s",&a);
printf("\nbookname\n");
for(i=0;i<n;i++)
{
if(strcmp(a,b[i].author)==0)
{
count++;
printf("%s\n",b[i].bname);
}
}
if(count==0)
printf("\nno such book");
}
void book_pub_name(int n)
{
int i;
char a[20],count=0;
printf("\nenter the publisher name:");
scanf("%s",&a);
printf("\nbook name\n");
for(i=0;i<n;i++)
{
if(strcmp(a,b[i].pub_name)==0)
{
printf("%s\n",b[i].bname);
count++;
}
}
if(count==0)
printf("\nno such book");
}
void book_300(int n)
{
int i,count=0;
printf("\nthe book whose cost is 500 and above :");
printf("\nbook name\n");
for(i=0;i<n;i++)
{
if(b[i].cost>=500)
{
printf("%s\n",b[i].bname);
count++;
}
}
if(count==0)
printf("\nno such book");
}
void all_book(int n)
{
int i;
printf("\naccno\tbook name\tauthor name\tpublisher name\tcost\n");
for(i=0;i<n;i++)
{
printf("%d\t%s\t\t%s\t\t%s\t\t%d\n",b[i].acc_no,b[i].bname,b[i].author,b[i].
pub_name,b[i].cost);
}
}

/*enter how many number :3
enter the accession number1                                                    
                                                                               
enter book name :fsg                                                          
                                                                               
enter author name :peer                                                        
                                                                               
enter publisher name :vision                                                  
                                                                               
enter the cost :550                                                            
enter the accession number2                                                    
                                                                               
enter book name :pom                                                          
                                                                               
enter author name :santosh                                                    
                                                                               
enter publisher name :vision                                                  
                                                                               
enter the cost :300                                                            
enter the accession number3                                                    

enter book name :khgkg

enter author name :mama

enter publisher name :ndaa

enter the cost :600

enter the name which you want to search :peer

bookname
fsg

enter the publisher name:vision

book name
fsg
pom

the book whose cost is 500 and above :
book name
fsg
khgkg

accno   book name       author name     publisher name  cost
1       fsg             peer            vision          550
2       pom             santosh         vision          300
3       khgkg           mama            ndaa            600
 */

No comments: