#include <iostream>
#include <string>
using namespace std;
// Base class
class Media {
protected:
string title;
double duration;
public:
Media(string t, double d) : title(t), duration(d) {}
virtual void display() const {
cout << "Title: " << title << "\nDuration: " << duration << " minutes" << endl;
}
};
// Subclass: Song
class Song : public Media {
private:
string artist, genre;
public:
Song(string t, double d, string a, string g)
: Media(t, d), artist(a), genre(g) {}
void display() const override {
Media::display();
cout << "Artist: " << artist << "\nGenre: " << genre << endl;
}
};
// Subclass: Podcast
class Podcast : public Media {
private:
string episode;
public:
Podcast(string t, double d, string e)
: Media(t, d), episode(e) {}
void display() const override {
Media::display();
cout << "Episode: " << episode << endl;
}
};
int main() {
// Stack-allocated objects
Song song("Imagine", 3.5, "John Lennon", "Pop");
Podcast podcast("Tech Talks", 45.0, "Episode 12: AI Trends");
// Directly call display() for each object
song.display();
cout << "-------------------" << endl;
podcast.display();
cout << "-------------------" << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gQmFzZSBjbGFzcwpjbGFzcyBNZWRpYSB7CnByb3RlY3RlZDoKICAgIHN0cmluZyB0aXRsZTsKICAgIGRvdWJsZSBkdXJhdGlvbjsKCnB1YmxpYzoKICAgIE1lZGlhKHN0cmluZyB0LCBkb3VibGUgZCkgOiB0aXRsZSh0KSwgZHVyYXRpb24oZCkge30KCiAgICB2aXJ0dWFsIHZvaWQgZGlzcGxheSgpIGNvbnN0IHsKICAgICAgICBjb3V0IDw8ICJUaXRsZTogIiA8PCB0aXRsZSA8PCAiXG5EdXJhdGlvbjogIiA8PCBkdXJhdGlvbiA8PCAiIG1pbnV0ZXMiIDw8IGVuZGw7CiAgICB9CgogIAp9OwoKLy8gU3ViY2xhc3M6IFNvbmcKY2xhc3MgU29uZyA6IHB1YmxpYyBNZWRpYSB7CnByaXZhdGU6CiAgICBzdHJpbmcgYXJ0aXN0LCBnZW5yZTsKCnB1YmxpYzoKICAgIF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