Software for Big Bang Book Store
Hi,
Problem Statement:
Quote:
A book store maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether its available or not.
Design a system using a class called books with suitable member functions and constructors. Use new operator in constructors to allocate memory space required.
The salesman should be able to add new books to the database.
Code:
Code:
#include <iostream>
using namespace std;
int bookcount;
books *pointer;
void menu(void);
class books
{
private:
string title;
string author;
float price;
int stock;
public:
books(string ltitle,string lauthor,float lprice,int lstock)
{
title=ltitle;
author=lauthor;
price=lprice;
stock=lstock;
}
search(string ltitle)
{
//Search Algorithm goes here
if(found)
{
sell(ltitle);
}
else
{
cout<<"Book not found";
}
}
sell(string ltitle)
{
cout<<"\nBook name:"<<ltitle;
cout<<"\nPrice:"<<price;
cout<<"\nStock:"<<stock;
cout<<"\nEnter no. of copies to buy";
int num;
cin>>num;
if(num<=stock)
{
stock-=num;
cout<<"\nSold!";
}
else
{
cout<<"\nnot available";
}
}
};
int main()
{
int choice=1;
string ltitle;
string lauthor;
float lprice;
int lstock;
menu();
while(choice!=3)
{
cout<<"\nEnter Your choice:";
cin>>choice;
if(choice==1)
{
cout<<"\nEnter name of the book:";
cin>>ltitle;
search(ltitle);
}
if(choice==2)
{
cout<<"\nEnter name of book:";
cin>>ltitle;
cout<<"\nAuthor";
cin>>lauthor;
cout<<"\nPrice:";
cin>>lprice;
cout<<"\nStock:";
cin>>lstock;
pointer=new books(string ltitle,string lauthor,float lprice,int lstock);
}
menu();
}
}
void menu(void)
{
cout<<endl<<"\t\t\tWelcome to Big Bang Book Store"<<endl;
cout<<"1) Buy a Book"<<endl;
cout<<"2)Add a book to database"<<endl;
cout<<"3)Exit"<<endl;
}
I am having trouble with making the search algorithm........and perhaps you all will find 50 other flaws in it.:p
Thanks for the help. :)