954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ OOP can't find item by ID

Hi every1!
Thats my code that used to work before I've added some attributes to my items.

void manager::EditStockItem()
{
  ListStock();
		{
			string z;
			bool found;

			cout<< endl<<"<===================================================>"<<endl<<endl;
			cout << "Enter ID of the Stock Item you want to edit" << endl<<endl;
			cin>>z;

			found = false;
	          vector <Item*>::iterator iter = theStock.begin();
	          for(iter = theStock.begin();iter != theStock.end();++iter)
				{
				
					if (z == ((*iter)->getStockID()))
					  {
						 found = true;
						 break;
					  }
			    }

			if(found)
				{
					system("cls");
					char choice;
					bool valid = false;
					for(;;) 
					{
						system("cls");
						do 
						  {
							cout << " Edit details of "<<z<<endl;
							cout << "		1. To edit ID\n";
							cout << "		2. To edit Title\n";
							cout << "		3. To edit Publisher\n";
							cout << "		4. To edit Price\n";
							cout << "		5. To Cancel\n";
							cin >> choice;
							if(choice == '5') 
								{
									ShowAdminMenu();
								}

							else if(choice < '1' || choice > '4')
								{		
									cout << "\nNot a valid char!\n\n";
									char aChar;
									cout << endl << "Enter any character to continue .. " << endl;	
									cin >> aChar;
									system("cls");
								}
							else
							    {
								    valid = true;
							    }
						}
					  while(!valid);
					  cout << "\n";
					  switch(choice) 
						{
						  char aChar;
						  case '1':
							 {
								cout << "Enter new ID" << endl;
								string newStockID;
								cin.sync();
								getline(cin,newStockID);
								(*iter)->setStockID(newStockID);
								ListStock();
							 }
							cout << endl << "Enter any character to continue .. " << endl;	
							cin >> aChar;
							break;
					      case '2':
							 {
								cout << "Enter new Title: " << endl;
								string newTitle;
								cin.sync();
								getline(cin,newTitle);
								(*iter)-> setTitle(newTitle);
								ListStock();
							 }
					       cout << endl << "Enter any character to continue .. " << endl;
					       cin >> aChar;
					       break;
				         case '3':
							 {
								 cout << "Enter new Publisher: " << endl;
								 string newPublisher;
								 cin.sync();
								 getline(cin,newPublisher);
								(*iter)-> setPublisher(newPublisher);
								ListStock();
							 }
							cout << endl << "Enter any character to continue .. " << endl;
							cin >> aChar;
							break;
						case '4':
							 {
								cout << "Enter new Price" << endl;
								string newPrice;
								cin.sync();
								getline(cin,newPrice);
								(*iter)->setPrice(newPrice);
								ListStock();
							 }
							cout << endl << "Enter any character to continue .. " << endl;	
							cin >> aChar;
							break;				
						}
					cout << "\n";
				}
			}
		 else
			{
				cout << "Not found" << endl;
				
			}
	}
}


Heres the Stock vector

void manager::BuildStockVector()
{
	theStock.push_back(new Book("SBK010","978-0-307-47427-8","A Tale of Two Cities","Penguin Classics","General","345","12"));
	theStock.push_back(new Book("SBK020","325-0-412-45527-4","The Da Vinci Code","Random House","General","237","14.25"));
	theStock.push_back(new Book("SBK011","978-0-307-47427-3","Copy of the book 'A Tale of Two Cities'","Penguin Classics","General","340","12"));	
	theStock.push_back(new Journal("SJN010","0811-8203","Desire Journal","8","01.04.2012","History","Chronicle Books","144","10.75"));	
	theStock.push_back(new Video("SVD010","The Squid and the Whale","Drama","1:45:22","AVI","Keep Case","Sony Pictures Home Entertainment","20"));		
	theStock.push_back(new Video("SVD020","High Fidelity","Dogstar Films","Comedy","1:37:44","DVD","Keep Case","17.50"));	
	theStock.push_back(new MusicCD("SCD010","Chris Rea","The Best Of Chris Rea","0:45:22","Tyvek Sleeve","CD","16","East/West Records","6.50"));	
	theStock.push_back(new MusicCD("SCD020","Smokie","The Best Of Smokie","0:48:12","Paper Sleeve","CD-R","17","Paradiso","4.75"));	
	theStock.push_back(new Journal("SJN010","0811-8204","Copy of 'Desire Journal'","8","01.04.2012","History","Chronicle Books","144","10.75"));
	theStock.push_back(new Book("SBK021","325-0-412-45527-2","Copy of the book 'The Da Vinci Code'","Random House","General","235","14.25"));
	theStock.push_back(new Journal("SJN020","0577-2173","CSC Journal","3","01.08.2011","IT","CSC Journals","87","4.25"));
	theStock.push_back(new Journal("SJN021","0577-2175","Copy of the 'CSC Journal'","3","01.08.2011","IT","CSC Journals","87","4.25"));
}
vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

It's askin to enter ID of the item to edit but when I do so it returns NOT FOUND...I'm newbie to C++ so not sure if I have to upload any other files for a full picture...

vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Oh another thing .. The classes are (controller/Stock/Item/Publication/Books) ( controller/Stock/Item/Publication/Journals) ( controller/Stock/Item/av/Video) and ( controller/Stock/Item/av/MusicCD)

vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Run time debugging is a big part of creating a successful program. Either use your debugger to step through the program with known input or enter debugging code, something like the following often works pretty well, and see if you can track down the problem.

On line 16 of EditStockItem() output the value of z and (*iter)->getStockID() and then pause the program (with this code or something similar: char trash; cin >> trash; ). Review the results of the output. Are z and (*iter)->getStockID() ever the same, or not, as you cycle through the loop?

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

As far as I understand getStockID() is not working..

vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

I assume outputting z went okay, but you got junk for the (*iter)->getStockID() stuff. If so there other possible problems besides something wrong with getStockID():

--the syntax you're using to call getStockID() isn't working
--the process to enter information into the vector isn't working so the contents of the vector aren't what you think they are

Who knows what it is at this point. But we do know it's probably not what/where you thought it was in the first place. It was the obvious first place to look, but it didn't pan out. So, I'd go back earlier in the program, try to add a single item to the vector and then try to output the information, including at least a call to getStockID(). That should help you take the next step to figuring out where the problem is.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

You're right Z is fine but (*iter)->getStockID() displays nothing...absolutely nothing..I'm thinking about earlier stage and ....Be4 classes were controller/stock/item/book and it was working fine.. But later I've added another class so now I have like controller/stock/item/publication/book, but I still can't imagine where the problem might be...

vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

I can add stock and display it back no problem

vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

How do you display the contents of the vector of stock when you display it successfully, and where are you checking the display?

Post the header file for the manager class, please.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

I use getAllDetails() to display The Stock and if I add new item befor this function I can see that in a list..here's the code

#pragma once
#include <vector>
using std::vector;
class manager
{
private:
	string CurrentUserID;
	vector <customer*> theCus;
	vector <Item*> theStock;
	void BuildCustomerVector();
	void BuildStockVector();
	void BuildAdminVector();
    void Login();
	void aLogin();
	void uLogin();
	void AddUser();
	void AddAdmin();
	void AddCustomer();
	void ListUsers();
	void EditUser();
	void ListStock();
	void ChangePass();
	void AddStock();
	void AddBook();
	void AddJournal();
	void AddVideo();
	void AddMusicCD();
	void EditStockItem();
	void HireInfo();
	

public:
	manager(void);
	~manager(void);
	void ShowUserMenu();
	void ShowAdminMenu();

};
vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Ok. I don't see getAllDetails() in code posted so far. theStock is listed as a private member variable of the manager class. How does getAllDetails() get access to theStock?

Please post header file for the Item class, too, so getStockID() declaration can be viewed.

Just like you included the vector header file for the manager class to use, you will need to include the header files for STL string class, the Item class and the customer class for the mangager class to use in the header file. I don't seen those headers included in the mangager class. That may be the easiest thing to check out.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

This simple function returns all details apart from ID ....

void manager::ListStock() 
{
	system("cls");
	cout << endl << "Stock Items" << endl << "<=====================>" << endl;	
	vector <Item*>::iterator iter = theStock.begin();
	for(iter = theStock.begin();iter != theStock.end();++iter)
	{   
		cout<<(*iter)->getStockID() << endl;
		(*iter)->getAllDetails();
		cout << endl << "==================" << endl;
	}
	cout << endl << "End of List" << endl;
}
vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

So if you call ListStock() and it correctly prints out all the attributes except the ID of the Item pointers in theStock, then please post the Item class header file and the implementation of getStockID().

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

Just to remind it goes :manager/Stock(abstract)/Item/publication/book .
There's nothin in Stock.cpp and I'm not sure if I need this at all..But it's there and it works.

This is header file for book.cpp

#pragma once
#include "publication.h"

class Book:
	public publication
{
public:
	Book(void);
	Book(string SID, string ISBN, string Title, string Publisher, string SubjectArea, string NumberPages,string Price);
	~Book(void);
	void getAllDetails();
	
	
};

This is header file for Item.cpp

#pragma once
#include <string>
using namespace std;

class Item:
	public stock
{
protected:
	string StockID;
	string ISBN;
	string ISSN;
	string Title;
	string IssueNo;
	string IssueDate;
	string Publisher;
	string SubjectArea;
	string NumberPages;
	string RunningTime;
	string StorageCase;
	string CDType;
	string TrackNo;
	string Artist;
	string Format;
	string Genre;
	string Price;
	
	
public:
	Item(void);
	Item(string StockID, string Title, string Publisher, string Price, string SubjectArea, string NumberPages, string ISBN, string ISSN,string IssueNo,string IssueDate,string RunningTime,string StorageCase,string CDType, string TracNo,string Artist,string Format, string Genre);
	~Item(void);
	string getStockID();
	string getPrice();
	string getTitle();
	string getPublisher();
	string getNP();
	string getSA();
	string getISBN();
	string getISSN();
	string getIssueNo();
	string getIssueDate();
	string getRunningTime();
	string getStorageCase();
	string getCDType();
	string getTrackNo();
	string getArtist();
	string getFormat();
	string getGenre();

	void setStockID(string newStockID);
	void setTitle(string newTitle);
	void setPublisher(string newPublisher);
	void setPrice(string newPrice);
	void setISBN(string newISBN);
	void setISSN(string newISSN);
	void setIssueNo(string newIssueNo);
	void setIssueDate(string newIssueDate);
	void setNumberPages(string newNumberPages);
	void setSubjectArea(string newSubjectArea);
	void setRunningTime(string newRu8nningTime);
	void setStorageCase(string newStorageCase);
	void setCDType(string newCDType);
	void setTrackNo(string newTrackNo);
	void setArtist(string newArtist);
	void setFormat(string newFormat);
	void setGenre(string newGenre);
	virtual void getAllDetails();
	
};


This is Item.cpp with getStockID() in it:

#include "StdAfx.h"
#include "Item.h"

Item::Item(void)
{
}


Item::Item(string newStockID, string newTitle, string newPublisher, string newPrice, string newSubjectArea, string newNumberPages, string newISBN,string newISSN,string newIssueNo, string newIssueDate, string newRunningTime,string newStorageCase,string newCDType,string newTrackNo,string newArtist,string newFormat, string newGenre)
{
	StockID=newStockID;
	Title=newTitle;
	Publisher=newPublisher;
	SubjectArea = newSubjectArea;
	NumberPages = newNumberPages;
	ISBN = newISBN;
	ISSN =newISSN;
	IssueDate = newIssueDate;
	IssueNo = newIssueNo;
	RunningTime = newRunningTime;
	StorageCase = newStorageCase;
	CDType = newCDType;
	TrackNo = newTrackNo;
	Artist = newArtist;
	Format = newFormat;
	Genre = newGenre;
	Price=newPrice;
}

Item::~Item(void)
{
}

string Item::getStockID()
{
	return StockID;
}
string Item::getPrice()
{
	return Price;
}
string Item::getTitle()
{
	return Title;
}
string Item::getPublisher()
{
	return Publisher;
}
string Item::getNP()
{
	return NumberPages;
}
string Item::getSA()
{
	return SubjectArea;
}
string Item::getISBN()
{
	return ISBN;
}
string Item::getISSN()
{
	return ISSN;
}
string Item::getIssueDate()
{
	return IssueDate;
}
string Item::getIssueNo()
{
	return IssueNo;
}
string Item::getRunningTime()
{
	return RunningTime;
}
string Item::getStorageCase()
{
	return StorageCase;
}
string Item::getCDType()
{
	return CDType;
}
string Item::getTrackNo()
{
	return TrackNo;
}
string Item::getArtist()
{
	return Artist;
}
string Item::getFormat()
{
	return Format;
}
string Item::getGenre()
{
	return Genre;
}


void Item::setStockID(string newStockID)
{
	StockID = newStockID;
}
void Item::setTitle(string newTitle)
{
Title = newTitle;
}
void Item::setPublisher(string newPublisher)
{
Publisher = newPublisher;
}
void Item::setPrice(string newPrice)
{
Price = newPrice;
}
void Item::setSubjectArea(string newSubjectArea)
{
SubjectArea = newSubjectArea;
}
void Item::setNumberPages(string newNumberPages)
{
NumberPages = newNumberPages;
}
void Item::setISBN(string newISBN)
{
ISBN = newISBN;
}
void Item::setISSN(string newISSN)
{
ISSN = newISSN;
}
void Item::setIssueDate(string newIssueDate)
{
IssueDate=newIssueDate;
}
void Item::setIssueNo(string newIssueNo)
{
IssueNo=newIssueNo;
}
void Item::setRunningTime(string newRunningTime)
{
RunningTime = newRunningTime;
}
void Item::setStorageCase(string newStorageCase)
{
StorageCase = newStorageCase;
}
void Item::setCDType(string newCDType)
{
CDType = newCDType;
}
void Item::setTrackNo(string newTrackNo)
{
TrackNo = newTrackNo;
}
void Item::setFormat(string newFormat)
{
Format = newFormat;
}
void Item::setArtist(string newArtist)
{
Artist = newArtist;
}
void Item::setGenre(string newGenre)
{
Genre = newGenre;
}

void Item::getAllDetails()
{

}


To be honest I'd send everything after a whole day of useless trying..

vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Welcome to the world of runtime debugging. It can be long and tedious.

Does the non default Book constructor assign SID to StockID? Posting the entire definition of that constructor wouldn't hurt.

Please post the call you used to getAllDetails() and the version of getAllDetails() used (it's declared as virtual defined as void in class Item, so I assume it has a different definition in class Publication and class Book).

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

Right..Here's what I'll do (because my brain is stalled and I've already made some modifications trying to solve it )... I'll upload most of it so it is easier to trace the process..Here goes...

Manager.cpp(NOT the whole code just one of the functions that is "malfunctioning")

#include "StdAfx.h"
#include "manager.h"
manager::manager(void)       //Constructor
{
	BuildStockVector();
	BuildCustomerVector();
	Login();
	ShowUserMenu();
	ShowAdminMenu();
	
}
manager::~manager(void)
{
}void manager::ListStock() 
{
	system("cls");
	cout << endl << "Stock Items" << endl << "<=====================>" << endl;	
	vector <Item*>::iterator iter = theStock.begin();
	for(iter = theStock.begin();iter != theStock.end();++iter)
	{   
		cout<<(*iter)->getStockID() << endl;
		(*iter)->getAllDetails();
		cout << endl << "==================" << endl;
	}
	cout << endl << "End of List" << endl;
}


Manager.h

#pragma once
#include <vector>
using std::vector;
class manager
{
private:
	string CurrentUserID;
	vector <customer*> theCus;
	vector <Item*> theStock;
	void BuildCustomerVector();
	void BuildStockVector();
	void BuildAdminVector();
    void Login();
	void aLogin();
	void uLogin();
	void AddUser();
	void AddAdmin();
	void AddCustomer();
	void ListUsers();
	void EditUser();
	void ListStock();
	void ChangePass();
	void AddStock();
	void AddBook();
	void AddJournal();
	void AddVideo();
	void AddMusicCD();
	void EditStockItem();
	void HireInfo();
	

public:
	manager(void);
	~manager(void);
	void ShowUserMenu();
	void ShowAdminMenu();

};


Stock.cpp

#include "StdAfx.h"
#include "stock.h"

stock::stock(void)
{

}
stock::~stock(void)
{
}


Stock.h

#pragma once

class stock
{
public:
	stock(void);
	~stock(void);
};


Item.cpp

#include "StdAfx.h"
#include "Item.h"

Item::Item(void)
{
}


Item::Item(string newStockID, string newTitle, string newPublisher, string newPrice, string newSubjectArea, string newNumberPages, string newISBN,string newISSN,string newIssueNo, string newIssueDate, string newRunningTime,string newStorageCase,string newCDType,string newTrackNo,string newArtist,string newFormat, string newGenre)
{
	StockID=newStockID;
	Title=newTitle;
	Publisher=newPublisher;
	SubjectArea = newSubjectArea;
	NumberPages = newNumberPages;
	ISBN = newISBN;
	ISSN =newISSN;
	IssueDate = newIssueDate;
	IssueNo = newIssueNo;
	RunningTime = newRunningTime;
	StorageCase = newStorageCase;
	CDType = newCDType;
	TrackNo = newTrackNo;
	Artist = newArtist;
	Format = newFormat;
	Genre = newGenre;
	Price=newPrice;
}

Item::~Item(void)
{
}

string Item::getStockID()
{
	return StockID;
}
string Item::getPrice()
{
	return Price;
}
string Item::getTitle()
{
	return Title;
}
string Item::getPublisher()
{
	return Publisher;
}
string Item::getNP()
{
	return NumberPages;
}
string Item::getSA()
{
	return SubjectArea;
}
string Item::getISBN()
{
	return ISBN;
}
string Item::getISSN()
{
	return ISSN;
}
string Item::getIssueDate()
{
	return IssueDate;
}
string Item::getIssueNo()
{
	return IssueNo;
}
string Item::getRunningTime()
{
	return RunningTime;
}
string Item::getStorageCase()
{
	return StorageCase;
}
string Item::getCDType()
{
	return CDType;
}
string Item::getTrackNo()
{
	return TrackNo;
}
string Item::getArtist()
{
	return Artist;
}
string Item::getFormat()
{
	return Format;
}
string Item::getGenre()
{
	return Genre;
}


void Item::setStockID(string newStockID)
{
	StockID = newStockID;
}
void Item::setTitle(string newTitle)
{
Title = newTitle;
}
void Item::setPublisher(string newPublisher)
{
Publisher = newPublisher;
}
void Item::setPrice(string newPrice)
{
Price = newPrice;
}
void Item::setSubjectArea(string newSubjectArea)
{
SubjectArea = newSubjectArea;
}
void Item::setNumberPages(string newNumberPages)
{
NumberPages = newNumberPages;
}
void Item::setISBN(string newISBN)
{
ISBN = newISBN;
}
void Item::setISSN(string newISSN)
{
ISSN = newISSN;
}
void Item::setIssueDate(string newIssueDate)
{
IssueDate=newIssueDate;
}
void Item::setIssueNo(string newIssueNo)
{
IssueNo=newIssueNo;
}
void Item::setRunningTime(string newRunningTime)
{
RunningTime = newRunningTime;
}
void Item::setStorageCase(string newStorageCase)
{
StorageCase = newStorageCase;
}
void Item::setCDType(string newCDType)
{
CDType = newCDType;
}
void Item::setTrackNo(string newTrackNo)
{
TrackNo = newTrackNo;
}
void Item::setFormat(string newFormat)
{
Format = newFormat;
}
void Item::setArtist(string newArtist)
{
Artist = newArtist;
}
void Item::setGenre(string newGenre)
{
Genre = newGenre;
}

void Item::getAllDetails()
{

}


Item.h

#pragma once
#include <string>
using namespace std;

class Item:
	public stock
{
protected:
	string StockID;
	string ISBN;
	string ISSN;
	string Title;
	string IssueNo;
	string IssueDate;
	string Publisher;
	string SubjectArea;
	string NumberPages;
	string RunningTime;
	string StorageCase;
	string CDType;
	string TrackNo;
	string Artist;
	string Format;
	string Genre;
	string Price;
	
	
public:
	Item(void);
	Item(string StockID, string Title, string Publisher, string Price, string SubjectArea, string NumberPages, string ISBN, string ISSN,string IssueNo,string IssueDate,string RunningTime,string StorageCase,string CDType, string TracNo,string Artist,string Format, string Genre);
	~Item(void);
	string getStockID();
	string getPrice();
	string getTitle();
	string getPublisher();
	string getNP();
	string getSA();
	string getISBN();
	string getISSN();
	string getIssueNo();
	string getIssueDate();
	string getRunningTime();
	string getStorageCase();
	string getCDType();
	string getTrackNo();
	string getArtist();
	string getFormat();
	string getGenre();

	void setStockID(string newStockID);
	void setTitle(string newTitle);
	void setPublisher(string newPublisher);
	void setPrice(string newPrice);
	void setISBN(string newISBN);
	void setISSN(string newISSN);
	void setIssueNo(string newIssueNo);
	void setIssueDate(string newIssueDate);
	void setNumberPages(string newNumberPages);
	void setSubjectArea(string newSubjectArea);
	void setRunningTime(string newRu8nningTime);
	void setStorageCase(string newStorageCase);
	void setCDType(string newCDType);
	void setTrackNo(string newTrackNo);
	void setArtist(string newArtist);
	void setFormat(string newFormat);
	void setGenre(string newGenre);
	virtual void getAllDetails();
	
};


publication.cpp

#include "StdAfx.h"
#include "publication.h"

publication::publication(void)
{
}
publication::publication(string stockid, string price, string title, string publisher,string SArea, string NPages,string isbn,string issn, string issueno, string issuedate)
{
StockID = stockid;
Price = price;
Title = title;
Publisher = publisher;
SubjectArea = SArea;
NumberPages = NPages;
ISBN =isbn;
ISSN = issn;
IssueDate = issuedate;
IssueNo = issueno;
}
publication::~publication(void)
{

}
string publication::getstockid()
{
	return stockid;
}

publication.cpp

#include "StdAfx.h"
#include "publication.h"

publication::publication(void)
{
}
publication::publication(string stockid, string price, string title, string publisher,string SArea, string NPages,string isbn,string issn, string issueno, string issuedate)
{
StockID = stockid;
Price = price;
Title = title;
Publisher = publisher;
SubjectArea = SArea;
NumberPages = NPages;
ISBN =isbn;
ISSN = issn;
IssueDate = issuedate;
IssueNo = issueno;
}
publication::~publication(void)
{

}
string publication::getstockid()
{
	return stockid;
}

publication.h

#pragma once
#include <string>
using namespace std;
#include "Item.h"


class publication:
	public Item
{
protected:
	string stockid;
	string title;
	string publisher;
	string SArea;
	string NPages;
	string isbn;
	string issn;
	string issuedate;
	string issueno;
	string price;
public:

	publication(void);
	publication(string stockid, string title, string publisher,string SArea, string NPages,string isbn,string issn, string issuedate,string issueno, string price);
	~publication(void);
	string getstockid();
};

Book.cpp

#include "StdAfx.h"
#include "Book.h"

Book::Book(void)
{
}
Book::Book(string StockID, string ISBN, string Title, string Publisher, string SubjectArea, string NumberPages,string Price)
{
	stockid = StockID;
	isbn = ISBN;
	title = Title;
	publisher = Publisher;
	SArea = SubjectArea;
	NPages = NumberPages;
	price = Price;
}
Book::~Book(void)
{
}
string Journal::getStockID()
{
	return StockID;
}
void Book::getAllDetails()
{
	cout <<"   Book " << endl;
	//cout <<" ID           : "<<stockid<<endl;
	cout <<" ISBN         : "<<isbn<<endl;
	cout <<" Title        : "<<title<<endl;
	cout <<" Publisher    : "<<publisher<<endl;
	cout <<" Subject area : " << SArea<<endl;
	cout <<" No of pages  : " <<NPages<<endl;
	cout <<" Price        : $"<<price<<endl;
	

	
}

Book.h

#pragma once
#include "publication.h"

class Book:
	public publication
{
private:
	string StockID;
	string Title;
	string Publisher;
	string SubjectArea;
	string NumberPages;
	string ISBN;
	string Price;
public:
	Book(void);
	Book(string StoskID, string ISBN, string Title, string Publisher, string SubjectArea, string NumberPages,string Price);
	~Book(void);
	void getAllDetails();
	string getStockID();
	
};
vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

Oh sorry , and vector..

void manager::BuildStockVector()
{
	theStock.push_back(new Book("SBK010","978-0-307-47427-8","A Tale of Two Cities","Penguin Classics","General","345","12"));
	theStock.push_back(new Book("SBK020","325-0-412-45527-4","The Da Vinci Code","Random House","General","237","14.25"));
	theStock.push_back(new Book("SBK011","978-0-307-47427-3","Copy of the book 'A Tale of Two Cities'","Penguin Classics","General","340","12"));	
	theStock.push_back(new Journal("SJN010","0811-8203","Desire Journal","8","01.04.2012","History","Chronicle Books","144","10.75"));	
	theStock.push_back(new Video("SVD010","The Squid and the Whale","Drama","1:45:22","AVI","Keep Case","Sony Pictures Home Entertainment","20"));		
	theStock.push_back(new Video("SVD020","High Fidelity","Comedy","1:37:44","DVD","Keep Case","Dogstar Films","17.50"));	
	theStock.push_back(new MusicCD("SCD010","Chris Rea","The Best Of Chris Rea","0:45:22","Tyvek Sleeve","CD","16","East/West Records","6.50"));	
	theStock.push_back(new MusicCD("SCD020","Smokie","The Best Of Smokie","0:48:12","Paper Sleeve","CD-R","17","Paradiso","4.75"));	
	theStock.push_back(new Journal("SJN010","0811-8204","Copy of 'Desire Journal'","8","01.04.2012","History","Chronicle Books","144","10.75"));
	theStock.push_back(new Book("SBK021","325-0-412-45527-2","Copy of the book 'The Da Vinci Code'","Random House","General","235","14.25"));
	theStock.push_back(new Journal("SJN020","0577-2173","CSC Journal","3","01.08.2011","IT","CSC Journals","87","4.25"));
	theStock.push_back(new Journal("SJN021","0577-2175","Copy of the 'CSC Journal'","3","01.08.2011","IT","CSC Journals","87","4.25"));
}
vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

and here stdafx.h just incase

#pragma once

#include "targetver.h"
#include<sstream>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

#include "person.h"
#include "admin.h"
#include "user.h"
#include "customer.h"
#include "stock.h"
#include "Item.h"
#include "publication.h"
#include "av.h"
#include "Book.h"
#include "Journal.h"
#include "Video.h"
#include "MusicCD.h"
vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This is going to get a bit long, so hopefully I don't trip over my own shoelaces.

Assumption: You are doing a copy/paste when you post your code.

C++ is case sensitive. So the variable StockID in class Item is different than the variable called stockid declared in class publication. Therefore publication class publication and class Book have both StockID and stockid. In Book the non default constructor assigns the first input string (inadviseable also called StringID) to stockid inherited from publication, not the class variable StockID inherited from Item.

The getStockID() function in class book returns StockID(), not stockid, but even that wouldn't matter because in manager::EditItem, you are using an Item pointer to call a non virtual function, meaning it will call the version of getStockID() in Item, not the version of getStockID() in class Book. Unfortunately since the Item default constructor doesn't give StockID a value and the non default constructor of Book also doesn't assign a value to StockID so StockID has no value when the Item version of getStockID() is called.

I recommend you remove all variable declarations from publication and Book that are inherited from Item and only declare any new variable attributes you want those classes to have. That means the Book non default constructor will assign the first string passed in(PLEASE call it somehting other than StockID) to the variable called StockID inherited from Item. And beware when calling methods from base class pointers, as the virtual functions will be of the class stored as a base pointer not the base class methods, but the non virtual functions will be the version in the base class not the derived class version(, and any method in the derived class not declared in the base class won't be available to be called through the base class pointer at all).

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

I've removed all repetitive attributes from publication and Book.. Now I'm getting errors error C2661: 'Book::Book' : no overloaded function takes 8 arguments. I've tried to make "few" more changes but.. no idea where to look for solution..

vindom
Light Poster
41 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You