Untitled

 avatar
unknown
plain_text
a year ago
2.0 kB
15
Indexable
#include <iostream>
#include <string>
#include <vector>

class Movie {
protected:
    std::string title;
    int year;
    std::string genre;

public:
    Movie(const std::string& title, int year, const std::string& genre) 
        : title(title), year(year), genre(genre) {}

    virtual void displayInfo() const {
        std::cout << "Title: " << title << std::endl;
        std::cout << "Year: " << year << std::endl;
        std::cout << "Genre: " << genre << std::endl;
    }

    virtual void play() const = 0;
};

class CDMovie : public Movie {
public:
    CDMovie(const std::string& title, int year, const std::string& genre) 
        : Movie(title, year, genre) {}

    void displayInfo() const override {
        std::cout << "CD Movie:" << std::endl;
        Movie::displayInfo();
    }

    void play() const override {
        std::cout << "Playing CD..." << std::endl;
    }

    void refer() const {
        std::cout << "Referencing CD..." << std::endl;
    }

    void lend() const {
        std::cout << "Lending CD..." << std::endl;
    }
};

class WebMovie : public Movie {
public:
    WebMovie(const std::string& title, int year, const std::string& genre) 
        : Movie(title, year, genre) {}

    void displayInfo() const override {
        std::cout << "Web Movie:" << std::endl;
        Movie::displayInfo();
    }

    void play() const override {
        std::cout << "Streaming online..." << std::endl;
    }

    void buy() const {
        std::cout << "Buying online movie..." << std::endl;
    }
};

int main() {
    CDMovie cdMovie("Inception", 2010, "Science Fiction");
    WebMovie webMovie("The Shawshank Redemption", 1994, "Drama");

    std::vector<Movie*> movies;
    movies.push_back(&cdMovie);
    movies.push_back(&webMovie);

    for (const auto& movie : movies) {
        movie->displayInfo();
        movie->play();
        std::cout << std::endl;
    }

    return 0;
}
Editor is loading...
Leave a Comment