Starting from:
$35

$29

Computer Programming Laboratory Lab #10 Solution


Write a single program which realizes following tasks respectively.

    1. You should write a small library and a program in C programming language.

        ◦ The library should use a struct called ‘Book’. This struct should keep three strings (for title, author and subject of a book), and an integer (for identification and publication year of a book).

        ◦ The program should keep these records for books in a struct array named Books that is allocated dynamically.

        ◦ If the array is full, increase the size of the array so you can add new books.

        ◦ The program will have a menu as shown in Figure 1. You should design the menus as shown in the figure.

        ◦ If the user entered an invalid option, print the message "TRY AGAIN" on the screen, and let them return to the menu again. The program continues until the user select "EXIT" option. If the user chooses the "EXIT SUBMENU" option while in the submenu, it is routed back to the main menu.

        ◦ Figure 2 shows how the user adds a new book.

        ◦ If the user selects the 2nd option in the Main menu, the user is routed to the submenu.



















Figure 1. Menu Types    Figure 2. Add New Book Screen


    • Figure 3 shows the result of the searched book from the list of books according to the title of the book. Likewise, it allows you to bring 1 book according to the features given in other options. If the user enters an incorrect input, handle it and redirect them back to the menu.

    • Figures 5 and 6 show the list of books. In option 5, you must first sort the books by year in descending order. Then you have to return the list. In the 6th option, you should sort the books in ascending order according to the book_id value, in other words, according to the order in which they are registered in the system. Other rules also apply in these cases.













Figure 3. Search Book by Title    Figure 4. Search Book by Author























Figure 5. List of books sorted by year    Figure 6. List of books sorted by book_id



General rules:

    • You are not allowed to use any library other than;
        ◦ <stdio.h>

        ◦ <string.h>
        ◦ <stdlib.h>

    • You cannot use realloc() or malloc() for dynamic allocation operation. You can only use calloc().
    • If there is more than one match while performing any search, select the first one.

    • You can write your own functions to make things easier.
    • Don’t forget that the program shouldn’t terminate when an operation is done.

    • You can use other variables, arrays etc. to make things easier.

    • To read a string which includes spaces, use following codes:


fflush(stdin);
scanf("%[^\n]%*c", string);

More products