205: Book Catalog: Define a struct to represent a book with attributes like title, author, and publication year. Write a program to create a catalog of books by taking user input and display books published after a certain year.

 

// Book Catalog: Define a struct to represent a book with attributes like title, author, and publication year.
// Write a program to create a catalog of books by taking user input and display books published after a certain year.

#include <iostream>
using namespace std;
struct Books
{
    string title, author;
    int year;
};
Books new_book();
void print_book(int i, Books x[]);

int main()
{
    int num;
    cout << "Enter the total number of books: ";
    cin >> num;
    // const int total = num;
    Books book[num];

    for (int i = 0; i < num; i++)
    {
        book[i] = new_book();
    }

    system("cls");
    int year;
    cout << "Enter the year: ";
    cin >> year;

    cout << "\nEvery book published before " << year << " are: \n";

    for (int i = 0; i < num; i++)
    {
        if (book[i].year < year)
        {
            print_book(i, book);
        }
    }

    return 0;
}

Books new_book()
{
    system("cls");
    Books x;
    cout << "Enter the name of the book: ";
    getline(cin >> ws, x.title);
    cout << "Enter the author of the book: ";
    getline(cin >> ws, x.author);
    cout << "Enter the year of publication: ";
    cin >> x.year;
    return x;
}
void print_book(int i, Books x[])
{
    cout << endl
         << "Book name: " << x[i].title << endl;
    cout << "Book author: " << x[i].author << endl;
    cout << "Publication year: " << x[i].year << endl;
}


Comments

Popular posts from this blog

153: Write a program to read an amount (integer value) and break the amount into smallest possible number of bank notes. Note: The possible banknotes are 500, 100, 50, 20, 10, 5, 2, and 1

206: Write a program to create a class named "Circle" which has the property "radius". Define functions to calculate the area and circumference of the circle.

221: // In Task 2, we discussed multilevel inheritance with parameterized constructors for Student, UndergraduateStudent, and GraduateStudent classes in a university management system. Can you explain the advantages of using multilevel inheritance with specific details about the functions and data members in these classes? How were the parameterized constructors (e.g., setting student name, age, and ID) used to ensure that each class in the hierarchy correctly initializes its properties, such as creating an UndergraduateStudent named "John," aged 20, with a student ID of 12345