hi
i want to :
1. view all the books
2. search for a book
i have managed to complete part of this . the code is as follow:
#include <iostream>
#include <fstream>
#include <assert.h>
#include <stdlib.h>
using namespace std;
const int BOOK_MAX = 5000 ;
const int USER_MAX = 1400;
struct User_D
{
char username [20];
int houseno[3];
char streetname [20];
double userno;
};
struct Book_D
{
int bookno,noc;
char authorsurname [20];
char bookname[50];
char authorforename [15];
char genre [1];
double booknumber;
public:
void showbook();
void showall();
int search3(char a[]);
int issue(char a[]);
int retrn(char a[]);
}L;
void Book_D::showall()
{ cout<<"\n"<<[BookD].authorsurname<<"\t\t"<<[BookD].authorforename<<"\t\t\t\t\t"<<[BookD].bookname<<"\t\t\t\t\t"<<[BookD].genre<<"\t"<<[Book\
D].booknumber<<"\n";
}
void Book_D::showbook()
{
cout<<"\nBook No. : "<<booknumber<<"\nTitle : "<<bookname<<"\nAuthor : "<<authorforename<<authorsurname<<"\nGenre:" <<genre;
}
int Book_D::search3(char name[])
{
int f=0;
if(strcmp(authorsurname,authorforename)==0)
{
showbook();
f=1;
}
else
f=0;
return f;
}
int Book_D::issue(char name1[])
{
int f=0;
if(strcmp(bookname,name1)==0) {
noc--;
showbook();
cout<<"\n!!BOOK ISSUED FROM LIBRARY!!";
f=1;
}
else f=0;
return f;
}
int Book_D::retrn(char name2[])
{
int f=0;
if(strcmp(bookname,name2)==0) {
noc++;
showbook();
cout<<"\n!!BOOK RETURNED TO LIBRARY!!";
f=1;
}
else f=0;
return f;
}
int main ()
{
int ans;
int i;
int n,tot,flag=0,ch1,ch2;
int a;
char nm[50];
char b[50],c[50],d[50];
char authorname;
char btitel;
cout<<"\n\t\t\t1.Show Entire Library"
<<"\n\t\t\t2.Search For a Book"
<<"\n\t\t\t3.Issue a Book"
<<"\n\t\t\t4.Return a Book"
<<"\n\t\t\t5.Exit"
<<"\n\n\t\t\t\tEnter Choice:\t";
cin >> ans;
switch(ans)
{
case'1':
ifstream ifile;
ifile.open("bookdata.dat");
if (!ifile)
{
cerr << "File not found\n" ;
exit (0);
}
Book_D hname[USER_MAX];
cout<<"\n"<<"FIRSTNAME"<<"\t\t"<<"SURNAME"<<"\t\t\t\t\t"<<"BOOKTITLE"<<"\t\t\t\t\t"<<"GENRE"<<"\t"<<"BOOK NO.\n";
for (int Book_D=0;Book_D<50;Book_D++)
{
for (int i=0; i<40;i++)
{
ifile.get(hname[Book_D].authorsurname[i]);
cout<<hname[Book_D].authorsurname[i];
}
}cout << "\n";
ifile.close();
break;
case2:
cout<<"\n\n\n\n\n\n\n\t\t\tEnter Author name:";
cin>> authorname;
ifstream ifile2;
ifile2.open("bookdata.dat");
ifile2.read((char*)&L,sizeof(L));
while(ifile2)
{
flag=L.search3(b);
if(flag==1)
{
ifile2.close();
break;
}
ifile2.read((char*)&L,sizeof(L));
}
if(flag==0) cout<<"\n\n\n\t\t\t!!NO BOOKS WRITTEN BY THIS AUTHOR!!";
ifile2.close();
break;
case3:
cout<<"\n\n\n\n\n\n\n\t\t\tEnter Title:";
cin>> btitle;
ifstream iofile;
iofile.open("bookdata.dat",ios::in|ios:ut,ios::binary);
iofile.read((char*)&L,sizeof(L));
while(iofile)
{
flag=L.issue(c);
if(flag==1)
{
iofile.seekp(iofile.tellg()-sizeof(L));
iofile.write((char*)&L,sizeof(L));
break;
}
iofile.read((char*)&L,sizeof(L));
}
if(flag==0) cout<<"\n!!NOT FOUND!!";
iofile.close();
break;
}
}
can you tell me what i am doing wrong? thank you.
:cry: