Hello , I'm having trouble with a C++ assignment. We're supposed to create an inventory program for keeping track of books, CDs and DVDs. We are supposed to use an abstract class InventoryItem, and classes Book, CD, DVD. Also a class Inventory will contain all the functions needed to enter the items into the data base. I'm having trouble figuring out how to get the object of Book, CD or DVD assigned into the memory space using new. I've just done a little, but here is the code I have so far:
#include <iostream>
#include <string>
using namespace std;
/////////////////////////////////////////////////////////////////////
class InventoryItem
{
public:
virtual ~InventoryItem(){}
virtual int IamThis(char c, char *pname)=0;
virtual int nonHand()=0;
virtual float Report(ostream& os)=0;
};
////////////////////////////////////////////////////////////////////
class Book : public InventoryItem
{
private:
string title;
string author;
string description;
float cost;
int nonhand;
char Iamthis;
public:
Book():title(""),author(""),description(""),cost(0.0),nonhand(0),Iamthis('b'){}
Book(string tit,string aut,string desc,float cst,int num, char iam):nonhand(0){}
virtual int IamThis(char c, char *pname){return 0;}
virtual int nonHand(){return 0;}
virtual float Report(ostream& os){return 0;}
};
////////////////////////////////////////////////////////////////////
class CD : public InventoryItem
{
private:
string title;
string artistName;
float playTime;
string musicType;
float cost;
int nonhand;
char Iamthis;
};
/////////////////////////////////////////////////////////////////////
class DVD : public InventoryItem
{
private:
string title;
string starActor;
string director;
string producer;
float runTime;
float cost;
int nonhand;
};
//////////////////////////////////////////////////////////////////////
class Inventory
{
private:
InventoryItem *PI[200];
int n;
public:
Inventory():n(0){}
~Inventory(){
for (int i=0;i<n;i++){
delete PI[i];
}
}
void createBook(string tit, string aut,string desc,float cst,int num,char iam)
{
Book* bookptr;
bookptr = new Book;
cout<<"book is: ";
}
void createCD(){}
void creatDVD(){}
void Report(){}
void computePrice(){}
};
/////////////////////////////////////////////////////////////////////
int main()
{
Inventory Inv;
Inv.createBook("Super Dog","J. Jones","Story about an Heroic Dog",12.99,0,'b');
return 0;
}
Any ideas or help out there? Appreciate. Thanks.