| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #include <iostream>
- #include <vector>
- #include <string>
- class Artwork {
- public:
- Artwork(const std::string& author, const std::string& title, int birthYear, const std::string& category)
- : author(author), title(title), birthYear(birthYear), category(category) {}
- virtual void displayInfo() const {
- std::cout << "Author: " << author << ", Title: " << title << ", Birth Year: " << birthYear << ", Category: " << category;
- }
- virtual ~Artwork() = default;
- private:
- std::string author;
- std::string title;
- int birthYear;
- std::string category;
- };
- class Painting : public Artwork {
- public:
- Painting(const std::string& author, const std::string& title, int birthYear, const std::string& category, const std::string& size)
- : Artwork(author, title, birthYear, category), size(size) {}
- void displayInfo() const override {
- Artwork::displayInfo();
- std::cout << ", Size: " << size;
- }
- private:
- std::string size;
- };
- class Music : public Artwork {
- public:
- Music(const std::string& author, const std::string& title, int birthYear, const std::string& category, const std::string& content)
- : Artwork(author, title, birthYear, category), content(content) {}
- void displayInfo() const override {
- Artwork::displayInfo();
- std::cout << ", Content: " << content;
- }
- private:
- std::string content;
- };
- class Chamber : public Music {
- public:
- Chamber(const std::string& author, const std::string& title, int birthYear, const std::string& content, int numPerformers)
- : Music(author, title, birthYear, "Chamber", content), numPerformers(numPerformers) {}
- void displayInfo() const override {
- Music::displayInfo();
- std::cout << ", Number of Performers: " << numPerformers;
- }
- private:
- int numPerformers;
- };
- int main() {
- std::vector<Artwork*> artworks;
- artworks.push_back(new Painting("Artist", "Painting", 2020, "Painting", "30x40"));
- artworks.push_back(new Music("Composer", "Music", 2021, "Music", "Symphony"));
- artworks.push_back(new Chamber("Composer", "Chamber", 2022, "Quartet", 4));
- for (const auto& artwork : artworks) {
- artwork->displayInfo();
- std::cout << std::endl;
- }
-
- for (const auto& artwork : artworks) {
- delete artwork;
- }
- return 0;
- }
|