I have to make a library system program that can buy and sell books. The library
ID: 3534180 • Letter: I
Question
I have to make a library system program that can buy and sell books. The library store has the list of the inventory and the program user can look at them and order the books they want.
In doing the program, I will need to use:
1. Book Structure: Title, Author, ISBN, Price, and Available copies
struct Book
{string title, author, ISBN;
etc.
};
2. Also at the beginning, I will need to prompt the user the file name containing the data for the filename that hold the book list
bool Prompt (ifstream& fin)
{
string File_name;
cout << "enter the filename holds book collection: ";
cin >> File_name;
fin.open(File_name.c_str()) ;
if (fin.fail())
{
cout <<"Bad input";
return false;
}
else
{return true;}
}
3. If file is read succesfuly, display this menu with the following options:
a) Buy a book
b) Return a book
c) Request to replace a book
d) Display availability
e) Print alphabetically sorted book list (based on Title)
f) Print the details of a book (Prompt user for the title)
g) Print titles of books by an author(prompt user for author
Explanation / Answer
#include<iostream.h>
#include<fstream.h>
struct lib
{
char name[30],aut[30];
int ISBN,cop;
float price;
};
void main()
{
fstream.file;
file.open("lib.txt");
lib l,temp;
char n[30]ch;
cout<<"enter book name to found";
cin>>n;
while (file!=eof)
{
l=file.read((*ch)&l,sizeof(l));
if(l.name=n)
{
cout<<"a)Buy a book
b) Return a book
c) Request to replace a book
d) Display availability
e) Print alphabetically sorted book list (based on Title)
f) Print the details of a book (Prompt user for the title)
g) Print titles of books by an author(prompt user for author