Here is my code:
class LibItem
{
public:
virtual void PrintDetails() = 0;
virtual void setDetails() = 0;
void setTitle(string TitleName)
{
Title = TitleName;
}
string getTitle()
{
return Title;
}
void setReleaseDate(string date)
{
ReleaseDate = date;
}
string getReleaseDate()
{
return ReleaseDate;
}
void setAuthor(string AuthorName)
{
Author = AuthorName;
}
string getAuthor()
{
return Author;
}
void setCopyright(string CopyrightDetails)
{
Copyright = CopyrightDetails;
}
string getCopyright()
{
return Copyright;
}
void setGenre(string GenreDetails)
{
Genre = GenreDetails;
}
string getGenre()
{
return Genre;
}
void setStatus(string StatusDetails)
{
Status = StatusDetails;
}
string getStatus()
{
return Status;
}
private:
string Title;
string ReleaseDate;
string Author;
string Copyright;
string Genre;
string Status;
};
class Book : public LibItem
{
public:
Book(string TitleName)
{
setTitle(TitleName);
}
void setISBN(int ISBNDetails)
{
ISBN = ISBNDetails;
}
int getISBN()
{
return ISBN;
}
void setDetails(string setBookTitle, string setBookAuthor, string setBookReleaseDate, string setBookCopyright, string setBookGenre, string setBookStatus, int setBookISBN)
{
setTitle(setBookTitle);
setAuthor(setBookAuthor);
setReleaseDate(setBookReleaseDate);
setCopyright(setBookCopyright);
setGenre(setBookGenre);
setStatus(setBookStatus);
setISBN(setBookISBN);
}
void PrintDetails()
{
cout << "Title: " << getTitle() << endl;
cout << "Author: " << getAuthor() << endl;
cout << "Release Date: " << getReleaseDate() << endl;
cout << "Copyrite: " << getCopyright() << endl;
cout << "Genre: " << getGenre() << endl;
cout << "Status: " << getStatus() << endl;
cout << "ISBN: " << getISBN() << endl;
}
private:
Book();
int ISBN;
};
class DVD : public LibItem
{
public:
DVD(string TitleName)
{
setTitle(TitleName);
}
void setRunningTime(int RunningTimeDetails)
{
RunningTime = RunningTimeDetails;
}
int getRunningTime()
{
return RunningTime;
}
void setDirector(string DirectorDetails)
{
Director = DirectorDetails;
}
string getDirector()
{
return Director;
}
void setStudio(string StudioDetails)
{
Studio = StudioDetails;
}
string getStudio()
{
return Studio;
}
void setProducer(string ProducerDetails)
{
Producer = ProducerDetails;
}
string getProducer()
{
return Producer;
}
void setDetails(string setDVDTitle, string setDVDAuthor, string setDVDReleaseDate, string setDVDCopyright, string setDVDGenre, string setDVDStatus, int setDVDRunningTime, string setDVDDirector, string setDVDStudio, string setDVDProducer)
{
setTitle(setDVDTitle);
setAuthor(setDVDAuthor);
setReleaseDate(setDVDReleaseDate);
setCopyright(setDVDCopyright);
setGenre(setDVDGenre);
setStatus(setDVDStatus);
setDirector(setDVDDirector);
setStudio(setDVDStudio);
setProducer(setDVDProducer);
}
void PrintDetails()
{
cout << "Title: " << getTitle() << endl;
cout << "Author: " << getAuthor() << endl;
cout << "Release Date: " << getReleaseDate() << endl;
cout << "Copyrite: " << getCopyright() << endl;
cout << "Genre: " << getGenre() << endl;
cout << "Status: " << getStatus() << endl;
cout << "Running Time: " << getRunningTime() << endl;
cout << "Director: " << getDirector() << endl;
cout << "Studio: " << getStudio() << endl;
cout << "Producer: " << getProducer() << endl;
}
private:
DVD();
int RunningTime;
string Director;
string Studio;
string Producer;
};
I am having trouble with the virtual void setDetails();
I am wanting both the Book and DVD class to have a method called setDetails to set the details. The problem is, both the Book class and the DVD class have different arguments for this method.
How can I achieve this?
How is the best way to solve this problem?
Since
only makes sense for a DVD object, and
only makes sense for a Book, the methods shouldn’t be
virtual, nor in the base class.Say I give you a
LibItem*and I tell you to set its details. What do you do? Does it make sense to set its details, since they differ from one concrete implementing class to another?The base class should only have the method that sets:
which shouldn’t be
virtual, since its behavior doesn’t change from implementation to implementation, and you should set specific details on the implementing classes themselves.