Structure for managing a book library
Swift
Medium
structs
Task «Structure for managing a book library»
Create a structure `Book` with fields `title` (String), `author` (String), `year` (Int), and `isAvailable` (Bool). Implement a structure `Library` containing an array of books. Write a function that takes a file name, reads a list of books from it (each line: title;author;year;availability (true/false)), adds them to the library, and then outputs a list of available books sorted by publication year (in ascending order). If there are no available books, output "No available books".
Input Format
First line: file name for reading. In the following lines of the file: each line contains book data separated by a semicolon: title;author;year;availability
Output Format
List of available books in the format: "title by author (year)", each on a new line. If there are no books, output "No available books".
Examples
Example 1
INPUT
books.txt
Война и мир;Толстой;1869;true
Преступление и наказание;Достоевский;1866;false
Мастер и Маргарита;Булгаков;1967;true
Евгений Онегин;Пушкин;1833;true
OUTPUT
Евгений Онегин by Пушкин (1833)
Война и мир by Толстой (1869)
Мастер и Маргарита by Булгаков (1967)
Example 2
INPUT
books.txt
Отцы и дети;Тургенев;1862;false
Герой нашего времени;Лермонтов;1840;false
OUTPUT
No available books
main.swift