COPY CONSTRUCTORS
I really need help.
i previously posted a problem regarding aggregation and inheritance. Look at the user defined constructor and please tell me if im correct with the Publisher object. There is a main file which calls the BookItem constructor like this:
BookItem text1("Author", "Title", Publisher("Publisher's name")), 2002);
I dont know how to create the Set and GetPublisher() functions, i want to be able to set and get the Publisher's name. Can someone please help me. Someone was helping me but i still cant get it right.
I have a
SetPublisher(Publisher pubTemp){
delete pub;
pub = new Publisher(pubTemp);
//initialise the copy constructor
}
The GetPublisher returns a string or a class type, not sure?
i done a bit of extra work on the assignment operator overloading as well, not sure if thats right, too
please, get me out of this mess????
#include<iostream>
#include<string>
using namespace std;
#include "BookItem.h"
#include "StockItem.h"
// USER DEFINED CONSTRUCTOR
BookItem::BookItem(string Authors, const string &Title, Publisher
pubTemp, int Year = 0)
:StockItem(Title)
{
pub = new Publisher(pubTemp);
this->SetAuthors(Authors);
this->SetTitle(Title);
// this->SetPublisher(pub);
this->SetYear(Year);
}
string BookItem::GetAuthors() const
{
return(this->Authors);
}
string BookItem::GetTitle() const
{
return(this->Title);
}
string BookItem::GetPublisher() const
{
return("");
}
int BookItem::GetYear() const
{
return(this->Year);
}
void BookItem::SetAuthors(string Authors)
{
this->Authors = Authors;
}
void BookItem::SetTitle(const string &Title)
{
this->Title = Title;
}
void BookItem::SetPublisher(Publisher pubTemp)
{
delete pub;
pub = new Publisher(pubTemp);
}
void BookItem::SetYear(int Year)
{
this->Year = Year;
}
//COPY CONSTRUCTOR
BookItem::BookItem(const BookItem& bkObject)
:StockItem(bkObject), Authors(bkObject.GetAuthors()),Title(bkObject.GetT itle()),
pub(bkObject.pub), Year(bkObject.GetYear())
{
}
BookItem BookItem::operator=(const BookItem& temp)
{
if (this == &temp)
{
// IF THE RIGHT SIDE IS THE SAME AS THE LEFT SIDE
return *this;
}
else
{
delete pub;
Authors = temp.Authors;
Title = temp.Title;
pub = temp.pub;
Year = temp.Year;
return *this;
}
}
void BookItem::RecordPurchase(const int NumberPurchased,
const double &CostPrice)
{
double num = NumberPurchased * CostPrice;
SetTotalCost(num);
SetCostPrice(CostPrice);
SetNumberSold(NumberPurchased);
}
BookItem::~BookItem()
{
delete pub;
}
void BookItem::Print()
{
cout << endl;
cout << "Stock Item: " << GetTitle() << endl;
cout << "\tNumber Sold " << "\t- " << GetNumberSold() << endl;
cout << "\tTotal Revenue " << "\t- " << GetTotalRevenue() << endl;
cout << "\tTotal Cost " << "\t- " << GetTotalCost() << endl;
//cout << "\tAverage Profit " << "\t- " << GetAverageProfit() << endl;
cout << "\tAuthors " << "\t- " << GetAuthors() << endl;
cout << "\tPublisher " << "\t- " << GetPublisher() << endl;
}
__________________
gbilios
|