Error : structure required on left side of . or .*
Hello,
Problem Description : It will create class Book. Using class object book details will be stored.
Problem Occurerd : Fetching object data member using array of object.
[FONT='Arial','sans-serif']Error : structure required on left side of . or .*[/FONT]
Can anyone suggest how to reolve it? Below is the code to make proble more clearer.
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <iomanip.h>
class Book{
static int Lastisbn;
int isbn;
char *auth;
char *title;
char *publ;
float price;
int stk_pos;
public:
Book();
Book(char *a,char *t,char *p,float prc);
Book Purchase(Book* b[],int n,char *t,char *a);
void Stock(Book b,int cp);
void Display(Book b,int cpy);
~Book()
{
delete []auth;
delete []title;
delete []publ;
}
};
int Book :: Lastisbn;
Book :: Book()
{
auth = new char[25];
title = new char[25];
publ = new char[25];
price = 0;
}
Book :: Book(char *a,char *t,char *p,float prc)
{
Lastisbn++;
isbn = Lastisbn;
auth = a;
title = t;
publ = p;
price = prc;
stk_pos= stk_pos + 1;
}
Book Book :: Purchase(Book* b[],int n,char *t,char *a)
{
int cpy,len;
char *tempt;
char *tempa;
len=strlen(t);
tempt = new char[len];
strcpy(tempt,t);
len=strlen(a);
tempa = new char[len];
strcpy(tempt,a);
for(int i=0;i<n;i++)
{
if(b[i].title==t && b[i].auth==a)
{
cout<<"Enter no. of copies required.";cin>>cpy;
b[i].Stock(b[i],cpy);
b[i].Display(b[i],cpy);
break;
}
}
}
void Book :: Stock(Book b,int cp)
{
if(b.stk_pos>=cp)
b.stk_pos=b.stk_pos - cp;
}
void Book :: Display(Book b,int cpy)
{
cout<<"Book Name:"<<b.auth;
cout<<"Title:"<<b.title;
cout<<"Publisher:"<<b.publ;
if(b.stk_pos>0)
{
cout<<"\nTotal cost of requested copies are"<<cpy * b.price;
cout<<"\nAvail Copies :"<<b.stk_pos;
}
else
{
cout<<"\nNo stock availabe for the given book.";
}
}
const int a = 3;
int main()
{
Book *b= new Book[a];
char auth[25];
char title[25];
char publ[25];
char o;
float price;
char ians;
clrscr();
for(int i=0;i<a;i++)
{
cout<<"Enter the author name:";cin>>auth;
cout<<"Enter the title:";cin>>title;
cout<<"Enter the publisher:";cin>>publ;
cout<<"Enter the price:";cin>>price;
b[i]=b[i](auth,title,publ,price);
}
do
{
cout<<"\n 1. Purchase:";
cout<<"\n 2. Inventory Status:";
cout<<"\n 3. View Book Details:";
cout<<"\n 4. Exit.";
switch(o)
{
case 1:
b[i].Purchase(b,a,b[i].title,b[i].auth);break;
case 2:
b[i].Stock(b[i]);break;
case 3:
b[i].Display(b[i]);break;
case 4:
ians='Y';break;
default:
cout<<"\nInvalid option.Try again.";
};
}
while(o='Y' || o='y');
getch();
return 0;
}
Thanks in Advance.
__________________
987654321
|