Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
3.7 kB
4
Indexable
Never
// Movie.h
#ifndef MOVIE_H
#define MOVIE_H

#include <string>

class Movie {
protected:
    std::string title;
    std::string genre;
    int year;
    float rating;
    int status; // 0: available, 1: lent, 2: lost
public:
    Movie(const std::string& title, const std::string& genre, int year, float rating);
    virtual void DisplayDetails() const;
    virtual bool IsAvailable() const;
    virtual void Lend();
    virtual void Return();
    virtual void Lost();
};

class CDMovies : public Movie {
private:
    std::string refer;
public:
    CDMovies(const std::string& title, const std::string& genre, int year, float rating, const std::string& refer);
    void Refer(const std::string& reference);
    virtual void Lend() override;
};

class WebMovies : public Movie {
private:
    std::string url;
    int validDays;
public:
    WebMovies(const std::string& title, const std::string& genre, int year, float rating, const std::string& url, int validDays);
    void Buy();
};

#endif // MOVIE_H



// Movie.cpp
#include "Movie.h"
#include <iostream>

Movie::Movie(const std::string& title, const std::string& genre, int year, float rating)
    : title(title), genre(genre), year(year), rating(rating), status(0) {}

void Movie::DisplayDetails() const {
    std::cout << "Title: " << title << ", Genre: " << genre << ", Year: " << year << ", Rating: " << rating << std::endl;
}

bool Movie::IsAvailable() const {
    return status == 0;
}

void Movie::Lend() {
    if (status == 0) {
        status = 1;
        std::cout << "Movie '" << title << "' has been lent." << std::endl;
    } else {
        std::cout << "Movie '" << title << "' is not available for lending." << std::endl;
    }
}

void Movie::Return() {
    if (status == 1) {
        status = 0;
        std::cout << "Movie '" << title << "' has been returned." << std::endl;
    } else {
        std::cout << "Movie '" << title << "' was not lent." << std::endl;
    }
}

void Movie::Lost() {
    if (status == 1) {
        status = 2;
        std::cout << "Movie '" << title << "' has been marked as lost." << std::endl;
    } else {
        std::cout << "Movie '" << title << "' was not lent." << std::endl;
    }
}

CDMovies::CDMovies(const std::string& title, const std::string& genre, int year, float rating, const std::string& refer)
    : Movie(title, genre, year, rating), refer(refer) {}

void CDMovies::Refer(const std::string& reference) {
    refer = reference;
}

void CDMovies::Lend() {
    if (status == 0) {
        status = 1;
        std::cout << "CD Movie '" << title << "' has been lent." << std::endl;
    } else {
        std::cout << "CD Movie '" << title << "' is not available for lending." << std::endl;
    }
}

WebMovies::WebMovies(const std::string& title, const std::string& genre, int year, float rating, const std::string& url, int validDays)
    : Movie(title, genre, year, rating), url(url), validDays(validDays) {}

void WebMovies::Buy() {
    std::cout << "You bought the web movie '" << title << "' with URL: " << url << std::endl;
}



// main.cpp
#include "Movie.h"

int main() {
    Movie movie("Inception", "Sci-Fi", 2010, 8.8);
    movie.DisplayDetails();
    movie.Lend();
    movie.Lend();
    movie.Return();
    movie.Lost();
    
    CDMovies cdMovie("Interstellar", "Sci-Fi", 2014, 8.6, "CD-1234");
    cdMovie.DisplayDetails();
    cdMovie.Lend();
    cdMovie.Return();
    
    WebMovies webMovie("The Matrix", "Action", 1999, 8.7, "www.example.com/thematrix", 30);
    webMovie.DisplayDetails();
    webMovie.Buy();
    
    return 0;
}
Leave a Comment