Book struct

Book Struct

Define a Book struct that includes the member variables: title, author, and page_count. Create an instance of the Book struct and assign its member variables with user input.

Hint

Steps

Answer

#include <iostream>
#include <string>

struct Book {
    std::string title;
    std::string author;
    int page_count;
};

int main() {
    Book myBook;

    std::cout << "Enter the title of the book: ";
    std::getline(std::cin, myBook.title);

    std::cout << "Enter the author of the book: ";
    std::getline(std::cin, myBook.author);

    std::cout << "Enter the page count of the book: ";
    std::cin >> myBook.page_count;

    std::cout << "Book Information:" << std::endl;
    std::cout << "Title: " << myBook.title << std::endl;
    std::cout << "Author: " << myBook.author << std::endl;
    std::cout << "Page Count: " << myBook.page_count << std::endl;

    return 0;
}
Questions