In this code I am getting structure required on left side of . or .* error on this line
ob[i].getdata();
please let me know am I doing anything wrong ?
#include<iostream.h>
#include<string.h>
#include<iomanip.h>
//Using namespace std
class book
{
private:
char *author;
char title[50];
int price;
char publisher[50];
int stock_position;
public:
book(int x)//constructor defined
{
author=new char[x];
char *a=new char[10];
}
void getdata();
void display();
};//class ends
void book :: getdata()
{
cout<<"Enter title of book";
cin>>title;
cout<<"Enter author of book";
cin>>author;
cout<<"Enter price of book";
cin>>price;
cout<<"Enter publisher of book";
cin>>publisher;
cout<<"Enter number of copies";
cin>>stock_position;
}
void book :: display()
{
cout<<setw(20)<<title<<setw(20)<<author<<setw(20)<<publisher<<setw(20)<<price
<<setw(10)<<stock_position;
}
main()
{
int size; int i;
cout<<"How many character you want in author name\n";
cin>>size;
book *ob[5];
ob[50]=new book(size);
char bname[50];
int choice,nbook;
while(1)
{
cout<<"Menu:1.Input Data 2.Display 3.search book 4.Purchase book 5.Exit";
cout<<"\n Enter your choice";
cin>> choice;
switch(choice)
{
case 1:
cout<<"How many books data you want to enter";
cin>>nbook;
for(i=0;i<nbook;i++)
ob[i].getdata();
break;
case 2:
if (nbook<=0)
cout<<"No data available";
else
{
cout<<setw(20)<<"title"<<setw(20)<<"author"<<setw(20)<<"Publisher"<<setw(20)<<"prices"<<setw(10)<<"stock position";
for(i=0;i<nbook;i++)
{
ob[i].putdata();
}
}
break;
case 3:
if (nbook<=0)
cout<<"No data available";
else
{
cout<<setw(20)<<"title"<<setw(20)<<"author"<<setw(20)<<"Publisher"<<setw(20)<<"prices"<<setw(10)<<"stock position";
for(i=0;i<nbook;i++)
{
cout<<"Enter book name you want to search";
cin>>bname;
if (strcmp(bname,ob[i].title)==0)
{
ob[i].putdata();
}
}
}
break;
case 4:
if (nbook<=0)
cout<<"No data available";
else
{
for(i=0;i<nbook;i++)
{
cout<<"Enter book name you want to purchase";
cin>>bname;
if (strcmp(bname,ob[i].title)==0)
{
cout<<"book details are given below";
cout<<setw(20)<<"title"<<setw(20)<<"author"<<setw(20)<<"Publisher"<<setw(20)<<"prices"<<setw(10)<<"stock position";
ob[i].putdata();
cout<<"How many copies you want to puchase";
cin>>copies;
If (ob[i].stock_position>=copies)
{
cout<<"Requested copies are available\n";
cout<<"Total cost is:\t"<<copies*ob[i].price;
}
else
{
cout<<"Sorry!!!!!Requested copies arenot available\n";
}
}
}
break;
case 5:
exit(0);
}//while ends
}//main ends
}
code tags is ok.
If i use book *ob[50]
then it will work ?
How to get working the code I want to remove the error
structure required on left side of . or .*