Close.
Remember the derived class inherits from the base class. Therefore, the derived class does not have any data members that duplicate data members in the base class.
In your case, the base class Publication does not have an ISBN member because not all publications have an ISBN. Only books do. The same applies to author. So remove these from the base class:
- Class publication
-
-
{
-
public:
-
char title [30];
-
char editor [30];
-
char publisher [30];
-
};
The book class does not need title, editor or publisher because title and publisher are inherited from publication. Books don't have editors so now editor needs to be removed from publication. Now things look like:
- Class publication
-
-
{
-
public:
-
char title [30];
-
char publisher [30];
-
};
-
-
class book: public publication
-
-
{
-
private:
-
-
char author [30];
-
char ISBN [20];
-
};
-
-
Finally, the magazine class has an editor, a title, and a publisher. The title and the publisher come from the publication class and the editor becomes a member of the magazine class:
- class magazine: public publication
-
-
{
-
private:
-
char editor [30];
-
};
-
You should be able to see that there are no duplications of data members and that each class either has the data or inherits the data it needs.
Does any of this make sense to you?