1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
struct BOOK
{
int Bno;
char Bname[20];
char Author[20];
float Price;
};
void EnterDetails(BOOK A[], int);
void DisplayDetails(BOOK A[], int);
void SearchByBno(BOOK A[], int);
void SearchByBname(BOOK A[], int);
void main()
{
clrscr();
int n;
BOOK B[20];
cout<<"Enter the number of different books you would be entering: ";
cin>>n;
cout<<endl<<endl;
EnterDetails(B,n);
DisplayDetails(B,n);
SearchByBno(B,n);
SearchByBname(B,n);
getch();
}
void EnterDetails(BOOK A[], int N)
{
for(int i=0; i<N; i++)
{
cout<<"Enter the details of book "<<i+1<<":\n\n";
cout<<"Enter book number: ";
cin>>A[i].Bno;
cout<<"Enter book name: ";
gets(A[i].Bname);
cout<<"Enter Author of the book: ";
gets(A[i].Author);
cout<<"Enter price of the book in $: ";
cin>>A[i].Price;
cout<<"\n\n";
}
cout<<"\n\n";
}
void DisplayDetails(BOOK A[], int N)
{
for(int i=0; i<N; i++)
{
cout<<"Details of book "<<i+1<<" "<<"are:\n\n";
{
cout<<"Book number: ";cout<<A[i].Bno<<"\n";
cout<<"Book name: ";cout<<A[i].Bname<<"\n";
cout<<"Author: ";cout<<A[i].Author<<"\n";
cout<<"Price: "<<A[i].Price<<"\n\n";
}
}
cout<<"\n\n";
}
void SearchByBno(BOOK A[], int N)
{
int a, found=0;
cout<<"Enter book number of the book you are looking for: ";
cin>>a;
for(int i=0; i<N, (!found);i++)
{
if(A[i].Bno==a)
found++;
}
if(!found)
cout<<"No book matches this book number.";
else if(found==1)
{
cout<<"The details of the book of book number \""<<a<<"\" are:\n\n";
cout<<"Name: "<<A[i].Bname<<"\n";
cout<<"Author: "<<A[i].Author<<"\n";
cout<<"Price: "<<A[i].Price<<"\n";
}
cout<<"\n\n";
}
void SearchByBname(BOOK A[], int N)
{
int found=0;
char Name[20];
cout<<"Enter the name of the book you are looking for: ";
gets(Name);
for(int i=0; i<N, (!found); i++)
{
if(!(strcmpi(A[i].Bname,Name)))
found++;
}
if(!found)
cout<<"The name of the book you entered is not present.";
else if(found==1)
{
cout<<"The details of the book of the name\""<<Name<<"\" are:\n\n";
cout<<"Book number: "<<A[i].Bno<<"\n";
cout<<"Author: "<<A[i].Author<<"\n";
cout<<"Price: "<<A[i].Price<<"\n";
}
}
|