Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming Image will explain what you need to do. There also a image of the books which will be used in the library. code

C programming

Image will explain what you need to do. There also a image of the books which will be used in the library. code is given but need to write more in "TO DO" section in the code. please read the description and follow the marking methods in the image below.

Description You will write a program that manages a small library of books. As a user you can borrow and return books. As a librarian you can oversee the whole collection of books. The program runs from a menu system that is already implemented. Details A zip file is available for download on Minerva. This will uncompress to a folder containing the source code. The basic structure of the code is provided. You have to implement the body of several functions (labelled TO DO: in the code). The code, as is, will compile and run but will simply print messages, without any effect. The application starts in the main() function in main.c and you can trace the code behaviour from there. You should make sure you understand the code structure and the data structures that are defined. The program specification You are provided with a skeleton code as a starting point. This code is modular and split across several source code and header files. A Makefile is provided that compiles the whole application. To build the application on linux type make on the command line in the source code folder. If you are using another platform or development environment (IDE) you will need to ensure you can create a single executable application from the code provided. (eg. you can create a C Project in CodeBlocks and add all the C source and header files). On linux, this will compile the executable into a sub-folder bin, which also contains a plain text file of book data. If you execute the code it will work as-is. You can run the code and it will print simple messages, but with no real functionality. You can add any further functions you require to complete the code. It is possible to complete this work without any extra functions. You should consider where to add them and how they interact with the code as a whole.

Marking The user interface works correctly (4 marks) Function main() (2 marks) Function initLibrary() (4 marks) Function readBooks() (4 marks) Function exitLibrary() (2 marks) Function listBooks() (2 marks) Function listBorrowedBooks() (3 marks) Function listAvailableB

Books

Frank Herbert Dune

Isaac Asimov I,Robot

William Gibson Neuromancer

Ray Bradbury Farenheit 451

Andy Weir The Martian

Neal Stephenson Snow Crash

Jeff Noon Vurt

main.c

#include #include #include

#include "libraryStructures.h" #include "library.h"

//// // Code module for main() // main function takes command line arguments // and opens the library menu // Input: book data filename via command line // Usage: ./library books.txt

int main( int argc, char **argv ) { char bookFile[40];

//TO DO : // check that correct number of command line arguments are entered // use the error message printf("Error Expected use: ./library books.txt "); // exit the application if there is an error

// assign command line value to filename string

// DO NOT ALTER // start the system printf(" Intialising library system! "); libraryCLI( bookFile ); printf(" Closing library system! ");

return 0; }

library.c

#include #include #include

#include "libraryStructures.h" #include "library.h" #include "user.h" #include "librarian.h" #include "utility.h"

//// // Code module for main library menu and file management // Reads the book and initialises the problem data

// Initialise library data // Input: // bookfile - name of book file // theLibrary - library data structure

void initLibrary( char *bookFile, Library *theLibrary ) {

theLibrary->maxBooks = 12; theLibrary->maxBorrowed = 4;

// TO DO : // dynamically allocate the bookList array for storing books // check the book file exists // use the error message and exit the program if it does not printf("Error Book file does not exist: %s ",bookFile); // open it if it exists

// use the readBooks function to read in the file and add the book records into the bookList array

// remember to close the file

// Initialise the User data

return; }

// Read in book file and create the books data structure // the book file is in a fixed format: // * book author // * book title // * blank line // Input: // books - file pointer to text input file // bookList - alocated array for storing Book structures // Output: // numBooks - number of books read

int readBooks( FILE *books, Book *bookList ) {

int numBooks = 0;

// TO DO: // read from the book file pointer // assign values to a Book structure in the bookList array for each complete record // read data until the file ends return numBooks; }

// Free any allocated library data // Input: // theLibrary - library data structure

void exitLibrary( Library *theLibrary ) {

// TO DO:

// free the allocated lists

return; }

// DO NOT ALTER THIS FUNCTION // Library menu system

void libraryCLI( char *bookFile ) { int libraryOpen = 1; int option;

// create the library structure Library *theLibrary = (Library *)malloc( sizeof(Library) );

initLibrary( bookFile, theLibrary ); while( libraryOpen ){ printf(" Main menu options 1 User login 2 Librarian login 3 Exit system Choice:"); option = optionChoice();

if( option == 1 ) { printf(" User login "); userCLI( theLibrary ); } else if( option == 2 ) { printf(" Librarian login "); librarianCLI( theLibrary ); } else if( option == 3 ) { libraryOpen = 0; printf(" Closing "); } else printf(" Unknown option "); }

exitLibrary( theLibrary );

// free the library structure free( theLibrary );

return; }

librarian.c

#include #include

#include "libraryStructures.h" #include "librarian.h" #include "utility.h"

//// // Code module for librarian // They can list the books and see what is borrowed

// List the borrowed books on the screen // Format should be "author - title" on each line

void listBorrowedBooks( Book *bookList, int numBooks ) {

// TO DO : // // list the books in format "name - title" return; }

// List the books on the screen // Format should be "author - title" on each line

void listBooks( Book *bookList, int numBooks ) {

// TO DO : // // list the books in format "name - title" return; }

// DO NOT ALTER THIS CODE

// Menu system for the librarian

void librarianCLI( Library *theLibrary ) { int librarianLoggedIn = 1; int option;

while( librarianLoggedIn ){ printf(" Librarian options 1 List books 2 List borrowed books 3 Log out Choice:"); option = optionChoice();

if( option == 1 ) { printf(" List of books: "); listBooks( theLibrary->bookList, theLibrary->numBooks ); } else if( option == 2 ) { printf(" List of borrowed books: "); listBorrowedBooks( theLibrary->bookList, theLibrary->numBooks ); } else if( option == 3 ) { librarianLoggedIn = 0; printf(" Logging out "); } else printf(" Unknown option "); } return; }

utility.c

#include #include #include

#include "utility.h"

//// // Utility functions to handle "safer" string input //

// DONT ALTER THESE FUNCTIONS

// read in a line of text and convert to an integer option

int optionChoice( void ) { int option = -1; char line[80];

// read in the current line as a string fgets(line,80,stdin);

// atoi() converts string to integer, returns 0 if could not convert option = (int)atoi(line);

return option; }

// remove newline character from the fgets() input

void removeNewLine(char* string) {

size_t length = strlen(string);

if((length > 0) && (string[length-1] == ' ')) { string[length-1] ='\0'; } return; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago