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

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

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.

212: Build a class representing a university student with private data members for name, ID, and a static data member for the total number of students. Implement getter and setter functions for name and ID, and a static getter function to retrieve the total number of students. Use default constructors