Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Create class Books

+9 votes
asked Jun 14, 2019 by mark (450 points)
Create class Books, it should have private variable, title, size_h, size_w, number_of_pages and public variables year, author. Create also one public method getData() and constructor, which allows initialization of all variables of the class. In the main function, create two objects of the class. Use getData() method and return the title of the book, it’s height, width, number of pages, year of publishing (year) and author.

2 Answers

+1 vote
answered Aug 28, 2025 by Jerry Jeremiah (2,040 points)
+1 vote
answered Aug 29, 2025 by aasim shaheriya (170 points)
#include <iostream>

#include <string>

using namespace std;

class Books {

private:

    string title;

    float size_h;

    float size_w;

    int number_of_pages;

public:

    int year;

    string author;

    Books(string t, float h, float w, int pages, int y, string a) {

        title = t;

        size_h = h;

        size_w = w;

        number_of_pages = pages;

        year = y;

        author = a;

    }

    void getData() {

        cout << "Title: " << title << endl;

        cout << "Height: " << size_h << " units" << endl;

        cout << "Width: " << size_w << " units" << endl;

        cout << "Number of Pages: " << number_of_pages << endl;

        cout << "Year: " << year << endl;

        cout << "Author: " << author << endl;

    }

};

int main() {

    Books book1("The Great Gatsby", 8.0, 5.0, 218, 1925, "F. Scott Fitzgerald");

    Books book2("1984", 7.5, 4.5, 328, 1949, "George Orwell");

    cout << "Book 1 details:" << endl;

    book1.getData();

    cout << endl;

    cout << "Book 2 details:" << endl;

    book2.ge

tData();

    cout << endl;

    return 0;

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...