I am getting many errors highlighted in red. Hope you can help me get rid of them.
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;
}
void search(string ltitle)
{
books *lpointer;
int lnumbook;
bool found=0;
lpointer=pointer; /*error 'pointer' was not declared in this scope
...but I declared 'pointer' as global variable */
for(lnumbook=1;lnumbook<=bookcount;lnumbook++)
{
if(!strcmp((*lpointer).title,ltitle)) //cannot convert string* to const char*
found=1;
}
if(found)
{
sell(ltitle);
}
else
{
cout<<"Book not found";
}
}
void 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); //no matching function call
}
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);
/*pointer not in this scope. expected-primary expression before ltitle, lauthor, lprice,lstock*/
}
menu();
}
return 0;
}
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;
}