Okay im so lost please help
Whta i have to do is do a read function.
This read function will read the data for the entry from the console, prompting the user for each input that is required.
The read function will ask for the media and entertainment type and create the objects based on the users input. Once the media and entertainment objects have been created, the equivalent read functions of the objects are called to read in the other attributes of the objects.
How do i create the objects based on the users input.
The media and entertainment classes are abstract here is the code.
Code:
int Entry::read()
{
}
Media
Code:
Media::Media():_barcode(""),_speed(""){}
Media::Media(const Media& media)
{
_barcode = media._barcode;
_speed = media._speed;
}
const string& Media::getBarcode() const
{
return _barcode;
}
const string& Media::getSpeed() const
{
return _speed;
}
void Media::setBarcode(const string& barcode)
{
this->_barcode = barcode;
}
void Media::setSpeed(const string& speed)
{
this->_speed = speed;
}
bool Media::operator ==(const Media& obj) const
{
if (this->getMediaType() == obj.getMediaType())
{
return true;
}
return false;
}
bool Media::operator !=(const Media& media) const
{
return !(*this==media);
}
int Media::read()
{
string m_barcode;
string m_speed;
cout << "Enter Barcode: ";
getline(cin, m_barcode, '\n');
cout << "Enter Speed: ";
getline(cin, m_speed, '\n');
return 0;
}
int Media::read(Tokeniser& tok)
{
string in_barcode(_barcode);
Tokeniser t1(in_barcode, ":");
_barcode = tok.nextToken();
string in_speed(_speed);
Tokeniser t2(in_speed, ":");
_speed = tok.nextToken();
return 0;
}
int Media::write() const
{
cout<<"Media Type: " << this->getMediaType()<< endl;
cout<<"Barcode: "<< _barcode<<endl;
cout<<"Speed: "<<_speed<<endl;
return 0;
}
int Media::write(ofstream& outf) const
{
outf << this->getMediaType() << ":" << _barcode << ":" << _speed;
return 0;
}
Entertainment
Code:
Entertainment::Entertainment():_rating("NR"),_title(""),_purchaseDate(),_purchaseCost(),_publisher(""){}
Entertainment::Entertainment(const Entertainment& entertainment)
{
_rating = entertainment._rating;
_title = entertainment._title;
_purchaseDate = entertainment._purchaseDate;
_purchaseCost = entertainment._purchaseCost;
_publisher = entertainment._publisher;
}
const string& Entertainment::getRating() const
{
return _rating;
}
const string& Entertainment::getTitle() const
{
return _title;
}
const Currency& Entertainment::getPurchaseCost() const
{
return _purchaseCost;
}
const Date& Entertainment::getPurchaseDate() const
{
return _purchaseDate;
}
const string& Entertainment::getPublisher() const
{
return _publisher;
}
void Entertainment::setRating(const string& rating)
{
this->_rating = rating;
}
void Entertainment::setTitle(const string& title)
{
this->_title = title;
}
void Entertainment::setPurchaseCost(const Currency& cost)
{
this->_purchaseCost = cost;
}
void Entertainment::setPurchaseDate(const Date& purchaseDate)
{
this->_purchaseDate = purchaseDate;
}
void Entertainment::setPublisher(const string& publisher)
{
this->_publisher = publisher;
}
bool Entertainment::operator ==(const Entertainment& obj) const
{
if (_title == obj.getTitle() && this->getEntertainmentType() == obj.getEntertainmentType())
{
return true;
}
return false;
}
bool Entertainment::operator !=(const Entertainment& entertainment) const
{
return !(*this==entertainment);
}
int Entertainment::read()
{
string e_rating;
string e_title;
Date e_purchaseDate;
Currency e_purchaseCost;
string e_publisher;
string conv_day, conv_month, conv_year;
string conv_dollars, conv_cents;
int day, month, year;
int dollars, cents;
char *garbage;
cout << "Enter Rating: ";
getline(cin, e_rating,'\n');
cout << "Enter Title: ";
getline(cin, e_title,'\n');
cout << "Enter Purchase Date: ";
getline(cin, conv_day,'/');
day = strtol(conv_day.c_str(),&garbage,10);
getline(cin, conv_month,'/');
month = strtol(conv_month.c_str(),&garbage,10);
getline(cin, conv_year,'\n');
year = strtol(conv_year.c_str(),&garbage,10);
cout << "Enter Purchase Cost: ";
getline(cin, conv_dollars,'.');
dollars = strtol(conv_dollars.c_str(),&garbage,10);
getline(cin, conv_cents,'\n');
cents = strtol(conv_cents.c_str(),&garbage,10);
cout << "Enter Publisher: ";
getline(cin, e_publisher,'\n');
return 0;
}
int Entertainment::read(Tokeniser& tok)
{
string in_r(_rating);
Tokeniser t1(in_r, ":");
_rating = tok.nextToken();
string in_t(_title);
Tokeniser t2(in_t, ":");
_title = tok.nextToken();
return 0;
}
int Entertainment::write() const
{
//ME
cout<<"Entertainment Type: " << this->getEntertainmentType() << endl;
cout<<"Rating: "<< _rating <<endl;
cout<<"Title: "<< _title <<endl;
cout<<"Purchase Date: "<< _purchaseDate <<endl;
cout<<"purchase Cost: "<< _purchaseCost <<endl;
cout<<"Publisher: "<< _publisher <<endl;
return 0;
}
int Entertainment::write(ofstream& outf) const
{
//ME
outf << this->getEntertainmentType() << ":" << _rating << ":" << _title << ":"
<< _purchaseDate << ":" << _purchaseCost << ":" << _publisher;
return 0;
}