New Get Assignment Help - Upto 30% OFF*
Home/ TheTutorhelp
Tasks:
Introduction:
Using file handling with structure, a complex problem can be solved using the C programming language. But, at the time of growing data size; file size also increases. This can lead to excessive usage of memory. It also creates time and space complexity. So, in the case of growing data size, the file handling feature is fully inappropriate
In that case, the dynamic memory allocation technique is needed. So, when the data size increases, the dynamic memory allocation strategy using Link List is very much required to solve complex problems.
(a)
To design a library system for Kent Institute; the system can be divided into various modules like insert books, delete a particular book, search a specific book, view books according to ISBN code, issue a book and edit the record of a book.
Creating a book; the variables are chosen as, ISBN_code, title, author, category, price, quantity,date_receive, rackNo, issue. The different data types and ranges for the variables are:
Int ISBN_CODE; - It is a unique number
Char title [30] – It denotes the title of the Book so that it may be a maximum of 30 characters long.
Char author [30] - It represents the name of the Author for the book and can be a maximum of 30 characters long.
Char category [20]- It represents the book’s category like Literature, Engineering, Science,Comics, Story, etc.
Float price- It denotes the price for the book
Int quantity- It determines the quantity of the particular book.
Char date_receive[8]- It defines the date in dd/mm/yy format in which the datebook is received.
Int RackNo- It defines the particular Rack Number where the book is located.
Char issue- It defines whether the particular book is issued or not. Its value is ‘N' by default. When any book is issued, then it is updated as ‘Y.'
o implement the system in C programming using structure; the above variables, data types and ranges are the most appropriate option. The primary data types are chosen for the following causes,
The derived data types for the system are chosen as, array, structure and pointer. The data types and variables are used for the efficient utilization of memory. Each data type has a specific memory size in the C programming language. The smallest data type(s) and range(s) are chosen to match the type of appropriate data.
The various operations for the system can be divided as below,
Insert_ books () - This function displays various categories of books. After opening the file pointer and assigning the pointer to the end of the file; the user chooses a particular category and scans all records about a particular book from that category by the user.Then this record is appended at the end of the file.
Delete_book()- This functions accepts ISBN_code of a particular book from user. After opening the file pointer, it assigns to the beginning of the file. The ISBN_code is searched with records of the file's ISBN_code up to the end of the file. If the user's code is not matched, then message display as "Book is not found." If the record is matched, then all records are copied to another file except file pointer points that matched record. Then, the previous file is deleted and a new file is renamed as the previous one.
Delete_book()- This functions accepts ISBN_code of a particular book from user. After opening the file pointer, it assigns to the beginning of the file. The ISBN_code is searched with records of the file's ISBN_code up to the end of the file. If the user's code is not matched, then message display as "Book is not found." If the record is matched, then all records are copied to another file except file pointer points that matched record. Then, the previous file is deleted and a new file is renamed as the previous one.
Search_book()- This function takes ISBN from the user and opens the file pointer. After placing the file pointer at the beginning of the file, all records (ISBN) are searched with the user's ISBN from top to end of the file. This algorithm uses a linear search technique. After finding the record, the message is displayed otherwise message "Book is not found”is displayed
View-sorted-book ()- Using a simple Mergesort algorithm, the file would be sorted according to ISBN_code. After partitioning the file into f1 and f2; reading a block from each file. After taking the 1st record from each block and write those in sorted order in a new file named m1. This process is repeated from each block but writes into another file called m2. This process continues until f1 and f2 complete reading. So, m1 and m2 store ordered a pair of records. The above process is repeated and finally getting merge pair of records. At last, sorted records of length four is achieved. Two new files, m1 and m2, are merged into m to get the sorted records
Issue-book()- This process scans ISBN_code from user. Assign the pointer to the top of the file named, m (sorted records). The searching process continues up to end of the file using binary search technique. When the user's ISBN matches with file m's ISBN then accepts student's information and writes it into another file. The issue field of book structure is updated as ‘Y.' If the ISBN is not matched, then it displays the message "Sorry, that book is not available."
Edit_book()- This function accepts ISBN_code from user. After opening the file pointer and placing it into the m (sorted) file; the searching process begins using the Binary search technique to match the user's ISBN with m file's ISBN. If the record matches; accepts other file information like title, author, category, price, quantity, date_receive, RackNo, etc. from the user. In the current position of the file pointer, this record is overwritten. If the user’s ISBN is not found then an error message “Sorry Book is not found” is displayed. At last, close the file (Kanetkar, 2017).
(c)
Algorithm for Insert_ books ()
Step 1: file pointer declaration as FP
Step 2: various categories displayed
Step 3: User choices a category
Step 4: fp, the file pointer is opened in write mode
Step 5: fp is placed at the end of the file
Step 6: Scans all information of a book about particular category from user
Step 7: writes info into the end of the file
Step 8: closes fp
This algorithm is very efficient for time and space because records are inserted at the end of the file. There is no traversing of file pointer otherwise it is assigned at the end of the file.
Algorithm for Delete_book()-
This algorithm first searches the particular book from file whether it is present or not. If the record is present, then that particular record is deleted. Here, the searching process is done as per the linear search algorithm because the records are not in sorted order. So, in this case, the time complexity is larger if the record is at the end of the file.
Algorithm for Search_book()
As the records are stored into the file sequentially, then records are not in sorted order. So, this algorithm follows a linear searching technique. In case the record is found at the beginning of the file, the time complexity is smaller, the middle of the file, the time complexity is middle; otherwise, the time complexity will be larger.
Algorithm View-sorted-book ():
This algorithm is chosen as the Merge sort technique. From various sorting algorithms, this technique is chosen for the following causes,
Algorithm for Issue-book ()
Binary_search() algorithm
In this case, the binary search algorithm is followed as the records of the file are previously sorted and stored into m file.
This algorithm is faster than the linear search technique. When the records of the file are large,then this algorithm is very much efficient than linear search, but records should be in sorted order.
Algorithm for Edit_book()
(d)
The above system is implemented using File handling with structure. But, in the case of large data; efficient file handling is very complex, Storing, editing, retrieving, updating, searching and sorting procedures will be very complex in text files for a large amount of data. Operations will be complex and require lots of memory spaces during operations like deleting the previous file and renaming the new file, etc.
So, I recommend that the Link list implementation will be the best way for a large amount of data. For handling large data of the University; the link list is chosen in the following reasons,
Conclusion:
This system first implements the University Library Information system using file handling feature in C programming where Book record is considered within a structure. When a large University is considered where lots of data handling is needed, then this system is fully inappropriate.
In that case, the dynamic memory allocation procedure is taken into consideration. After taking the Link List concept, this problem is easily resolved where Book is taken as a node for the Link List.
References:
Books:
Balagurusamy. E 2018, Programming in ANSI C, the Tata McGraw-Hill Companies, New York Kanetkar. Y 2017, Let Us C, BPB Publications, Kolkata
Lipschutz .S 2018, Data Structures, the Tata McGraw-Hill Companies, New York
Journal Articles:
Karuna & Gupta G 2014, “Dynamic Implementation using Linked List.”, IJERMT, vol.1,no.5., pp.44-48.
Yadav K 2015, "Data File Handling in C++," IJIRT, Vol. 2, no.6, pp.326-329
Download full sampleHire us and you won't be disappointed! Your good grades are just a click away!
Get 30% Discount onAssignment Writing Help?