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

88: Using switch statement Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following: // Percentage >= 90% : Grade A Percentage >= 80% : Grade B Percentage >= 70% : Grade C Percentage >= 60% : Grade D Percentage >= 40% : Grade E Percentage < 40% : Grade F

15: Take input of age and name of 3 people by user and determine oldest and youngest among them with his age. -_-_-_-_-_-_-_-_-(line with spaces input concept)-_-_-_-_-_-_-_-_