SlideShare a Scribd company logo
1 of 15
1
Objectives
Gain hands on experience with programming C.
To Practice the following:
Dynamic memory allocation, handle file IO, loops, setup
and use of data structures, and function decomposition.
Submission details
You must only submit (using the submit command on latcs5) An
electronic copy of the code (There is NO hardcopy to be
handed-in)
See the end of this document for more details
This is an individual assignment. You are not permitted to
work as a part of a group when writing this assignment.
Copying, Plagiarism
Plagiarism is the submission of somebody else’s work in a
manner that gives the impression that the work is your own.
For individual assignments, plagiarism includes the case where
two or more students work collaboratively on the assignment.
The Department of Computer Science and Computer
Engineering treats plagiarism very seriously. When it is
detected, penalties are strictly imposed.
Please Note:
While you are free to develop the code for this assignment on
any operating system, your solution (C code) must compile and
run on the latcs5 system using the cc (or by using gcc)
compiler. Code that does not run on the latcs5 system will
receive zero marks for implementation.
Delays caused by computer downtime cannot be accepted as a
valid reason for late submission without penalty. Students must
plan their work to allow for both scheduled and unscheduled
downtime.
Given resources
On lms you will see 3 files:-
1. CES_assignment-13.doc ( This document
2. AssignTemplate.c ( the source code template to start coding
in
3. sample_input.txt ( This is the sample input file which
contains the details of a number of books currently in the
“library”. {For a complete explanation of what each entry is see
task 2}
Programming Task
Implement a menu driven library catalogue system that allows
users to perform various catalogue maintenance tasks. You are
only allowed to use the C programming language. You are not
allowed to use C++.
Please do not use global variables. Up to 50% of marks will be
lost for assignments that use global variables.
Please do functional decomposition. Up to 50% of marks will
be lost for students who try to write the entire program in one
main function or something similar. There should be at least 5
functions for the assignment. One function for each task 2 to 4.
Two functions for task 5. More functions than 5 is also highly
recommended. The aim of this rule is to teach you how to pass
pointer arguments into functions.
The assignment has been broken up into 5 tasks.
Task 1 [10 marks code correctness]
The program should be menu driven. The user should be
presented with the following menu:
1. Load catalogue from file
2. Save catalogue to file
3. Display catalogue
4. Find book from catalogue
5. Quit
After selecting one of the above options the corresponding task
should be performed. After completing the selected task, the
menu should be displayed again for the user to choose again
unless the 5th option is chosen.
Task 2 [26 marks code correctness]
Implement the load catalogue from file menu option. After
selecting this option the user should be asked to enter the name
of a file to be loaded. The file should then be loaded into an
array of structures. The array of structures should have been
declared in the main function before the load catalogue function
was called. To get full marks for this task you should use run-
time (dynamically) allocated memory for the array of structures.
If you use static memory allocation you will lose 5 marks. You
can assume the file will have the following format.
[Number of books]
[Title of book]
[Author first name], [Author surname]
[Year of publication]
[Replacement cost]
…
…
[Title of book]
[Author first name], [Author surname]
[Year of publication]
[Replacement cost]
{The … above represents intermediate catalogue entries.}
Here is an explanation of the above fields:
[Number of books] - This is the number of book entries
stored in the file
[Title of book] – A string specifying the title of the book, the
string may contain spaces.
[Author First name], [Author Surname] – Two strings which do
not contain spaces but
are separated by a
comma followed by a space.
[Year of publication] - A number specifying the year that the
book was published
[Replacement cost] - Cost of replacing a book, it may contain a
decimal point.
Below is an example of a catalogue file that contains 2 books:
2
C for beginners
Peter, Kernighan
1999
102.50
XML data Management
Amit, Chandhri
2005
122.30
One way to copy the sample file (sample_input.txt) from
windows i7 into a putty session is to;_
1. opened vi with an appropriate file name,
2. Immediately issue the command in vi :set paste /*then press
return*/
3. Then enter insert mode by pressing i
4. Having opened sample_input.txt in notepad on windows
a. Highlight ALL the data there
b. Move pointer over putty, left click to activate putty, then
c. Right click to put data there.
5. It will now appear as follows:-
{The vi “page” on putty:-}
6
Cpp for beginners
Peter, Kernighan
1999
102.5
CPP FOR Beginners
Peter, Kernighan
1999
102.5
CPP FOR Beginners
PeTer, KerNIghan
2001
101.5
XML data Management
Amit, Chandhri
2005
122.3
PHP for the world wide web
William, Hope
2004
202.4
Computer networks
Andrew, Tanenbaum
2004
291.1
You can now save this in vi as usual and commence
programming; treating this file as if you had written it!!
Task 3 [12 marks code correctness]
Implement the save catalogue to file menu option. After
selecting this option the user should be asked to specify the
name of the save file. All the book catalogue data should be
stored onto the specified file in the same format as the file
loaded in Task 2.
Task 4 [12 marks code correctness]
Implement the display catalogue menu option.
All the attributes of the books should be displayed as follows:
Number of books in catalogue = [number of books]
---------------------------------------------------------------
Title: [title of book]
Author: [first name of author] [surname of author]
Year of publication: [year of publication]
Replacement cost: $[cost of replacement]
---------------------------------------------------------------
....
....
---------------------------------------------------------------
Title: [title of book]
Author: [first name of author] [surname of author]
Year of publication: [year of publication]
Replacement cost: $[cost of replacement]
---------------------------------------------------------------
Note: [title of book] [first name of author] [surname of author]
[year of publication]
[cost of replacement] have the same meaning as those for task
2.
Here is an example output:
Number of books in catalogue = 2
---------------------------------------------------------------
Title: C for beginners
Author: Peter Smith
Year of publication: 1999
Replacement cost: $102.50
---------------------------------------------------------------
Title: Java programmers hand book
Author: John Edwards
Year of publication: 2003
Replacement cost: $105.20
---------------------------------------------------------------
Task 5 [15 marks code correctness]
Implement the search book from catalogue menu option. After
selecting this option the user should be asked to specify the
book using the following sub-menu:
1. Specify book title
2. Specify author first name
3. Specify author last name
After choosing one of the above sub-menu options, the user
should be asked to type in a string to be used for finding the
book. Note the string has to completely match the relevant
book attribute. Partial match is not considered a match.
In the following example the user strings does not match the
corresponding books:
User types in for book title: Cforbeginners
Actual book title: C for beginners
User types in for author first name: peters
Actual book author first name: peter
User types in for author surname: peter
Actual book author surname: peterson
The search should be case insensitive. Therefore the following
does match:
User types in for author first name: peter
Actual book author first name: peTer
User types in for book title: c for beginners
Actual book title: C For Beginners
The matching books found should be displayed onto the screen
in the same format as task 4. If more than one matching book is
found then all matching books should be displayed.
Bonus Task [10 marks code correctness]
If you want bonus 10 marks for your assignment and are ready
for a challenge then you can implement an extra option to the
menu. This is the “Delete books” menu option. Once the user
selects this option then he/she ill be asked to do the same as
task 5 except the matching books found are first displayed and
then deleted from memory. To get the marks for this task the
memory for your array of structures must have been allocated
using dynamic memory allocation in Task 2. Here you will
need to delete that array of structures and create a new smaller
one that exactly fits the remaining (non-deleted) books. Note
if the search matches more than one book than all the matched
books will need to be deleted.
Marking Scheme
The assignment will be marked as follows:
1. Correct execution 75 marks
2. Coding style 25 marks
3. Bonus task
10 marks
1. Coding style will be marked according to the following
criteria:
- Use of comments
- Quality of functional decomposition.
- Algorithm design
2. A student can not get more than 100 marks. Therefore a
student who gets everything correct and also does the bonus
task will still only get 100 marks not 110. However, it is still a
good idea to do the bonus task since you are likely to lose some
marks somewhere in your program.
Submission Details
· Your program has to run under Unix on the latcs5 or latcs6
machine. System-specific code should not be used in your
program, as we emphasize use of portable C. Code that does not
compile or run on latcs5/6 will not be marked.
· Please ensure that your name and student number is on every
file that you submit.
· You are to submit your files from your latcs5 account. Make
sure you are in the same directory as the one containing these
files. Type the following commands at the Unix prompt
(ensuring that CES is in uppercase):
> submit CES <filename>
where <filename> is the actual complete name of your file.
DO NOT submit any executable files instead submit your source
code files only, that is, your progfilename.c. This is so your
code (( source code) can be compiled by an examiner in
latcs5/latcs6.
{Where progfilename is the filename you have given to your
source code.}
After submitting the files, the following command will list the
files submitted from your account:
> verify
You can submit the same filename as many times as you like
before the assignment deadline; the previously submitted copy
will be replaced by the latest one.
Emailing your code will not be accepted and will result in a
mark of 0 being awarded for the assignment. Only those
assignments that have been correctly submitted using the above
“>submit ….” process will be accepted for assessment. There
are no exceptions.
#include <stdio.h>
#include <stdlib.h>
struct book_type {
// You need to fill in your struct here
};
// This function loads a catalogue of books from a user specified
file name.
// Note you need to use malloc inside this function to allocate
the memory
// needed for the catalogue of books.
// After catalogue is allocated and filled up with books loaded
from the file,
// it is returned back to the main program via the book_type *
return type.
// The pointer parameter numBooks is used to pass the number
of books back
// out to the numBooks variable in the main function. This way
the other
// functions will be able to use this variable to find how many
books
// are stored in the catalogue.
struct book_type * loadCatalogue(int * numBooks);
// This function saves catalogue into a user specified text file
void saveCatalogue(struct book_type * bCatalogue, int
numBooks);
// This function displays the catalogue onto the screen.
void displayCatalogue(struct book_type * bCatalogue, int
numBooks);
// This function finds a user specified book or set of books and
displays them
void findBook(struct book_type * bCatalogue, int numBooks);
// Important questions for you to consider:
// ** Why are the parameters for the loadCatalogue function so
different
// from the other functions? Please explain the difference in
detail. ***
// This question is not part of the assignment requirements,
but it is
// something that you should be able to answer since it is
important
// knowledge.
int main() {
struct book_type * bookCatalogue;
int numBooks;
// Write a loop which continuously asks the user to choose one
of
// the following options until the quit option is selected:
// 1. Load catalogue from file
// 2. Save catalogue to file
// 3. Display catalogue
// 4. Find book from catalogue
// 5. Quit
//
// Use a switch statement to handle the different user choices.
// In the case that load catalogue is chosen you should call
the
// loadCatalogue function as follows:
// bookCatalogue = loadCatalogue(&numBooks);
//
// In the case that save catalogue is chosen you should call
the
// saveCatalogue function as follows:
// saveCatalogue(bookCatalogue, numBooks);
//
// It is up to you to work out how and when to call the other
functions.
}
C Programming Assignment - Library Catalogue System

More Related Content

Similar to C Programming Assignment - Library Catalogue System

Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docx
Assignment 1  Hypothetical Machine SimulatorCSci 430 Int.docxAssignment 1  Hypothetical Machine SimulatorCSci 430 Int.docx
Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docxjane3dyson92312
 
Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7ashhadiqbal
 
asgmt01.classpathasgmt01.project asgmt01 .docx
asgmt01.classpathasgmt01.project  asgmt01  .docxasgmt01.classpathasgmt01.project  asgmt01  .docx
asgmt01.classpathasgmt01.project asgmt01 .docxfredharris32
 
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docxOverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docxhoney690131
 
matmultHomework3.pdfNames of Files to Submit matmult..docx
matmultHomework3.pdfNames of Files to Submit  matmult..docxmatmultHomework3.pdfNames of Files to Submit  matmult..docx
matmultHomework3.pdfNames of Files to Submit matmult..docxandreecapon
 
LMP1 IO and Filesystems=========================Welcome .docx
LMP1 IO and Filesystems=========================Welcome .docxLMP1 IO and Filesystems=========================Welcome .docx
LMP1 IO and Filesystems=========================Welcome .docxmanningchassidy
 
CS 112 PA #4Like the previous programming assignment, this assignm.docx
CS 112 PA #4Like the previous programming assignment, this assignm.docxCS 112 PA #4Like the previous programming assignment, this assignm.docx
CS 112 PA #4Like the previous programming assignment, this assignm.docxannettsparrow
 
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdflailoesakhan
 
Car removal gold coast
Car removal gold coastCar removal gold coast
Car removal gold coastanaferral
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comStephenson22
 
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comWilliamsTaylorza48
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxRohitKumar639388
 
srt311 Project2
srt311 Project2srt311 Project2
srt311 Project2trayyoo
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.comHarrisGeorg12
 
Assignment2 A
Assignment2 AAssignment2 A
Assignment2 AMahmoud
 

Similar to C Programming Assignment - Library Catalogue System (19)

Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docx
Assignment 1  Hypothetical Machine SimulatorCSci 430 Int.docxAssignment 1  Hypothetical Machine SimulatorCSci 430 Int.docx
Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docx
 
Database Management Assignment Help
Database Management Assignment Help Database Management Assignment Help
Database Management Assignment Help
 
Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7
 
a3.pdf
a3.pdfa3.pdf
a3.pdf
 
asgmt01.classpathasgmt01.project asgmt01 .docx
asgmt01.classpathasgmt01.project  asgmt01  .docxasgmt01.classpathasgmt01.project  asgmt01  .docx
asgmt01.classpathasgmt01.project asgmt01 .docx
 
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docxOverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
 
matmultHomework3.pdfNames of Files to Submit matmult..docx
matmultHomework3.pdfNames of Files to Submit  matmult..docxmatmultHomework3.pdfNames of Files to Submit  matmult..docx
matmultHomework3.pdfNames of Files to Submit matmult..docx
 
LMP1 IO and Filesystems=========================Welcome .docx
LMP1 IO and Filesystems=========================Welcome .docxLMP1 IO and Filesystems=========================Welcome .docx
LMP1 IO and Filesystems=========================Welcome .docx
 
CS 112 PA #4Like the previous programming assignment, this assignm.docx
CS 112 PA #4Like the previous programming assignment, this assignm.docxCS 112 PA #4Like the previous programming assignment, this assignm.docx
CS 112 PA #4Like the previous programming assignment, this assignm.docx
 
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
 
Car removal gold coast
Car removal gold coastCar removal gold coast
Car removal gold coast
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.com
 
Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.com
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Imd 203 Questions
Imd 203 QuestionsImd 203 Questions
Imd 203 Questions
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
 
srt311 Project2
srt311 Project2srt311 Project2
srt311 Project2
 
Cmis 102 Effective Communication / snaptutorial.com
Cmis 102  Effective Communication / snaptutorial.comCmis 102  Effective Communication / snaptutorial.com
Cmis 102 Effective Communication / snaptutorial.com
 
Assignment2 A
Assignment2 AAssignment2 A
Assignment2 A
 

More from hyacinthshackley2629

Your company nameYour nameInstruction Page1. O.docx
Your company nameYour nameInstruction Page1. O.docxYour company nameYour nameInstruction Page1. O.docx
Your company nameYour nameInstruction Page1. O.docxhyacinthshackley2629
 
Your Company NameYour Company NameBudget Proposalfor[ent.docx
Your Company NameYour Company NameBudget Proposalfor[ent.docxYour Company NameYour Company NameBudget Proposalfor[ent.docx
Your Company NameYour Company NameBudget Proposalfor[ent.docxhyacinthshackley2629
 
Your company recently reviewed the results of a penetration test.docx
Your company recently reviewed the results of a penetration test.docxYour company recently reviewed the results of a penetration test.docx
Your company recently reviewed the results of a penetration test.docxhyacinthshackley2629
 
Your company wants to explore moving much of their data and info.docx
Your company wants to explore moving much of their data and info.docxYour company wants to explore moving much of their data and info.docx
Your company wants to explore moving much of their data and info.docxhyacinthshackley2629
 
Your company plans to establish MNE manufacturing operations in Sout.docx
Your company plans to establish MNE manufacturing operations in Sout.docxYour company plans to establish MNE manufacturing operations in Sout.docx
Your company plans to establish MNE manufacturing operations in Sout.docxhyacinthshackley2629
 
Your company just purchased a Dell server MD1420 DAS to use to store.docx
Your company just purchased a Dell server MD1420 DAS to use to store.docxYour company just purchased a Dell server MD1420 DAS to use to store.docx
Your company just purchased a Dell server MD1420 DAS to use to store.docxhyacinthshackley2629
 
your company is moving to a new HRpayroll system that is sponsored .docx
your company is moving to a new HRpayroll system that is sponsored .docxyour company is moving to a new HRpayroll system that is sponsored .docx
your company is moving to a new HRpayroll system that is sponsored .docxhyacinthshackley2629
 
Your company is considering the implementation of a technology s.docx
Your company is considering the implementation of a technology s.docxYour company is considering the implementation of a technology s.docx
Your company is considering the implementation of a technology s.docxhyacinthshackley2629
 
Your company is a security service contractor that consults with bus.docx
Your company is a security service contractor that consults with bus.docxYour company is a security service contractor that consults with bus.docx
Your company is a security service contractor that consults with bus.docxhyacinthshackley2629
 
Your company has just sent you to a Project Management Conference on.docx
Your company has just sent you to a Project Management Conference on.docxYour company has just sent you to a Project Management Conference on.docx
Your company has just sent you to a Project Management Conference on.docxhyacinthshackley2629
 
Your company has designed an information system for a library.  The .docx
Your company has designed an information system for a library.  The .docxYour company has designed an information system for a library.  The .docx
Your company has designed an information system for a library.  The .docxhyacinthshackley2629
 
Your company has had embedded HR generalists in business units for t.docx
Your company has had embedded HR generalists in business units for t.docxYour company has had embedded HR generalists in business units for t.docx
Your company has had embedded HR generalists in business units for t.docxhyacinthshackley2629
 
Your company You are a new Supply Chain Analyst with the ACME.docx
Your company   You are a new Supply Chain Analyst with the ACME.docxYour company   You are a new Supply Chain Analyst with the ACME.docx
Your company You are a new Supply Chain Analyst with the ACME.docxhyacinthshackley2629
 
Your company has asked that you create a survey to collect data .docx
Your company has asked that you create a survey to collect data .docxYour company has asked that you create a survey to collect data .docx
Your company has asked that you create a survey to collect data .docxhyacinthshackley2629
 
Your Communications PlanDescriptionA.What is your .docx
Your Communications PlanDescriptionA.What is your .docxYour Communications PlanDescriptionA.What is your .docx
Your Communications PlanDescriptionA.What is your .docxhyacinthshackley2629
 
Your community includes people from diverse backgrounds. Answer .docx
Your community includes people from diverse backgrounds. Answer .docxYour community includes people from diverse backgrounds. Answer .docx
Your community includes people from diverse backgrounds. Answer .docxhyacinthshackley2629
 
Your Communications Plan Please respond to the following.docx
Your Communications Plan Please respond to the following.docxYour Communications Plan Please respond to the following.docx
Your Communications Plan Please respond to the following.docxhyacinthshackley2629
 
Your Communication InvestigationFor your mission after reading y.docx
Your Communication InvestigationFor your mission after reading y.docxYour Communication InvestigationFor your mission after reading y.docx
Your Communication InvestigationFor your mission after reading y.docxhyacinthshackley2629
 
Your Communications PlanFirst step Choose a topic. Revi.docx
Your Communications PlanFirst step Choose a topic. Revi.docxYour Communications PlanFirst step Choose a topic. Revi.docx
Your Communications PlanFirst step Choose a topic. Revi.docxhyacinthshackley2629
 
Your coffee franchise cleared for business in both countries (Mexico.docx
Your coffee franchise cleared for business in both countries (Mexico.docxYour coffee franchise cleared for business in both countries (Mexico.docx
Your coffee franchise cleared for business in both countries (Mexico.docxhyacinthshackley2629
 

More from hyacinthshackley2629 (20)

Your company nameYour nameInstruction Page1. O.docx
Your company nameYour nameInstruction Page1. O.docxYour company nameYour nameInstruction Page1. O.docx
Your company nameYour nameInstruction Page1. O.docx
 
Your Company NameYour Company NameBudget Proposalfor[ent.docx
Your Company NameYour Company NameBudget Proposalfor[ent.docxYour Company NameYour Company NameBudget Proposalfor[ent.docx
Your Company NameYour Company NameBudget Proposalfor[ent.docx
 
Your company recently reviewed the results of a penetration test.docx
Your company recently reviewed the results of a penetration test.docxYour company recently reviewed the results of a penetration test.docx
Your company recently reviewed the results of a penetration test.docx
 
Your company wants to explore moving much of their data and info.docx
Your company wants to explore moving much of their data and info.docxYour company wants to explore moving much of their data and info.docx
Your company wants to explore moving much of their data and info.docx
 
Your company plans to establish MNE manufacturing operations in Sout.docx
Your company plans to establish MNE manufacturing operations in Sout.docxYour company plans to establish MNE manufacturing operations in Sout.docx
Your company plans to establish MNE manufacturing operations in Sout.docx
 
Your company just purchased a Dell server MD1420 DAS to use to store.docx
Your company just purchased a Dell server MD1420 DAS to use to store.docxYour company just purchased a Dell server MD1420 DAS to use to store.docx
Your company just purchased a Dell server MD1420 DAS to use to store.docx
 
your company is moving to a new HRpayroll system that is sponsored .docx
your company is moving to a new HRpayroll system that is sponsored .docxyour company is moving to a new HRpayroll system that is sponsored .docx
your company is moving to a new HRpayroll system that is sponsored .docx
 
Your company is considering the implementation of a technology s.docx
Your company is considering the implementation of a technology s.docxYour company is considering the implementation of a technology s.docx
Your company is considering the implementation of a technology s.docx
 
Your company is a security service contractor that consults with bus.docx
Your company is a security service contractor that consults with bus.docxYour company is a security service contractor that consults with bus.docx
Your company is a security service contractor that consults with bus.docx
 
Your company has just sent you to a Project Management Conference on.docx
Your company has just sent you to a Project Management Conference on.docxYour company has just sent you to a Project Management Conference on.docx
Your company has just sent you to a Project Management Conference on.docx
 
Your company has designed an information system for a library.  The .docx
Your company has designed an information system for a library.  The .docxYour company has designed an information system for a library.  The .docx
Your company has designed an information system for a library.  The .docx
 
Your company has had embedded HR generalists in business units for t.docx
Your company has had embedded HR generalists in business units for t.docxYour company has had embedded HR generalists in business units for t.docx
Your company has had embedded HR generalists in business units for t.docx
 
Your company You are a new Supply Chain Analyst with the ACME.docx
Your company   You are a new Supply Chain Analyst with the ACME.docxYour company   You are a new Supply Chain Analyst with the ACME.docx
Your company You are a new Supply Chain Analyst with the ACME.docx
 
Your company has asked that you create a survey to collect data .docx
Your company has asked that you create a survey to collect data .docxYour company has asked that you create a survey to collect data .docx
Your company has asked that you create a survey to collect data .docx
 
Your Communications PlanDescriptionA.What is your .docx
Your Communications PlanDescriptionA.What is your .docxYour Communications PlanDescriptionA.What is your .docx
Your Communications PlanDescriptionA.What is your .docx
 
Your community includes people from diverse backgrounds. Answer .docx
Your community includes people from diverse backgrounds. Answer .docxYour community includes people from diverse backgrounds. Answer .docx
Your community includes people from diverse backgrounds. Answer .docx
 
Your Communications Plan Please respond to the following.docx
Your Communications Plan Please respond to the following.docxYour Communications Plan Please respond to the following.docx
Your Communications Plan Please respond to the following.docx
 
Your Communication InvestigationFor your mission after reading y.docx
Your Communication InvestigationFor your mission after reading y.docxYour Communication InvestigationFor your mission after reading y.docx
Your Communication InvestigationFor your mission after reading y.docx
 
Your Communications PlanFirst step Choose a topic. Revi.docx
Your Communications PlanFirst step Choose a topic. Revi.docxYour Communications PlanFirst step Choose a topic. Revi.docx
Your Communications PlanFirst step Choose a topic. Revi.docx
 
Your coffee franchise cleared for business in both countries (Mexico.docx
Your coffee franchise cleared for business in both countries (Mexico.docxYour coffee franchise cleared for business in both countries (Mexico.docx
Your coffee franchise cleared for business in both countries (Mexico.docx
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

C Programming Assignment - Library Catalogue System

  • 1. 1 Objectives Gain hands on experience with programming C. To Practice the following: Dynamic memory allocation, handle file IO, loops, setup and use of data structures, and function decomposition. Submission details You must only submit (using the submit command on latcs5) An electronic copy of the code (There is NO hardcopy to be handed-in) See the end of this document for more details This is an individual assignment. You are not permitted to work as a part of a group when writing this assignment. Copying, Plagiarism Plagiarism is the submission of somebody else’s work in a manner that gives the impression that the work is your own. For individual assignments, plagiarism includes the case where two or more students work collaboratively on the assignment. The Department of Computer Science and Computer Engineering treats plagiarism very seriously. When it is detected, penalties are strictly imposed. Please Note: While you are free to develop the code for this assignment on
  • 2. any operating system, your solution (C code) must compile and run on the latcs5 system using the cc (or by using gcc) compiler. Code that does not run on the latcs5 system will receive zero marks for implementation. Delays caused by computer downtime cannot be accepted as a valid reason for late submission without penalty. Students must plan their work to allow for both scheduled and unscheduled downtime. Given resources On lms you will see 3 files:- 1. CES_assignment-13.doc ( This document 2. AssignTemplate.c ( the source code template to start coding in 3. sample_input.txt ( This is the sample input file which contains the details of a number of books currently in the “library”. {For a complete explanation of what each entry is see task 2} Programming Task Implement a menu driven library catalogue system that allows users to perform various catalogue maintenance tasks. You are only allowed to use the C programming language. You are not allowed to use C++. Please do not use global variables. Up to 50% of marks will be lost for assignments that use global variables. Please do functional decomposition. Up to 50% of marks will be lost for students who try to write the entire program in one main function or something similar. There should be at least 5 functions for the assignment. One function for each task 2 to 4.
  • 3. Two functions for task 5. More functions than 5 is also highly recommended. The aim of this rule is to teach you how to pass pointer arguments into functions. The assignment has been broken up into 5 tasks. Task 1 [10 marks code correctness] The program should be menu driven. The user should be presented with the following menu: 1. Load catalogue from file 2. Save catalogue to file 3. Display catalogue 4. Find book from catalogue 5. Quit After selecting one of the above options the corresponding task should be performed. After completing the selected task, the menu should be displayed again for the user to choose again unless the 5th option is chosen. Task 2 [26 marks code correctness] Implement the load catalogue from file menu option. After selecting this option the user should be asked to enter the name of a file to be loaded. The file should then be loaded into an array of structures. The array of structures should have been declared in the main function before the load catalogue function was called. To get full marks for this task you should use run- time (dynamically) allocated memory for the array of structures. If you use static memory allocation you will lose 5 marks. You can assume the file will have the following format. [Number of books]
  • 4. [Title of book] [Author first name], [Author surname] [Year of publication] [Replacement cost] … … [Title of book] [Author first name], [Author surname] [Year of publication] [Replacement cost] {The … above represents intermediate catalogue entries.} Here is an explanation of the above fields: [Number of books] - This is the number of book entries stored in the file [Title of book] – A string specifying the title of the book, the string may contain spaces. [Author First name], [Author Surname] – Two strings which do not contain spaces but are separated by a comma followed by a space. [Year of publication] - A number specifying the year that the book was published [Replacement cost] - Cost of replacing a book, it may contain a decimal point. Below is an example of a catalogue file that contains 2 books: 2 C for beginners Peter, Kernighan 1999 102.50 XML data Management
  • 5. Amit, Chandhri 2005 122.30 One way to copy the sample file (sample_input.txt) from windows i7 into a putty session is to;_ 1. opened vi with an appropriate file name, 2. Immediately issue the command in vi :set paste /*then press return*/ 3. Then enter insert mode by pressing i 4. Having opened sample_input.txt in notepad on windows a. Highlight ALL the data there b. Move pointer over putty, left click to activate putty, then c. Right click to put data there. 5. It will now appear as follows:- {The vi “page” on putty:-} 6 Cpp for beginners Peter, Kernighan 1999 102.5 CPP FOR Beginners
  • 6. Peter, Kernighan 1999 102.5 CPP FOR Beginners PeTer, KerNIghan 2001 101.5 XML data Management Amit, Chandhri 2005 122.3 PHP for the world wide web William, Hope 2004 202.4 Computer networks Andrew, Tanenbaum 2004
  • 7. 291.1 You can now save this in vi as usual and commence programming; treating this file as if you had written it!! Task 3 [12 marks code correctness] Implement the save catalogue to file menu option. After selecting this option the user should be asked to specify the name of the save file. All the book catalogue data should be stored onto the specified file in the same format as the file loaded in Task 2. Task 4 [12 marks code correctness] Implement the display catalogue menu option. All the attributes of the books should be displayed as follows: Number of books in catalogue = [number of books] --------------------------------------------------------------- Title: [title of book] Author: [first name of author] [surname of author] Year of publication: [year of publication] Replacement cost: $[cost of replacement] ---------------------------------------------------------------
  • 8. .... .... --------------------------------------------------------------- Title: [title of book] Author: [first name of author] [surname of author] Year of publication: [year of publication] Replacement cost: $[cost of replacement] --------------------------------------------------------------- Note: [title of book] [first name of author] [surname of author] [year of publication] [cost of replacement] have the same meaning as those for task 2. Here is an example output: Number of books in catalogue = 2 --------------------------------------------------------------- Title: C for beginners Author: Peter Smith Year of publication: 1999 Replacement cost: $102.50
  • 9. --------------------------------------------------------------- Title: Java programmers hand book Author: John Edwards Year of publication: 2003 Replacement cost: $105.20 --------------------------------------------------------------- Task 5 [15 marks code correctness] Implement the search book from catalogue menu option. After selecting this option the user should be asked to specify the book using the following sub-menu: 1. Specify book title 2. Specify author first name 3. Specify author last name After choosing one of the above sub-menu options, the user should be asked to type in a string to be used for finding the book. Note the string has to completely match the relevant book attribute. Partial match is not considered a match. In the following example the user strings does not match the corresponding books: User types in for book title: Cforbeginners Actual book title: C for beginners User types in for author first name: peters Actual book author first name: peter
  • 10. User types in for author surname: peter Actual book author surname: peterson The search should be case insensitive. Therefore the following does match: User types in for author first name: peter Actual book author first name: peTer User types in for book title: c for beginners Actual book title: C For Beginners The matching books found should be displayed onto the screen in the same format as task 4. If more than one matching book is found then all matching books should be displayed. Bonus Task [10 marks code correctness] If you want bonus 10 marks for your assignment and are ready for a challenge then you can implement an extra option to the menu. This is the “Delete books” menu option. Once the user selects this option then he/she ill be asked to do the same as task 5 except the matching books found are first displayed and then deleted from memory. To get the marks for this task the memory for your array of structures must have been allocated using dynamic memory allocation in Task 2. Here you will need to delete that array of structures and create a new smaller one that exactly fits the remaining (non-deleted) books. Note if the search matches more than one book than all the matched books will need to be deleted. Marking Scheme The assignment will be marked as follows:
  • 11. 1. Correct execution 75 marks 2. Coding style 25 marks 3. Bonus task 10 marks 1. Coding style will be marked according to the following criteria: - Use of comments - Quality of functional decomposition. - Algorithm design 2. A student can not get more than 100 marks. Therefore a student who gets everything correct and also does the bonus task will still only get 100 marks not 110. However, it is still a good idea to do the bonus task since you are likely to lose some marks somewhere in your program. Submission Details · Your program has to run under Unix on the latcs5 or latcs6 machine. System-specific code should not be used in your program, as we emphasize use of portable C. Code that does not compile or run on latcs5/6 will not be marked. · Please ensure that your name and student number is on every file that you submit. · You are to submit your files from your latcs5 account. Make sure you are in the same directory as the one containing these files. Type the following commands at the Unix prompt (ensuring that CES is in uppercase): > submit CES <filename>
  • 12. where <filename> is the actual complete name of your file. DO NOT submit any executable files instead submit your source code files only, that is, your progfilename.c. This is so your code (( source code) can be compiled by an examiner in latcs5/latcs6. {Where progfilename is the filename you have given to your source code.} After submitting the files, the following command will list the files submitted from your account: > verify You can submit the same filename as many times as you like before the assignment deadline; the previously submitted copy will be replaced by the latest one. Emailing your code will not be accepted and will result in a mark of 0 being awarded for the assignment. Only those assignments that have been correctly submitted using the above “>submit ….” process will be accepted for assessment. There are no exceptions. #include <stdio.h> #include <stdlib.h> struct book_type { // You need to fill in your struct here }; // This function loads a catalogue of books from a user specified file name. // Note you need to use malloc inside this function to allocate
  • 13. the memory // needed for the catalogue of books. // After catalogue is allocated and filled up with books loaded from the file, // it is returned back to the main program via the book_type * return type. // The pointer parameter numBooks is used to pass the number of books back // out to the numBooks variable in the main function. This way the other // functions will be able to use this variable to find how many books // are stored in the catalogue. struct book_type * loadCatalogue(int * numBooks); // This function saves catalogue into a user specified text file void saveCatalogue(struct book_type * bCatalogue, int numBooks); // This function displays the catalogue onto the screen. void displayCatalogue(struct book_type * bCatalogue, int numBooks); // This function finds a user specified book or set of books and displays them void findBook(struct book_type * bCatalogue, int numBooks); // Important questions for you to consider: // ** Why are the parameters for the loadCatalogue function so different // from the other functions? Please explain the difference in detail. *** // This question is not part of the assignment requirements, but it is // something that you should be able to answer since it is
  • 14. important // knowledge. int main() { struct book_type * bookCatalogue; int numBooks; // Write a loop which continuously asks the user to choose one of // the following options until the quit option is selected: // 1. Load catalogue from file // 2. Save catalogue to file // 3. Display catalogue // 4. Find book from catalogue // 5. Quit // // Use a switch statement to handle the different user choices. // In the case that load catalogue is chosen you should call the // loadCatalogue function as follows: // bookCatalogue = loadCatalogue(&numBooks); // // In the case that save catalogue is chosen you should call the // saveCatalogue function as follows: // saveCatalogue(bookCatalogue, numBooks); // // It is up to you to work out how and when to call the other functions. }