Write a program that maintains a list of books in stock for Wildcat bookstore. T
ID: 3686217 • Letter: W
Question
Write a program that maintains a list of books in stock for Wildcat bookstore. The program should repeatedly print a menu of options to allow a user to select from the following operations, until the user decides to exit. Insert a book record Delete a book record Print the book list Search the book list Quit. Each book record in the list consists of book title (string), number of copies in stock (int), and price (double). The book list should be maintained in the lexicographical order (also called dictionary order) of the book titles. Option 1 should read a book record (title, quantity, and price) from the user and insert the record into the current book list. Option 2 should ask the user for a book title and delete the record that exactly matches the title from the book list. If no such book exists, then report the book is not in stock and do nothing. Option 3 should display all the books in stock, in the lexicographical order of the book titles. Option 4 should allow the user to type a search key (a string), then search all the books in stock and display all matched books which contain the key as the substring of the book titles. For example, if the search key is "Computer", the book title of "Introduction to Computer Science" matches, but the book title of "Great Principles of Computing" does not match. If one or more matched book titles have been found, display the book records in lexicographical order otherwise, report no such book is in stock. Option 5 should quit the program. To make it simple, for this program, assume the book title is case sensitive, (e.g., "computer networks" and "Computer networks" are considered as two different books) Complete the class definition of the following two classes Book and Booklist and use them in your program. Note you can add other member functions to the class Book and/or the class Booklist, if you need them for your program, but you should not remove or modify either data members or member functions, from the following declarations.Explanation / Answer
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include<stdlib.h>
//using namespace std;
class book
{
char title[100];
int quantity;
double price;
friend class booklist;
};
class booklist
{
public:
void insert()
{
book obj1;
ofstream fout;
fout.open("bookstore.txt",ios::app);
cout<<" Enter book Title : ";
cin>>obj1.title;
cout<<" Enter book Quantity : ";
cin>>obj1.quantity;
cout<<" Enter book Price : ";
cin>>obj1.price;
fout<<obj1.title<<obj1.quantity<<obj1.price<<endl;
fout.close();
}
void del()
{
}
void list()
{
}
void search()
{
ifstream fin;
fin.open("bookstore.txt",ios::in);
char search_title[100],line[100];
cout<<" Enter book Title to search : ";
cin>>search_title;
while(!fin.eof())
{
getline(fin,line);
if(strcmp(search_title,line))
{
cout<<" Enter book Title : "<<obj1.title;
cout<<" Enter book Quantity : "<<obj1.quantity;
cout<<" Enter book Price : "<<obj1.price;
}
}
}
};
int main()
{
int ch;
do
{
cout<<" 1. Insert a book record";
cout<<" 2. Delete a book record";
cout<<" 3. Print book List";
cout<<" 4. Search a book record";
cout<<" 5. Exit";
cout<<" Please Enter choice : ";
cin>>ch ;
if(ch==1)
{
booklist obj;
obj.insert();
//cout<<" 1";
}
else if(ch==2)
{
booklist obj;
obj.del();
cout<<" 2";
}
else if(ch==3)
{
booklist obj;
obj.list();
cout<<" 3";
}
else if(ch==4)
{
booklist obj;
obj.search();
cout<<" 4";
}
else if(ch==5)
{
cout<<" !!!!!Exiting the Program!!!!!";
}
if(ch<0 || ch>5)
{
cout<<" ---Please Enter Correct choice---";
}
}while(ch!=5);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.