Untitled

 avatar
unknown
plain_text
a year ago
779 B
4
Indexable
#include <iostream>
#include <string>

class Book {
public:
    // Constructor
    Book(std::string title, std::string author, int year) {
        this->title = title;
        this->author = author;
        this->year = year;
    }

    // Member function to print book details
    void printDetails() {
        std::cout << "Title: " << title << std::endl;
        std::cout << "Author: " << author << std::endl;
        std::cout << "Year: " << year << std::endl;
    }

private:
    std::string title;
    std::string author;
    int year;
};

int main() {
    // Create a Book object using the constructor
    Book book1("The Great Gatsby", "F. Scott Fitzgerald", 1925);

    // Call the printDetails function to print book details
    book1.printDetails();

    return 0;
}