Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 1st, 2010, 04:35 AM
Authorized User
 
Join Date: Mar 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Smile 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
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to display scrollbars on left side of screen? rupen CSS Cascading Style Sheets 4 November 2nd, 2005 05:18 AM
left side menu nusrati HTML Code Clinic 1 July 16th, 2004 03:52 PM
Left Join error mariakovacs Access ASP 2 October 13th, 2003 04:16 PM
LEFT ERROR xcalibur ASP.NET 1.0 and 1.1 Professional 1 October 10th, 2003 09:23 AM
Left Error kilika ASP.NET 1.0 and 1.1 Professional 3 July 7th, 2003 04:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.