In the periodical derived class, i want to be able to output title and publisher on the base class publication where i output the description, how can i do that?
Code:
#include <iostream.h>
#include <string.h>
class publication {
char title[60];
char publisher[40];
public:
publication(char* t, char* p) {strcpy(title, t); strcpy(publisher,p);}
virtual void out(ostream &os) const { os << "Publication: " << title << "\n" << "Published by " << publisher << endl; }
};
ostream &operator<<(ostream &os, const publication &x) {
x.out(os);
return os;
}
class periodical : public publication {
char description[20];
public:
periodical(char* t, char* p, char* d) : publication(t,p) {strcpy(description, d);}
void out(ostream &os) const { os << "Published " << description << endl;}
};
int main() {
publication *p[3];
p[0] = new publication("OOP244 Notes", "Seneca College");
p[1] = new periodical("Toronto Sun", "Southam News", "Daily");
/*p[2] = new book("21 Days to a Better You", "Prentice Hall",
"Joseph Noodlemeyer", "1-234-5546-3");*/
for (int i=0; i < 3; i++) {
cout << *p[i] << '\n';
delete p[i];
}
return 0;
}