(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
Assignment 8 Group 2 - Final Group Project Report
1. 1
Assignment
8
Project
B:
Library
Information
System
Written
by:
Group
2
Software
Development
Process
(SDP):
1. Problem
Statement:
This
program
is
an
electronic
rental
system
of
a
library
in
a
town
called
ABC.
In
this
system,
there
are
some
features
that
were
included,
such
as:
• To
store
the
set
of
books
including
their
author(s),
title,
ISBN,
subject,
loan
type
(normal,
short
loan,
no-‐take-‐out),
shelf-‐mark,
loan
status,
number
of
copies,
etc
• To
provide
options
for
altering
the
details
of
a
book,
mark
it
as
lost
/
damaged
/
ordered,
etc.
• To
create
different
privileges,
which
are
the
guest,
student,
teacher,
and
admin.
For
example,
the
teacher
and
admin
can
borrow
a
book
for
a
longer
time
compared
with
the
students.
Admin
can
see
the
borrower
list,
etc.
• To
alter
the
borrowing
time
• To
search
for
a
particular
book
and
allocate
a
book
to
a
specific
borrower
for
a
specific
time
period
• To
implement
return
and
renewal
• To
print
the
list
of
available
books
and
borrowed
books
• To
provide
borrower
statistics
(e.g.
about
the
number
of
books)
to
a
particular
account
2. Analysis
1. int
main()
function:
l Inputs:
No
input
in
this
function
l Outputs:
No
output
in
this
function
2. 2
2. void
mainmenu(void)
function:
l Inputs:
A
number
between
1
to
4,
1
leads
to
registration
menu,
2
leads
to
login
menu,
3
leads
to
search
books,
and
4
leads
to
exit
this
program
l Outputs:
The
registration(),
login(),
booksearch(),
and
exit_program()
function
according
to
the
number
input
3. void
wrong_option_sentence(void)
function:
l Inputs:
No
input
for
this
function
l Outputs:
The
sentence:
Please
try
again,
the
data
you
input
was
wrong.
4. void
registration
(void)
function:
l Inputs:
l User’s
ID
number
l User’s
first
name
l Surname
l Password
l Privilege
:
0=guest,
1=student,
2=teacher,
3=administrator
l Outputs:
The
sentence:
Registration
success!
Now
you
have
been
registered
in
this
library.
The
data
of
users
are
saved
in
the
userlist.txt
file
5. void
show_userdata
(void)
function:
l Inputs:
There
is
no
input
in
this
function.
l Outputs:
This
function
read
the
file
userlist.txt
and
store
in
filenm
file
variable.
It
will
process
the
data
of
users
such
as
user’s
ID,
surname,
given
name,
password,
and
privilege.
6. int
line_number
(FILE
*filenm)
function:
l Inputs:
There
is
no
input
in
this
function.
l Outputs:
There
is
no
output
in
this
function.
3. 3
7. void
showupdate_userdata
(void)
function:
l Inputs:
This
function
has
no
input
l Outputs:
This
function
only
open
and
then
write
the
existing
file
userlist.txt,
which
contains
the
user’s
ID,
given
name,
family
name,
password,
and
privilege.
8. FILE*
file_read
(char*)
function:
l Inputs:
No
input
in
this
function,
however
this
function
is
called
when
an
existing
file
is
needed
to
be
opened
and
read
l Outputs:
The
file
is
opened
and
saved
into
the
variable
filenm,
if
the
file
is
not
exist
and
cannot
be
opened,
the
sentence”
The
file
cannot
be
opened:
(filenm)”
will
be
displayed.
9.
FILE*
file_write
(char*)
function:
l Inputs:
No
input
in
this
function,
however
this
function
is
called
when
an
existing
file
is
needed
to
be
written
and
updated
l Outputs:
The
file
is
opened
and
ready
to
be
written,
then
it
is
saved
into
the
variable
filenm,
if
the
file
is
not
exist
and
cannot
be
opened,
the
sentence”
The
file
cannot
be
opened:
(filenm)”
will
be
displayed.
10.
FILE*
file_append
(char*)
function:
l Inputs:
No
input
in
this
function,
however
this
function
is
called
when
an
existing
file
is
needed
to
be
appended
l Outputs:
The
file
is
opened
and
ready
to
be
appended,
then
it
is
saved
into
the
variable
filenm,
if
the
file
is
not
exist
and
cannot
be
opened,
the
sentence”
The
file
cannot
be
opened:
(filenm)”
will
be
displayed.
11. void
file_close
(FILE
*filenm)
function:
l Inputs:
No
input
in
this
function,
however
this
function
is
called
when
an
existing
file
is
needed
to
be
closed
l Outputs:
The
file
is
closed,
and
if
it
fail
to
do
so,
a
sentence
“The
file
cannot
be
closed:
(filenm)”
will
be
displayed.
4. 4
12. void
login(void)
function:
l Inputs:
User
needs
to
input
his
first
name,
surname,
ID
number
and
password
which
all
are
already
registered.
If
all
these
are
correct,
user
will
get
into
the
borrower
function
and
it
should
obtain
other
input,
or
else
these
input
have
any
mistakes,
user
will
get
to
main
menu
and
it
should
obtain
some
input
as
well.
l Outputs:
Some
sentences
will
be
provided
on
screen
to
prompt
user
input
corresponding
information,
and
if
the
password
is
wrong
will
also
get
some
prompt.
Or
else
call
other
functions.
l Additional
requirements:
Using
the
strcmp
statement
to
check
the
alphabetic
string
with
surname
and
password,
only
both
of
surname
and
password
are
correct
the
login
in
process
is
successful.
13. void
borrower_function(int
id,
char*
name)
function:
l Inputs:
User
should
input
the
order
to
program
according
to
the
sentences
which
printed
on
screen.
l Outputs:
the
menu
which
is
using
to
prompt
user
input
order
should
be
printed
on
screen,
and
other
prompt
which
is
using
to
warm
user
the
happen
of
mistakes.
l Additional
requirements:
Different
order
will
call
another
functions
so
it
must
break
out
after
the
function.
14. void
loan_list(int
id,
char*
name)
function:
l Inputs:
User
needs
to
choose
does
him
want
to
renew
his
books,
if
he
has
already
borrowed
some
books.
l Outputs:
Some
of
information
about
the
books
which
have
been
borrowed
by
the
user
will
print
on
screen.
In
addition,
some
prompts
and
the
menu
for
choosing
orders
will
also
be
provided
on
screen.
15. FILE*
open_singlebook
(int
number)
function:
l Inputs:
There
is
no
input
in
this
function.
l Outputs:
The
value
of
filemn
will
be
assigned
to
this
function,
and
the
address
of
source
of
the
file
is
decided
by
the
'book_no',
the
value
filemn
is
determined
by
the
file_read()
function
with
parameter
file_name
l All
of
these
operations
is
doing
in
the
File,
and
return
a
value
to
the
function.
5. 5
16. FILE*
write_singlebook
(int
number)
function:
l Inputs:
The
value
of
the
pointer
filemn
is
determined
by
the
file_write()
function
with
parameter
file_name.
l Outputs:
The
value
of
filemn
will
be
assigned
to
this
function,
and
the
address
of
source
of
the
file
is
decided
by
the
'book_no'.
l All
of
these
operations
is
doing
in
the
File,
and
return
a
value
to
the
function.
17. char
*integerstring_conversion(char
*string,
int
n)
function:
l Inputs:
This
function
has
no
input,
however
the
data
that
used
to
be
the
parameters
is
come
from
the
other
function.
l Outputs:
After
this
function
the
value
will
assign
to
the
char
type
function
finally.
18. void
show_singlebook(int
no)
function:
l Inputs:
No
input
from
keyboard
in
this
function,
but
the
data
all
comes
from
other
functions
or
what
already
stored
in
file.
l Outputs:
Has
no
directly
output
on
screen
in
this
function.
The
data
is
assign
to
corresponding
character,
the
data
contains
last
borrowed
date,
and
due
date,
who
borrowed
this
book,
the
data
is
stored
in
file,
and
it
could
display
by
calling
this
function
in
other
statement.
l Other
requirements:
The
new
data
should
write
at
the
end
of
this
file,
which
means
the
data
that
already
existed
cannot
be
cancelled.
19.
void
renew(void)
function:
l Inputs:
User
needs
to
input
the
number
of
book
that
is
renew,
and
the
barcode
of
this
book.
l Some
of
prompts
should
be
display
on
the
screen,
prompt
user
input
corresponding
data.
20.
void
admin
(int
id,
char
*name)
function:
l Inputs:
User
need
to
input
the
order
in
this
function
according
to
the
prompts.
From
1-‐10.
l Outputs:
The
menu
for
each
order
should
be
displayed
firstly,
after
input
the
order
other
displayof
other
function
would
be
displayed.
6. 6
l Other
requirements:
After
choose
orders
must
exit
this
switch
function,
which
program
would
not
automatically
back
to
this
function.
21. void
borrowmenu(int
id,
char*name)
function:
l Inputs:
User
needs
to
choose
the
order,
just
either
1
or
2.
l Outputs:
The
menu
for
each
order
should
be
displayed
first,
or
else
user
input
the
order
which
is
neither
1
nor
2
therefore
it
should
prompt
user
input
the
correct
order.
And
then
the
function
connects
to
other
functions.
22.
void
borrow_function
(void)
function
:
l Input:
l enter
student
ID
correctly,
if
user
has
the
privilege,
enter
the
ISBN
and
the
barcode
of
the
book.
l enter
user’s
ID
number,
book’s
number
and
book’s
barcode.
l Output:
l if
users
input
an
inexistent
ID,
it
will
show
“sorry,
you
have
not
been
registered”;
if
a
correct
ID
have
been
store,
it
will
show
“hi
guest,
you
can
just
search
books
here”.
“The
book
number
is
%d”
if
ISBN
has
been
store.
“You
could
not
borrow
this
book,
the
book
was
marked
as
%s”
if
the
book
has
been
marked
by
someone
l “you
have
succeeded
borrowing
a
book.”
Or
if
user
entered
wrong
information,
system
will
display
“you
could
not
borrow
this
book”
and
“the
book’s
due
date
is
at
%d-‐%d-‐%d”
then
you
can
borrow
it
after
this
date.
“you
have
succeeded
borrowing
a
book”
if
succeed.
23.
void
bookreturn(int,
char*)
function:
l Input:
“please
enter
your
ID
number,
book’s
number
and
book’s
barcode”
when
return
a
book.
l Output:
“thanks
for
returning
the
book”
when
succeeded
and
“error
occurred”
when
error.
24.
void
display_available
(int,char*)
function:
l Input:
No
input
for
this
function
l Output:
The
list
of
available
books
7. 7
25.
void
display_borrowed
(int,char*)
function:
l Input:
No
input
for
this
function
l Output:
The
list
of
books
that
are
borrowed
currently
26.
void
display_borrower
(int,char*)
function:
l Input:
No
input
in
this
function
l Output:
the
borrower
and
the
book
they
borrowed
will
be
displayed
27.
void
display_users
(int,char*)
function:
l Input:
the
member’s
ID
number
that
want
to
be
displayed
l Output:
Member’s
fullname,
ID
number,
and
their
privilege
/
status
28.
void
privilege_changing
(int,char*)
function:
l Input:
the
user’s
ID
whose
privilege
you
want
to
change,
and
enter
the
user’s
new
privilege.
l Output:
“the
user’s
privilege
has
been
changed”
if
succeed;
“error”
if
error.
29.
void
mark_details
(int,char*)
function:
l Input:
enter
the
number
of
the
book
that
you
want
to
mark
and
mark
the
book’s
detail.
l Output:
“the
book’s
detail
has
been
marked”
if
succeed
and
“error
occurred”
if
error.
30.
void
booksearch
(void)
function:
l Input:
here
are
three
menus
you
can
choose
if
search
a
book:
by
subject.
By
author
and
by
title,
choose
and
enter
1-‐3.
Then
input
the
book’s
subject,
book’s
author
or
book’s
title
as
requirement.
l Output:
search
by
subject
and
enter
the
book’s
subject:
“the
subject
you
entered
is
too
short
(it
has
to
be
more
than
3
letters)”
and
“sorry,
the
book
cannot
be
found”
if
error;
“there
are
%d
8. 8
results
and
%d
pages
found”
if
succeed,
then
you
can
choose
to
see
a
book’s
details,
go
and
search
in
another
page
or
return
to
main
menu,
just
choose
1-‐3
and
enter
a
book
label
or
a
particular
page.
Search
by
author’s
name
and
enter
author
name:”the
author’s
name
you
entered
is
too
short
(it
has
to
be
more
than
3
letters)”
and
“please
enter
the
book’s
author
again”
if
error.
Search
by
book’s
title
and
enter
the
title:
“the
title
you
entered
is
too
short
(it
has
to
be
more
than
3
letters)”
and
“please
enter
the
book’s
title
again”
if
error.
After
the
process,
“you
have
renewed
the
book”
if
succeed.
31. void
subjectsearch
(void)
function:
l Inputs:
Enter
a
book
subject,
which
can
be
fiction
or
non-‐fiction
l Outputs:
Display
the
list
of
the
books
according
to
the
subject
input
32. void
booklist(int)
function:
l Inputs:
Enter
a
number
1-‐3
to
see
a
book
details,
move
to
the
next
page,
or
return
to
the
main
menu
l Outputs:
The
book
details
contains
label,
title,
author,
and
subject,
or
a
list
of
books
on
a
page,
or
it
can
display
main
menu
again
according
to
the
number
input
33. void
search_singlebook(int)
function:
l Inputs:
No
input
for
this
function
l Outputs:
Show
the
information
of
a
single
book
including
book
barcode,
loan
type,
loan
type,
loan
status,
the
time
last
borrowed
(
day,
month
and
year),
due
date(
day,
month
and
year),
the
details
of
the
book
and
its
borrower
34. void
authorsearch
(void)
function:
l Inputs:
An
author’s
name
l Outputs:
Display
the
list
of
the
books
according
to
the
author’s
name
35. void
titlesearch
(void)
function:
l Inputs:
The
title
of
the
book
9. 9
l Outputs:
Display
the
list
of
the
books
according
to
the
input
title
36. void
alteringtime(int,
int)
function:
l Inputs:
There
is
no
input
in
this
function.
l Outputs:
There
is
no
output
in
this
function,
but
the
time
of
the
book
borrowing
will
be
updated
and
renewed
37. void
update_singlebook
(int)
function:
l Inputs:
This
function
has
no
input
l Outputs:
Update
the
information
of
a
single
book
include
the
loan
type,
barcode,
due
day,
due
month
and
so
on.
38. void
show_bookinfo
(void)
function:
l Inputs:
No
input
in
this
function,
but
a
database
file
which
is
booklist.txt
is
necessary
l Outputs:
It
has
no
specific
output
but
is
show
the
data
of
a
book
that
could
be
updated
in
the
next
function
39.
void
update_bookinfo
(void)
function:
l Inputs:
No
input
in
this
function,
but
a
database
file
which
is
booklist.txt
is
necessary
l Outputs:
Update
the
information
of
a
collection
of
books
including
the
book
number,
title,
author,
shelf
mark,
ISBN
and
so
on
40.
void
exit_program(void)
function:
l Inputs:
No
input
in
this
function
l Outputs:
Display
the
sentence:
“Thanks
for
your
visit,
please
come
again
next
time!”
10. 10
3. Design
Algorithm:
1. int
main()
function:
l Call
the
show_bookinfo
function
l Call
the
show_userdata
function
l Call
the
mainmenu
function
l Return
0
for
this
main
function
2. void
mainmenu(void)
function:
l Declare
one
variable
of
the
type
of
integer
namely
a
l Display
the
menu
and
the
options
l Ask
user
to
input
a
number
between
1-‐4
l Store
and
save
the
number
input
into
variable
a
l Using
switch
function,
call
the
function
according
to
the
number
input
l If
it
is
1,
call
the
registration
function
l If
it
is
2,
call
the
login
function
l If
it
is
3,
call
the
booksearch
function
l If
it
is
4,
call
the
exit_program
function
l Otherwise,
the
wrong_option_sentence
function
will
be
called
3. void
wrong_option_sentence(void)
function:
l Display
the
sentence
“Please
try
again,
the
data
you
input
was
wrong.”
4. void
registration
(void)
function:
l Declare
two
variables
of
the
type
of
character
namely
pw
and
passw
l Declare
one
variable
of
the
type
of
integer
namely
a,
and
initialize
it
equal
to
0
l Declare
one
variable
of
the
type
of
integer
namely
b,
and
initialize
it
equal
to
0
l Cal
the
show_userdata
function
l While
a
is
zero,
the
registration
menu
will
be
appeared
l Ask
user
to
input
his/her
ID
number
l Read
the
value
and
store
it
into
users[number_of_users].ID
l If
the
ID
input
is
more
than
8
digits,
the
sentence
“Your
ID
number
should
be
within
8
digits.”
Is
displayed
l Ask
user
to
input
his/her
given
name
l Read
the
value
and
store
it
into
users[number_of_users].givenname
l Ask
user
to
input
his/her
last
name
l Read
the
value
and
store
it
into
users[number_of_users].surname
l Ask
user
to
input
his/her
password
l Read
the
value
and
store
it
into
users[number_of_users].password
11. 11
l Ask
user
to
input
his/her
privilege
between
0
to
3
l Read
the
value
and
store
it
into
users[number_of_users].userprivilege
l Display
the
sentence
”Registration
success!
Now
you
have
been
registered
in
this
library.”
l Go
back
to
the
main
menu
by
calling
mainmenu
function
5. void
show_userdata
(void)
function:
l declare
one
pointer
of
the
type
of
file
namely
filenm
l declare
one
variable
of
the
type
of
integer
namely
line
l declare
one
variable
of
the
type
of
integer
namely
a,
and
initialize
it
equal
to
0
l declare
one
variable
of
the
type
of
integer
namely
b
l declare
one
variable
of
the
type
of
character
namely
c
l declare
one
variable
of
the
type
of
character
namely
strarray
l assign
file_read
to
filenm
l assign
line_number
(filenm)
to
line
l output
the
value
of
users[a].ID
into
the
file
which
is
pointed
by
filenm
l fix
the
position
for
filenm
renewedly
l using
fseek
to
move
the
any
file
position
in
filenm
by
the
offset
-‐1L
from
the
current
position
l assign
c
to
users[a].surname[b]
l assign
'0'
to
users[a].surname[b]
l fix
the
position
for
filenm
renewedly
l using
fseek
to
move
the
any
file
position
in
filenm
by
the
offset
-‐1L
from
the
current
position
l assign
c
to
users[a].givenname[b]
l assign
'0'
to
users[a].givenname[b]
l assign
users[a].surname
and
blank
space
to
strarray,
and
then
assign
it
to
users[a].fullname
l fix
the
position
for
filenm
renewedly
l using
fseek
to
move
the
any
file
position
in
filenm
by
the
offset
-‐1L
from
the
current
position
l assign
c
to
users[a].password[b]
l assign
'0'
to
users[a].password[b]
l output
the
value
of
users[a].userprivilege
into
the
file
which
is
pointed
by
filenm
l assign
line
to
number_of_users
l close
the
file
6. int
line_number
(FILE
*filenm)
function:
l declare
one
variable
of
the
type
of
integer
namely
a
l declare
one
variable
of
the
type
of
integer
namely
l,
and
initialize
it
equal
to
0*
l when
the
a
='n',
the
value
of
l
plus
one
l let
filenm
point
to
the
outset
again
l this
function
return
the
value
of
1
12. 12
7. void
showupdate_userdata
(void)
function:
l declare
one
pointer
of
the
type
of
file
namely
filenm
l declare
one
variable
of
the
type
of
integer
namely
a
l assign
file_read
to
filenm
l input
the
data
of
user
to
the
file
l close
the
file
8. FILE*
file_read
(char*)
function:
l declare
one
pointer
of
the
type
of
file
namely
filenm
l assign
afile
to
filename
l open
and
read
the
file
of
filename
and
assign
it
to
filenm
l when
the
file
is
not
exist,
display
the
sentence
“The
file
cannot
be
opened:
(filenm)”
l this
function
return
the
value
as
filenm
9.
FILE*
file_write
(char*)
function:
l declare
one
pointer
of
the
type
of
file
namely
filenm
l assign
afile
to
filename
l open
and
write
on
the
file
of
filename
and
assign
it
to
filenm
l when
the
file
is
not
exist,
display
the
sentence
“The
file
cannot
be
opened:
(filenm)”
l this
function
return
the
value
as
filenm
10.
FILE*
file_append
(char*)
function:
l declare
one
pointer
of
the
type
of
file
namely
filenm
l assign
afile
to
filename
l open
and
append
the
file
of
filename
and
assign
it
to
filenm
l when
the
file
is
not
exist,
display
the
sentence
“The
file
cannot
be
opened:
(filenm)”
l this
function
return
the
value
as
filenm
11. void
file_close
(FILE
*filenm)
function:
l Close
the
file
l When
the
file
is
not
exist,
display
the
sentence
“The
file
cannot
be
closed:
(filenm)”
12. void
login(void)
function:
l Declare
the
function
into
no
return
value
and
no
parameters
l Declare
necessary
characters
into
int
type
and
initial
the
value
is
zero,
and
three
char
type
of
characters.
l Use
printf
statement
to
prompt
user
input
the
information
of
user
which
contains
first
name,
surname,
ID
number
and
the
self-‐defined
password.
13. 13
l If
the
serial
number
of
user
less
than
the
defined
number
of
users
call
the
while
loop,
and
inset
the
if
statement
to
the
while
loop
and
determine
following
implementation.
l First
if
statement
is
using
to
check
do
the
input
surname
and
password
coincide
with
the
given
surname
and
password
which
have
registered
already.
After
that
using
a
nested
if
statement
to
the
last
statement
which
is
using
to
check
the
privilege
of
user
who
are
login
in.
l If
the
privilege
of
user
is
1
or
2
call
the
borrower_function()
function;
or
if
the
privilege
of
user
is
3,
call
the
admin()
function,
or
else
prompt
user
who
is
just
guest,
and
calling
the
mainmenu()
function
to
back
main
menu
in
which
the
privilege
of
user
just
guest.
l And
after
the
fist
if
statement
finished
make
b
plus
1
to
itself,
and
prompt
user
as
well,
and
then
call
the
mainmenu()
function
to
back
main
menu.
13.
void
borrower_function(int
id,
char*
name)
function:
l Declare
the
function
into
has
no
return
value
but
has
two
parameters,
which
are
int
type
id,
and
char
type
pointer
name
respectively.
l Declare
b
into
char
type
and
has
eight
letter,
and
declare
a
and
i
into
int
type,
initial
i
with
zero.
l Use
printf
statements
to
display
the
menu
on
screen
to
prompt
user
to
switch.
l Use
switch
statement
to
judge
the
input
value
and
determine
the
following
statement
that
will
be
executed.
l For
case
1,
call
the
loan_list()
function
and
then
break
this
switch
statement.
l For
case
2,
call
the
renew()
function
and
then
break
this
switch
statement.
l For
case
3,
use
a
while
loop
with
condition
in
serial
number
less
than
defined
number
of
users.
After
that,
use
a
if
statement
to
check
the
ID
of
user,
if
the
ID
is
correct
we
using
printf
statement
to
prompt
user
input
his
new
password
and
using
scanf
statement
to
store
the
input
number
into
b,
and
then
use
strcpy
to
copy
this
number
to
replace
the
original
password,
what
is
more,
call
showupdate_userdata()
and
borrower_function().
In
addition,
if
i
is
equal
to
or
bigger
than
the
defined
number
of
users,
prompt
user
his
original
password
is
wrong.
l For
case
4,
call
the
mainmenu()
function
and
then
break
this
switch
statement.
14. void
loan_list(int
id,
char*
name)
function:
l Declare
the
function
into
has
no
return
value
but
has
two
parameters,
which
are
int
type
id,
and
char
type
pointer
name
respectively.
l Declare
necessary
letter
into
int
type,
and
a
FILE
type
pointer
filemn.
l Use
a
for
loop
with
initial
a
is
equal
to
zero
and
if
a
less
than
the
defined
number
of
books
the
a
will
plus
1
to
itself.
l Add
a
nested
while
loop
to
this
for
loop
with
condition
of
x
is
less
than
the
defined
number
of
users,
and
print
a
blank
space.
14. 14
l Use
the
if
statement
to
check
the
ID
if
so,
program
will
execute
the
following
statements,
displays
a
2,
and
the
defined
'no'
plus
1
to
itself,
and
connect
the
pointer
filemn
to
open_singlebook()
function,
and
then
execute
the
open_singlebook()
function.
l Add
a
while
loop
to
the
last
while
loop
with
condition
b
is
less
than
the
defined
singlebook_amount,
and
use
a
if
statement
to
check
the
name
in
the
struct
does
it
is
equal
to
zero
,if
so,
print
the
title,
due_year,
due_month,
and
due_day
on
screen
respectively,
or
else
let
b
plus
1
to
itself,
and
then
finish
the
last
while
loop.
l Let
x
plus
1
to
itself,
in
which
the
second
while
loop
is
still
going
on.
l In
the
other
conditions
of
the
first
if
statement,
x
also
plus
1
to
itself.
After
that,
finish
the
second
nested
while
loop
and
first
for
loop.
l Use
if
statement
to
check
the
'no',
if
it
is
equal
to
zero,
print
some
sentences
to
prompt
user
who
have
not
borrowed
any
book.
l If
the
value
of
'no'
is
not
equal
to
zero,
print
the
menu
to
user
and
gain
the
order
from
keyboard
by
scanf
statement
and
store
it
in
y.
l Use
if
statement
to
check
the
value
of
y,
if
it
is
equal
to
1,
call
the
renew()
function,
or
else,
call
the
borrower_function()
function.
After
that,
finish
the
if
statement.
l Finally,
call
the
borrower_function()
function.
15. FILE*
open_singlebook
(int
number)
function:
l Declare
the
function
into
has
FILE
type
return
value
and
with
parameter
number
in
int
type.
l Declare
a
FILE
type
of
pointer
filemn,
and
book_no
into
char
type
with
15
letters,
additionally,
declare
the
first
and
last
with
not
limited,
and
equal
to
'book'
and
'.txt'
respectively,
finally,
declare
a
pointer
named
file_name.
l Call
the
integerstring_conversion()
function.
l Give
the
file
name
beginning
with
'first'
and
'book_no'
in
series,
and
the
file
name
end
with
'file_name'
and
'last'.
l Connect
the
pointer
filemn
to
file_read()
function
with
parameter
of
file_name.
l Return
the
value
of
filemn
to
the
function.
16. FILE*
write_singlebook
(int
number)
function:
l Declare
the
function
into
has
FILE
type
return
value
and
with
parameter
number
in
int
type.
l Declare
a
FILE
type
of
pointer
filemn,
and
book_no
into
char
type
with
15
letters,
additionally,
declare
the
first
and
last
with
not
limited,
and
equal
to
'book'
and
'.txt'
respectively,
finally,
declare
a
pointer
named
file_name.
l Call
the
integerstring_conversion()
function.
15. 15
l Give
the
file
name
beginning
with
'first'
and
'book_no'
in
series,
and
the
file
name
end
with
'file_name'
and
'last'.
l Connect
the
pointer
filemn
to
file_write()
function
with
parameter
of
file_name.
l Return
the
value
of
filemn
to
the
function.
17. char
*integerstring_conversion(char
*string,
int
n)
function:
l Declare
this
function
into
char
type
return
value
and
has
two
parameter
which
are
char
type
pointer
string
and
int
type
n.
l Declare
necessary
letter
into
int
type.
l Use
if
statement
to
judge
whether
n
could
be
divide
by
10
with
no
remainder
and
has
result
0,
if
not,
make
the
string
is
equal
to
this
function
with
parameters
string
and
the
divided
result.
If
the
if
statement
is
false
do
not
execute
this
statement.
l Make
the
value
which
points
to
the
next
letter
in
this
string
equals
to
the
remainder
that
gain
from
n
divide
by
10.
l Make
value
of
pointer
string
is
equal
to
0,
which
means
to
initialize
the
string.
l Return
the
value
of
string
to
the
function.
18. void
show_singlebook(int
no)
function:
l Declare
necessary
elements
in
this
function,
which
consist
of
a
FILE
type
pointer,
three
int
type
in
that
one
has
initial
value
0,
and
two
char
type.
l Make
the
pointer
filemn
connecting
to
open_singlebook()
function
with
parameter
'no'.
l Define
the
'line'
is
equal
to
the
line_number
function
with
parameter
'filemn'
and
minus
2.
l Make
the
singlebook
is
equal
to
the
data
that
come
from
struct
type
borrowingdata,
and
then
distribute
the
memory
to
line
according
to
the
size
of
borrowing
data.
l Gain
the
1499
bytes
of
data
from
the
file
that
point
by
filemn
and
store
in
str.
l Use
for
loop
to
circularly
operate
each
line.
l Use
fscanf
to
assign
the
value
that
write
in
the
filemn
to
singlebook[]barcode
term
that
is
No.
a
line
in
singlebook
.
l Set
a
while
loop
that
with
condition
if
read
a
space
letter
in
filemn.
If
so,
use
fseek
to
locate
the
input
location,
move
to
the
last
one
cursor
from
the
end.
l Use
the
for
loop
to
repeatedly
gain
the
value
of
character
that
is
in
the
filemn,
with
condition
when
the
reading
process
get
a
character
that
is
not
space
character.
l After
that
set
a
0
to
the
loan
type
for
'b'
in
the
end.
l Locating
the
cursor
to
the
last
one
character
from
the
end
again.
16. 16
l Set
a
while
loop
that
with
condition
if
read
a
space
letter
in
filemn.
If
so,
use
fseek
to
locate
the
input
location,
move
to
the
last
one
cursor
from
the
end.
l Use
the
for
loop
to
repeatedly
gain
the
value
of
character
that
is
in
the
filemn,
with
condition
when
the
reading
process
get
a
character
that
is
not
space
character.
l After
that
set
a
0
to
the
loan
type
for
'b'
in
the
end.
l Locating
the
cursor
to
the
last
one
character
from
the
end
again.
l Use
a
while
loop
to
check
the
character
that
is
not
space
character,
if
so
locate
the
cursor
to
the
last
one
character
from
the
end.
l Gain
the
data
from
filemn
and
assign
the
data
to
lastborrowed_day,
lastborrowed_month
and
lastborrowed_year
of
No.a
term
in
singlebook
respectively.
l Use
a
while
loop
to
check
the
space
character,
if
so
locate
the
cursor
to
the
last
one
character
from
the
end.
l Gain
the
data
from
filemn
and
assign
the
data
to
due_day,
due_month
and
due_year
of
No.a
term
in
singlebook
respectively.
l Use
a
while
loop
to
check
the
space
character,
if
so
locate
the
cursor
the
last
one
character
from
the
end.
l Set
a
for
loop
to
gain
the
value
of
'details'
with
condition
that
if
there
is
not
a
'n'.
l Set
a
'0'
at
the
end
of
the
'details'
string.
And
finish
the
first
for
loop
here.
l Assign
the
value
of
line
to
singlebook_amout.
l Close
the
corresponding
file.
19. void
renew(void)
function:
l Declare
this
function
into
no
return
value
and
has
no
parameters.
l Declare
necessary
elements
in
this
function,
it
consist
of
a
file
type
pointer
filemn,
and
two
int
type
elements.
l Use
printf
statement
to
prompt
user
input
the
book's
number
and
book's
barcode.
l After
that
use
two
scanf
statements
to
gain
the
value
from
keyboard
and
store
it
in
corresponding
element
respectively.
l Call
the
alteringtime()
function
with
the
two
input
data
as
parameters.
20. void
admin
(int
id,
char
*name)
function:
l Declare
this
function
into
void
type
which
means
it
has
not
return
value
and
has
two
parameters
int
id
and
char
*name.
To
connect
each
user.
17. 17
l Declare
one
int
type
parameter
in
this
function,
which
would
be
used
in
the
following
statements.
l Use
some
printf
statements
to
display
the
menu
to
user,
which
could
prompt
choose
the
corresponding
choice.
l Use
a
scanf
statement
to
gain
the
input
from
keyboard
and
store
it
in
the
declared
parameter.
l Use
a
switch
statement
to
the
parameter
a.
l For
case
1,
call
the
borrowmenu()
function
with
parameters
id
and
name,
and
then
break
out
of
this
switch
statement.
l For
case
2,
call
the
booketurn()
function
with
parameters
id
and
name,
and
then
break
out
of
this
switch
statement.
l For
case
3,
call
the
display_available()
function
with
parameters
id
and
name,
and
then
break
out
of
this
switch
statement.
l For
case
4,
call
the
display_borrowed()
function
with
parameters
id
and
name,
and
then
break
out
of
this
switch
statement.
l For
case
5,
call
the
display_borrower()
function
with
parameters
id
and
name,
and
then
break
out
of
this
switch
statement.
l For
case
6,
call
the
display_users()
function
with
parameters
id
and
name,
and
then
break
out
of
this
switch
statement.
l For
case
7,
call
the
privilege_changing()
function
with
parameters
id
and
name,
and
then
break
out
of
this
switch
statement.
l For
case
8,
call
the
mark_details()
function
with
parameters
id
and
name,
and
then
break
out
of
this
switch
statement.
l For
case
9,
call
the
borrower_function()
function
with
parameters
id
and
name,
and
then
break
out
of
this
switch
statement.
l For
case
10,
call
the
mainmenu()
function
and
then
break
out
of
this
switch
statement.
l For
the
default
case,
call
the
wrong_option_sentence()
function
and
then
break
out
of
this
statement.
l Finish
this
function.
21. void
borrowmenu(int
id,
char*name)
function:
l Declare
this
function
into
void
type
which
means
it
has
no
return
value
and
has
two
parameters
which
are
int
type
id
and
char
type
pointer
name.
l Use
some
printf
statement
to
display
the
menu
and
prompts
on
screen.
l Use
scanf
statement
to
gain
the
input
order
from
keyboard,
and
store
it
in
declared
parameter.
18. 18
l Use
if
statement
to
judge
the
input,
if
the
input
is
not
1
or
2
prompt
user
to
input
the
correct
order,
and
use
scanf
statement
again.
l Use
switch
statement
to
judge
the
value
of
a.
l For
case
1,
call
the
borrow_function()
function
and
then
exit
this
switch
statement.
l For
case
2,
execute
the
printf
statement
to
prompt
use
already
quit
this
borrow
system,
and
then
quit
this
switch
statement.
l For
default
case,
call
the
borrower_function()
function
with
parameter
id
and
name.
22.
void
borrow_function
(void)
function
:
l -‐1.
Declare
five
variables
of
the
type
of
integer
namely
a,
b,
c,
d
and
e.
l -‐2.
Declare
four
variables
of
the
type
of
integer
namely
ID,
barcode,
no
and
tot.
l
-‐3.
Declare
two
variables
of
the
type
of
character
namely
name
and
ISBN.
l -‐4.
Declare
12
variables
of
the
type
of
short
integer
namely
year,
month
and
day;
year1,
month1
and
day1;
year2,
month2
and
day2:
year3,
month3
and
day3.
l -‐5.
Ask
user
to
enter
ID,
read
and
store
the
address
of
ID.
And
write
a
if-‐else
statement
to
determine
whether
the
use
has
been
registered.
l -‐6.
Write
an
if-‐else
statement
to
determine
whether
the
user
has
the
privilege
to
borrow
book
there
or
just
search
books.
l -‐7.
If
user
can
borrow
books,
user
is
asked
to
enter
the
ISBN,
book
number
and
barcode
of
the
book.
l -‐8.
Write
an
if-‐else
statement
to
determine
the
book
which
user
wants
to
borrow
is
available.
l -‐9.
Available
copies
of
the
book-‐1,
and
assign
“on-‐loan”
to
collection.
l -‐10.
Store
the
update-‐
information
of
the
user
to
the
collection.
l -‐11.
Use
pointers
to
divide
users
to
have
two
different
due
time
of
the
book.
l -‐12.
If
the
user
has
borrowed
the
book
successfully,
the
system
will
display
“you
have
succeeded
borrowing
a
book”.
23.
void
bookreturn(int,
char*)
function:
l -‐1.
Declare
one
pointer
of
the
type
of
file
namely
filenm.
l -‐2.
Declare
five
variables
of
the
type
of
integer
namely
a,
b,
book_no
(book
number),
bc
(book
barcode)
and
ID.
l -‐3.
Ask
users
to
enter
their
ID,
book
number
and
book
barcode
and
store
all
of
them.
l -‐4.
For
the
borrower,
the
number
of
the
book
he
or
she
borrowed
should
be
zero
again.
l -‐5.
Store
the
return
time.
The
due
time
to
this
specific
book
come
back
to
zero
all
again.
l -‐6.
The
number
of
copies
of
this
book
increases
1.
l -‐7.
The
borrower
ID[b]
+
1,
thus
the
user
can
borrow
other
books.
l
-‐8.
In
other
cases,
the
system
will
display
“Error
occurred”.
24.
void
display_available
(int,char*)
function:
l -‐1.
Declare
a
variable
of
the
type
of
integer
namely
a.
19. 19
l -‐2.
If
the
book
is
available,
add
the
title
of
the
book
to
the
list.
l -‐3.
Use
a
for
loop
to
list
all
the
available
books.
25.
void
display_borrowed
(int,char*)
function:
l -‐1.
Declare
a
variable
of
the
type
of
integer
namely
a.
l
-‐2.
If
the
available
copy
of
the
book
is
not
zero,
add
the
title
of
the
book
to
the
borrowed
list.
l -‐3.
Use
a
for
loop
to
list
all
the
borrowed
books.
26.
void
display_borrower
(int,char*)
function:
l -‐1.
Declare
a
pointer
of
the
type
of
file
namely
filenm.
l -‐2.
Declare
three
variables
of
the
type
of
integer
namely
a,
b,
and
c,
and
initialize
a,
b,
and
c
to
0
at
first.
l -‐3.
Assign
the
number
of
book
that
borrower
borrowed
to
c.
l -‐4.
If
the
borrower
borrowed
books,
list
the
borrower
and
the
titles
of
the
books.
l -‐5.
Use
for
loop
to
list
all
the
books
that
borrower
borrowed.
27.
void
display_users
(int,char*)
function:
l -‐1.
Declare
two
variable
of
the
type
of
integer
namely
a
and
b.
l -‐2.
Ask
user
to
enter
ID
and
read
and
store
the
value
of
it
into
the
address
of
b.
l -‐3.
Display
the
information
of
the
user:
full
name,
ID
and
member’s
privilege.
l -‐4.
Use
a
for
loop
to
list
all
the
members’
information
.
28.
void
privilege_changing
(int,char*)
function:
l -‐1.
Declare
two
variable
of
the
type
of
integer
namely
a
and
b,
and
set
the
initial
value
of
a
to
be
0.
l -‐2.
Declare
two
variable
of
the
type
of
integer
namely
new_prv
and
line.
l -‐3.
Ask
user
which
use’s
privilege
does
him
or
her
wants
to
change
and
input
their
ID.
l -‐4.
Read
and
store
the
value
of
the
input
into
the
address
of
b.
l -‐5.
Assign
new
privilege
to
user.
l -‐6.
If
all
the
cases
do
not
occur,
the
system
will
point
out
error.
29.
void
mark_details
(int,char*)
function:
l -‐1.
Declare
a
pointer
of
the
type
of
file
namely
filenm.
l -‐2.
Declare
two
variables
of
the
type
of
integer
namely
a
and
b,
and
initialize
a
to
0
first.
l -‐3.
Declare
a
variable
of
the
type
of
integer
namely
no
(number).
l -‐4.
Declare
two
strings
of
the
type
of
character
namely
title
and
markbook
and
control
the
length
of
the
characters
to
50-‐byte.
l -‐5.
Ask
user
to
enter
the
number,
barcode
and
other
detail
of
the
book
he
or
she
wants
to
mark.
l -‐6.
Read
and
store
the
value
of
the
input
into
the
address
of
no
(number),
b
and
maekbook
individually.
20. 20
l -‐7.
Assign
markbook
to
singlebook[a].details,
and
update
the
detail
information
one
by
one
by
using
an
if-‐else
statement.
l -‐8.
If
the
input
is
not
variable
to
the
function,
then
system
will
display
“Error
occurred”.
30.
void
booksearch
(void)
function:
l -‐1.
Declare
a
variable
of
type
of
integer
namely
a.
l -‐2.
Ask
user
to
choose
1-‐3:
1.Subject;
2.Author;
3.Title
to
search
a
certain
book.
l -‐3.
Read
and
store
the
value
of
input
to
into
the
address
of
a.
l -‐4.
Use
switch
statement
to
choose
the
operation
depending
on
the
value
of
a:
Case1:
search
by
entering
the
subject
Case2:
search
by
the
author’s
name
Case3:
search
by
the
title.
l -‐5.
If
all
the
cases
are
not
available,
then
the
default
will
be
wrong_option_sentence.
31. void
subjectsearch
(void)
function:
l Declare
an
array
sub
of
char
type
containing
50
elements
l Declare
the
variables
a
and
b
of
int
type
l Ask
user
to
enter
the
book’s
subject
and
read
and
store
the
subject
l Using
the
while
loop
to
check
whether
the
input
subject
is
too
short
l Using
for
loop
to
display
the
books
of
the
subject
32. void
booklist(int)
function:
l Declare
the
variables
a,
b,
booklabel
and
page
of
int
type
l Using
if
and
else
statement
to
check
the
whether
users
can
find
the
book
l Using
while
loop
to
display
the
details
of
book
found
including
book
label,
title,
author
and
subject
l Using
switch
and
cases
to
provide
options
for
users,
the
first
one
is
to
see
the
details
of
a
particular
book
and
enter
a
book
label,
the
second
one
is
to
move
to
another
page
and
enter
a
particular
book
page,
the
third
choice
is
to
go
back
to
the
main
menu,
and
then
the
wrong
options
33. void
search_singlebook(int)
function:
l Declare
the
variables
number,
a
of
int
type
l Using
for
loop
to
show
the
information
of
a
single
book
including
book
barcode,
loan
type,
loan
type,
loan
status,
the
time
last
borrowed(
day,
month
and
year),
due
date(
day,
month
and
year),
the
details
of
the
book
and
its
borrower
l Go
back
to
the
main
menu
34. void
authorsearch
(void)
function:
l Declare
an
array
aut
of
char
type
contains
50
elements
l Declare
the
variable
a
and
b
of
int
type,
and
initialize
b=0
21. 21
l Ask
user
to
enter
the
book’s
author
l Using
while
loop
check
whether
the
input
name
is
correct,
and
if
it
is
wrong
type
it
again
l Using
for
loop
to
show
the
findings
of
the
author
35. void
titlesearch
(void)
function:
l Declare
an
array
tit
of
char
type
contains
100
elements
l Declare
the
variables
a
and
b
of
int
type
l Ask
user
to
enter
the
book’s
title
l Using
while
loop
to
check
whether
the
input
title
is
correct
l Using
for
loop
to
display
the
findings
of
the
title
36. void
alteringtime(int,
int)
function:
l Declare
the
variable
book_no,
barcode
of
the
type
of
int
l Declare
the
filenm
of
the
type
of
FILE
using
pointer
l Declare
the
variable
a
of
int
type
and
initialize
a=0
l Declare
the
pointer
time_tand
give
the
values
to
b
l Using
strcut
to
declare
the
the
variables
tm,
time1
and
time
2
l Declare
the
variable
sec
of
in
type
l Open
the
file
book_no
l Using
if
and
else
statement
and
while
loop
to
state
the
privileges
l Using
pointers
to
get
the
values
of
time1
and
time2
in
tm_mday,
tm_mon
and
tm_year
l State
the
due
date
l Update
the
the
information
of
a
single
book
l Close
the
file
37. void
update_singlebook
(int)
function:
l Declare
the
variable
number
and
a
of
type
int
l Declare
the
filename
is
write_singlebook
l Print
the
data
to
the
file
write_singlebook
in
a
fixed
form
l Using
for
loop
to
print
the
data
to
the
file
write_singlebook
l Close
the
file
38. void
show_bookinfo
(void)
function:
l Declare
the
filenm
of
the
type
of
FILE
using
pointer
l Declare
the
variables
line,
a,
b,
of
the
int
type
and
initialize
a=0
l Declare
the
variable
c
and
an
array
str
contains
150
elements
of
char
type
l Read
the
file
booklist.txt
l Create
a
space
of
size
for
collection
and
displaybook,
and
then
convert
root
to
structbookdetails
using
pointer
l Read
1500-‐1
elements
from
booklist.txt
and
store
the
elements
22. 22
l Using
for
loop
to
output
the
file
to
collection[a]
l Using
while
loop
and
fseek
function
to
change
the
pointer
to
one
byte
before
the
beginning
l Using
for
loop
to
read
characters
from
file
title
l Place
the
pointer
at
one
byte
before
the
beginning
l Using
while
loop
and
fseek
function
to
change
the
pointer
to
one
byte
before
the
beginning
l Using
for
loop
to
read
characters
from
file
author
and
fseek
function
to
place
the
pointer
to
one
byte
before
the
beginning
l Using
while
loop
and
fseek
function
to
change
the
pointer
to
one
byte
before
the
beginning
l Using
for
loop
to
read
characters
from
file
shelfmark
and
fseek
function
to
place
the
pointer
to
one
byte
before
the
beginning
l Using
while
loop
and
fseek
function
to
change
the
pointer
to
one
byte
before
the
beginning
l Using
for
loop
to
read
characters
from
file
ISBN
and
fseek
function
to
place
the
pointer
to
one
byte
before
the
beginning
l Using
while
loop
and
fseek
function
to
change
the
pointer
to
one
byte
before
the
beginning
l Using
for
loop
to
read
characters
from
file
subject
and
fseek
function
to
place
the
pointer
to
one
byte
before
the
beginning
l Using
while
loop
and
fseek,
fscanf
functions
to
output
available
copies
l Using
while
loop
and
fseek,
fscanf
functions
to
output
total
copies
l Using
while
loop
and
fseek
function
to
change
the
pointer
to
one
byte
before
the
beginning
l Using
if
and
else
statement
to
check
the
place
of
the
pointer
l Using
for
while
loop
and
if
statement
to
place
the
pointer
to
one
byte
before
the
beginning,
and
output
the
data
to
borrowerID
l Close
the
file
39.
void
update_bookinfo
(void)
function:
l Declare
the
filenm
of
the
type
of
FILE
using
pointer
l Declare
the
variables
a
and
b
of
int
type
l Write
in
the
file
booklist.txt
l Output
the
data
book
number,
title,
author,
shelf
mark,
ISBN,
subject,
available
copies,
total
copies,
availability
and
borrower
ID
l Using
for
loop
to
output
the
data
l Output
booknumber
l Output
title
l Output
author
l Output
shelfmark
l Output
ISBN
l Output
subject
l Output
available_copies
l Output
total_copies
l Output
availability
l Using
for
loop
and
if
statement
to
output
borrower
ID
l Output
change
a
new
line
l Close
the
file
40.
void
exit_program(void)
function:
l Display
the
expression
Thanks
for
your
visit,
please
come
again
next
time
23. 23
l Exit
the
program
4. Implementation
See
the
C
code
with
comments
in
the
Appendix
at
the
end
of
the
report
5. Testing
If
the
program
is
run:
Main
menu
Continued
on
the
next
page
..
24. 24
1.
Register
The
information
of
users
saved
in
userlist.txt
Try
again
until
27. 27
If
you
input
wrong
password:
Test
function
in
Admin
account:
Borrow
and
return
a
book.
There
is
a
problem
here.
The
program
will
stop
here.
28. 28
Return
a
book.
See
the
available
book
list
See
the
borrowed
book
list
See
the
borrower
list
(Have
problem)
See
the
members’
information
(Have
problem)
29. 29
Change
users
privilege
Mark
book
detail
Go
back
to
my
account
30. 30
See
books
you
have
borrowed
Renew
a
book
(has
a
bug)
Change
password
(password
was
changed)
Continued
on
the
next
page
.
.
35. 35
Appendix
1. C
Source
code
(the
file
can
be
found
in
the
zipped
file
which
is
the
Assignment8.c
)
/*
Name: A Program for Creating a Library Rental System.
File Name: Assignment8.c
Copyright: Free
Author: Group 2
Description: This program is the ABC Town's library rental system which its user can log in,
register, borrow, and search books
*/
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>
#include<time.h>
#define DATABASE_PAGES 5
/* declare a number of books per page, which is 5 */
struct bookdetails /* declare a structure type namely bookdetails, which contains some
information about books*/
{
int booknumber;
char author[100];
char title[500];
char ISBN[100];
char subject[100];
char shelfmark[50];
int total_copies;
int available_copies;
char availability[50];
int borrowerID[50];
};
36. 36
struct borrowers /* declare a structure type namely borrowers, which contains some information
about borrowers*/
{
char surname[50];
char givenname[50];
char fullname[100];
int ID;
char password[8];
int userprivilege;
};
struct borrowingdata /* declare a structure type namely borrowingdata, which contains some
data about borrowing*/
{
int barcode;
char loantype[50];
char loanstatus[50];
int lastborrowed_day;
int lastborrowed_month;
int lastborrowed_year;
int due_day;
int due_month;
int due_year;
char details[20];
char borrower[20];
};
char filename[100]; /* declare a char-type variable filename (array), and four integer-type
variables as can be seen on the left */
int number_of_books;
int number_of_users;
int singlebook_amount;
int privilege;
void mainmenu(void); /* declare the 40 functions (including the main function) written in this
program */
void wrong_option_sentence(void);
38. 38
void show_bookinfo (void);
void update_bookinfo (void);
void exit_program(void);
struct bookdetails *collection; /*Declare a pointer of the type of structure bookdetails
namely collection*/
struct bookdetails **displaybook; /*Declare a pointer of the type of structure bookdetails
namely displaybook, which point to the pointer variable that point to struct bookdetails */
struct borrowers *users; /*Declare a pointer of the type of structure users namely
collection*/
struct borrowingdata *singlebook; /*Declare a pointer of the type of structure singlebook
namely collection*/
int main() /*this is the main program to perform the functions*/
{
show_bookinfo();/* implement the function show_bookinfo()*/
show_userdata();/* implement the function show_userdata()*/
mainmenu();/* implement the function mainmenu()*/
return 0;
}
void mainmenu(void) /* a function to display the main menu */
{
int a; /* declare one variable of the type of integer namely a*/
printf("n*********************************************n");
printf("nThis is the ABC Town's Library Rental System.nPlease register first
before you log in.n");
while(1)
{ /*
display the main menu */
printf("n*********************************************n");
printf(" Main Menu ");
printf("n*********************************************nn");
printf("1. Register n");
printf("2. Log in to My Accountn");
39. 39
printf("3. Search books you want to find n");
printf("4. Exit the program n");
printf("n*********************************************nn");
printf("To choose one of the options above, please choose 1 - 4: ");/* ask user
to choose*/
scanf("%d",&a); /* read the value and store it into variable a */
switch (a) /* use switch statement to choose the operation depending on
the value of a */
{
case 1 : registration(); /* case=1, implement the function
registration() */
break;
case 2 : login(); /* case=2, implement the function login() */
break;
case 3 : booksearch(); /* case=3, implement the function
booksearch() */
break;
case 4 : exit_program(); /* case=4, implement the function
exit_program() */
default : wrong_option_sentence(); /* the above cases do not occur,
implement the function exit_program() */
}
}
}
void wrong_option_sentence(void) /* a function is be implemented when the wrong option occur
*/
{
printf("nnPlease try again, the data you input was wrong.n");/* ask users to
try again */
getchar();
}
void registration(void) /* a function to register */
{
char pw , passw[8];/* declare two variables of the type of character namely pw
and passw*/
int a = 0;/* declare one variable of the type of integer namely a, and
initialize it equal to 0*/
40. 40
int b = 0;/* declare one variable of the type of integer namely b, and
initialize it equal to 0*/
show_userdata();/* implement the function show_userdata()*/
while( a == 0) /* while the user has not ever registered before */
{
printf("nn*********************************************n");
printf(" Registration");
printf("n*********************************************nn");
printf("Please enter your ID number (8 digits):n");/* ask user to enter ID
number */
scanf("%d", &users[number_of_users].ID);/* read the value and store it into
users[number_of_users].ID*/
if((users[number_of_users].ID > 99999999))/* when the inputted number is more
than 99999999, ask user to input again*/
{
printf("Your ID number should be within 8 digits.");/*ask user*/
a = 0;
}
else a = 1;
}
printf("nPlease enter your first (given) name:n");/* input the first name*/
scanf("%s", users[number_of_users].givenname);/* read the value and store it
into users[number_of_users].givenname*/
printf("nPlease enter your last name:n");/* input the last name*/
scanf("%s", users[number_of_users].surname);/* read the value and store it into
users[number_of_users].surname*/
printf("nCreate your own password:(less than 8 characters)n");/* input the new
password*/
b = 0;
while ((pw = getch())!='r') /* use getch to get a character and assign it to pw
*/
{
if ( b <8 && isprint(pw)) /* insert a if-else statement to judge operation
isprint(pw) and b<8
41. 41
as the test condition.*/
{
passw[b] = pw; /* assign pw to passw */
putchar('*'); /* use * to dispaly on the screen */
b++;
}
else if ( b > 0 && pw == 'b')/* insert a if-else statement to judge operation
pw == 'b' and b>0 */
{
--b;
putchar('b');/* back a space*/
putchar(' ');
putchar('b');/* back a space*/
}
}
passw[b]='0';/* assign NULL to passw */
for( b = 0; b<8; b++)
{
users[number_of_users].password[b] = passw[b];/* assign passw to
users[number_of_users].password */
}
printf("nnYour status is: n0. Guestn1. Studentn2. Teachern3. Adminn");/*
ask user to choose their status */
printf("nPlease enter a number between 0 - 3 from the options above: ");
scanf("%d", &users[number_of_users].userprivilege); /* read the value and
store it into the addres of users[number_of_users].userprivilege*/
strcpy(users[number_of_users].fullname, users[number_of_users].surname);/*
assign users[number_of_users].surname to number_of_users].fullname*/
strcat(users[number_of_users].fullname, users[number_of_users].givenname);/*
assign users[number_of_users].givenname to number_of_users].fullname*/
number_of_users += 1;
showupdate_userdata();/* implement the function showupdate_userdata()*/
printf("nRegistration success! Now you have been registered in this
library.n");
mainmenu();/* implement the function mainmenu()*/
42. 42
}
void show_userdata(void)/* a function to store the data of user */
{
FILE *filenm;/* declare one pointer of the type of file namely filenm */
int line;/* declare one variable of the type of integer namely line*/
int a = 0;/* declare one variable of the type of integer namely a, and
initialize it equal to 0*/
int b;/* declare one variable of the type of integer namely b*/
char c;/* declare one variable of the type of character namely c*/
char strarray[1500];/* declare one variable of the type of character namely
strarray*/
filenm = file_read ("userlist.txt");/* assign file_read to filenm */
line = line_number (filenm);/* assign line_number (filenm) to line */
users = (struct borrowers *) malloc( (line+1) * sizeof(struct borrowers)); /*
assign space to users */
for (a = 0; a < line; a++)
{
fscanf(filenm,"%d",&users[a].ID);/*output the value of users[a].ID into the
file which is pointed by filenm*/
while( isspace(fgetc(filenm)) );/* fix the position for filenm renewedly */
fseek(filenm,-1L,SEEK_CUR); /* using fseek to move the any file
position in filenm by the offset -1L from the current position */
for(b = 0; (c=fgetc(filenm))!='t' ; b++)
users[a].surname[b] = c;/* assign c to
users[a].surname[b] */
users[a].surname[b] = '0';/* assign '0' to
users[a].surname[b]*/
while( isspace(fgetc(filenm)) );/* fix the position for filenm renewedly */
fseek(filenm,-1L,SEEK_CUR); /* using fseek to move the any file
position in filenm by the offset -1L from the current position */
for(b = 0; (c = fgetc(filenm))!='t' ;b++)
users[a].givenname[b] = c;/* assign c to
users[a].givenname[b] */
users[a].givenname[b] = '0';/* assign '0' to
users[a].givenname[b] */
strcpy(strarray,users[a].surname);/* assign
users[a].surname to strarray*/
43. 43
strcat(strarray," ");/* assign " " to strarray*/
strcpy(users[a].fullname
,strcat(strarray,users[a].givenname));/* assign strarray to users[a].fullname */
while( isspace(fgetc(filenm)) );/* fix the position for filenm renewedly */
fseek(filenm,-1L,SEEK_CUR); /* using fseek to move the any file
position in filenm by the offset -1L from the current position */
for(b = 0; (c=fgetc(filenm))!='t' ; b++)
users[a].password[b] = c;/* assign c to
users[a].password[b] */
users[a].password[b] = '0';/* assign '0' to
users[a].password[b] */
while( isspace(fgetc(filenm)) ); /* fix the position for filenm renewedly */
fseek(filenm,-1L,SEEK_CUR); /* using fseek to move the any file
position in filenm by the offset -1L from the current position */
fscanf(filenm,"%d",&users[a].userprivilege);
/*output the value of users[a].userprivilege into the file which is
pointed by filenm*/
}
number_of_users = line;/* assign line to number_of_users */
file_close(filenm); /* close the file*/
return;
}
int line_number(FILE *filenm) /* a function to add the number of line*/
{
char a;/* declare one variable of the type of integer namely a*/
int l = 0;/* declare one variable of the type of integer namely l, and
initialize it equal to 0*/
while( (a = fgetc(filenm)) != EOF)
if (a == 'n') l++; /* when the a ='n', the value of l plus one.*/
rewind(filenm);/* let filenm point to the outset again*/
return l;
}
void showupdate_userdata (void)/* a function to store the data of user */
{
44. 44
FILE *filenm;/* declare one pointer of the type of file namely filenm */
int a;/* declare one variable of the type of integer namely a*/
filenm = file_write ("userlist.txt");/* assign file_read to filenm */
for (a = 0; a < number_of_users; a++)
{ /*input the data of user to the file */
fprintf(filenm,"%dt%st%st%st%dn",users[a].ID,users[a].givenname,users[a].su
rname,users[a].password,users[a].userprivilege);
}
file_close(filenm);/* close the file*/
}
FILE* file_read ( char *afile)/* a function to read the file */
{
FILE *filenm;/* declare one pointer of the type of file namely filenm */
strcpy(filename,afile);/* assign afile to filename */
filenm = fopen(filename,"r");/*open and read the file of filename and assign it
to filenm*/
if(filenm == NULL) /* when the file is empty, ask user */
{
printf("nThe file cannot be opened: %s !n", filename);
exit(1);
}
return filenm;
}
FILE* file_write (char *afile)/* a function to write the file */
{
FILE *filenm;/* declare one pointer of the type of file namely filenm */
strcpy(filename,afile);/* assign afile to filename */
filenm = fopen(filename,"w");/*open and write the file of filename and assign it
to filenm*/
if(filenm == NULL)/* when the file is empty, ask user */
{
printf("nThe file cannot be opened: %s !n", filename);
45. 45
system("pause");
exit(1);
}
return filenm;
}
FILE* file_append (char *afile)/* a function to append the file */
{
FILE *filenm;/* declare one pointer of the type of file namely filenm */
strcpy(filename,afile);/* assign afile to filename */
filenm = fopen(filename,"a");/*open and append the file of filename and assign
it to filenm*/
if(filenm == NULL)/* when the file is empty, ask user */
{
printf("nThe file cannot be opened: %s !n", filename);
system("pause");
exit(1);
}
return filenm;
}
void file_close(FILE *filenm)/* a function to close the file */
{
if (fclose(filenm)!=0)/* when the file that has been clodsed does not return 0,
ask user */
printf("The file cannot be closed: %s!n",filename);
}
void login (void)/* a function to log in */
{
int a , b = 0;/* declare two variables of the type of integer namely a and b,and
initialize b equal to 0*/
char y[100];/* declare one variable of the type of character namely y*/
char x[100];/* declare one variable of the type of character namely z*/
char z[100];/* declare one variable of the type of character namely x*/
46. 46
printf("nn*********************************************n");
printf(" Log In");
printf("n*********************************************nn");
printf("nPlease enter your first (given) name:n");/* input the first name*/
scanf("%s",y); /*read and store the value into y*/
printf("nPlease enter your surname:n");/* input the surname name*/
scanf("%s",x); /*read and store the value into x*/
printf("nPlease enter your ID number:n");/* input the ID number*/
scanf("%d",&a); /*read and store the value into the address of a*/
printf("nPlease enter your password:n");/* input the password*/
scanf("%s",z); /*read and store the value into z*/
while(b < number_of_users)
{
if(strcmp(users[b].surname,x) == 0 && strcmp(users[b].givenname,y) == 0 && a ==
users[b].ID && strcmp(users[b].password,z) == 0)
{/*compare the inputted data with the data in the struct*/
if((users[b].userprivilege == 1)||(users[b].userprivilege ==
2))/* when the user is student or teacher*/
{
borrower_function(a,x);/* implement the function
borrower_function(a,x)*/
}
else
{
if(users[b].userprivilege == 3)/* when the user is admin*/
{
admin(a,users[b].fullname);/* implement the function
admin(a,users[b].fullname)*/
}
else /* when the user is admin*/
{
printf("nYou can only search the book because you are
guest only.n");
mainmenu();/* implement the function mainmenu()*/
exit_program();/* implement the function
exit_program()*/
}
47. 47
}
}
else{b++;}
}
printf("nPerhaps the data you entered was wrong or you haven't registered yet.
Please try again.n");
mainmenu();/* implement the function mainmenu()*/
}
void borrower_function (int id , char* name)/* a function to display the information of
borrower */
{
char b[8];/* declare one variable of the type of character namely b*/
int a;/* declare one variable of the type of integer namely a*/
int i = 0;/* declare one variable of the type of integer namely i, and
initialize it equal to 0 */
printf("nn*********************************************n");/*menu*/
printf(" My Account");
printf("n*********************************************nn");
printf("n1. See books you have borrowedn2. Renew a book n3. Change your
passwordn4. Return to the main menun");
printf("nTo choose one of the options above, please choose 1 - 4: ");/*ask
user to choose*/
scanf("%d",&a);/* read and store the inputted value into the address of a*/
switch(a) /* use switch statement to choose the operation depending on the value
of a */
{
case 1: loan_list(id , name); break;/* case=1, implement the function
loan_list(id , name) */
case 2: renew(); break;/* case=2, implement the function renew()*/
case 3: while(i < number_of_users)
{
if(id == users[i].ID)/* the original password is ritht*/
{
printf("Please enter your new password:");/*ask user to
input password*/
scanf("%s", b); /* read and store the inputted value
into b*/
48. 48
strcpy(users[i].password, b);/* assign b to
users[i].password*/
printf("nYour password has been changed!n");
showupdate_userdata();/*implement the function
showupdate_userdata()*/
borrower_function(id , name);/*implement the function
borrower_function(id , name)*/
}
else{i++;}
}
printf("nYour original password is wrong.n");
break;
case 4: mainmenu(); break;/* case=4, implement the function mainmenu()*/
}
}
void loan_list(int id,char* name)/* a function to display the list of loan */
{
FILE *filenm;/* declare one pointer of the type of file namely filenm */
int a = 0;/* declare one variable of the type of integer namely a, and
initialize it equal to 0 */
int b = 0;/* declare one variable of the type of integer namely b, and
initialize it equal to 0 */
int x = 0;/* declare one variable of the type of integer namely x, and
initialize it equal to 0 */
int y;/* declare one variable of the type of integer namely y*/
int no = 0;/* declare one variable of the type of integer namely no, and
initialize it equal to 0 */
for (a = 0; a < number_of_books; a++)
{
while (x < number_of_users)
{
printf(" "); /*output 2*/
if (collection[a].borrowerID[x] == id)/* the id is coincident*/
{
printf("2"); /*output 2*/
49. 49
no++;
filenm = open_singlebook(collection[a].booknumber);/* assign
open_singlebook(collection[a].booknumber) to filenm*/
show_singlebook(collection[a].booknumber);/*implement the
function show_singlebook(collection[a].booknumber)*/
while (b < singlebook_amount)
{
if (strcmp(singlebook[b].borrower,name) == 0)/* the name
is coincident*/
{
printf("%st%dt %d-%d-
%dn",collection[a].title,singlebook[b].due_year,singlebook[b].due_month,singlebook[b].due_day
);
}/*display the information of loan*/
else{b++;}
}
x++;
}
else{x++;}
}
}
if (no == 0)/* the user nevers borrow books*/
{
printf("nYou haven't borrowed any book!n");
}
else
{ /* the menu of renewing*/
printf("Do you want to renew your book?n");
printf("n1. Yesn2. Nonn");
printf("To choose the option above, please enter 1 or 2: ");/*ask user to
choose*/
scanf("%d",&y);/* read and store the inputted value into y*/
if(y == 1)
{
renew();/*implement the function showupdate_userdata()*/
}
else
50. 50
{
borrower_function(id,name);/*implement the function
borrower_function(id,name)*/
}
}
borrower_function(id,name);/*implement the function borrower_function(id,name)*/
}
FILE* open_singlebook (int number)/* a function to open the file of single book*/
{
FILE *filenm;/* declare one pointer of the type of file namely filenm */
char book_no[15];/* declare one variable of the type of character namely
book_no*/
char first[]="book";/* declare one variable of the type of character namely
first,assign "book" to it*/
char last[]=".txt";/* declare one variable of the type of character namely
last,assign ".txt" to it*/
char *file_name;/* declare one pointer of the type of character namely
file_name*/
integerstring_conversion(book_no,number);/* implement the function
integerstring_conversion(book_no,number)*/
file_name = strcat(first,book_no);/*assign book_no to first, then assign it to
file_name*/
file_name = strcat(file_name,last);/*assign book_no to last, then assign it to
file_name*/
filenm = file_read (file_name);/*assign file_read (file_name) to filenm*/
return filenm;
}
FILE* write_singlebook (int number)/* a function to write the file of single book*/
{
FILE *filenm;/* declare one pointer of the type of file namely filenm */
char book_no[15];/* declare one variable of the type of character namely
book_no*/
char first[]="book";/* declare one variable of the type of character namely
first, assign "book" to it*/
char last[]=".txt";/* declare one variable of the type of character namely last,
assign ".txt" to it*/
51. 51
char *file_name;/* declare one pointer of the type of character namely
file_name*/
integerstring_conversion(book_no,number);/* implement the function
integerstring_conversion(book_no,number)*/
file_name = strcat(first,book_no);/*assign book_no to first, then assign it to
file_name*/
file_name = strcat(file_name,last);/*assign book_no to last, then assign it to
file_name*/
filenm = file_write (file_name);/*assign file_read (file_name) to filenm*/
return filenm;
}
char * integerstring_conversion(char *string, int n)/* a function to convert the string*/
{
int a;/* declare one variable of the type of integer namely a*/
if((a = n/10) != 0) string = integerstring_conversion(string,a);
*(string++) = (n%10+'0'); /*convert the number into integer*/
*string = '0';
return string;
}
void show_singlebook (int no)/* a function to store the data of single book*/
{
FILE *filenm;/* declare one pointer of the type of file namely filenm */
int line;/* declare one variable of the type of integer namely line*/
int a = 0;/* declare one variable of the type of integer namely a, and
initialize it equal to 0*/
int b;/* declare one variable of the type of integer namely b*/
char str[1500];/* declare one string of the type of character namely str*/
char w;/* declare one variable of the type of character namely w*/
filenm = open_singlebook (no);/* assign open_singlebook (no) to filenm */
line = line_number (filenm);/* assign line_number (filenm) to line */
line = line-2;/* assign line-2 to line */
singlebook = (struct borrowingdata *) malloc( line * sizeof(struct
borrowingdata));/* assign space to singlebook */
fgets(str,1500,filenm);/*read filenm and store into str*/
52. 52
for (a = 0; a < line; a++)
{
fscanf(filenm,"%d",&singlebook[a].barcode);/*output the value of
singlebook[a].barcode into the file which is pointed by filenm*/
while( isspace(fgetc(filenm)) );
fseek(filenm,-1L,SEEK_CUR);/* fix the position for filenm renewedly */
for(b = 0; !isspace(w = fgetc(filenm)) ; b++)
singlebook[a].loantype[b] = w;/* assign w to
singlebook[a].loantype[b] */
singlebook[a].loantype[b] = '0';/* assign '0' to
singlebook[a].loantype[b] */
fseek(filenm,-1L,SEEK_CUR); /* fix the position for filenm
renewedly */
while( isspace(fgetc(filenm)) );
fseek(filenm,-1L,SEEK_CUR); /* fix the position for filenm renewedly
*/
for(b=0; !isspace(w = fgetc(filenm)) ;b++)
singlebook[a].loanstatus[b] = w;/* assign w to
singlebook[a].loanstatus[b] */
singlebook[a].loanstatus[b] = '0';/* assign '0' to
singlebook[a].loanstatus[b] */
fseek(filenm,-1L,SEEK_CUR); /* fix the position for filenm
renewedly */
while( isspace(fgetc(filenm)) );
fseek(filenm,-1L,SEEK_CUR);/* fix the position for filenm renewedly */
fscanf(filenm,"%d/",&singlebook[a].lastborrowed_day);
/*output the value of singlebook[a].lastborrowed_day into the file
which is pointed by filenm*/
fscanf(filenm,"%d/",&singlebook[a].lastborrowed_month);
/*output the value of singlebook[a].lastborrowed_month into the file
which is pointed by filenm*/
fscanf(filenm,"%d",&singlebook[a].lastborrowed_year);
/*output the value of singlebook[a].lastborrowed_year into the file
which is pointed by filenm*/
while( isspace(fgetc(filenm)) );
fseek(filenm,-1L,SEEK_CUR);/* fix the position for filenm renewedly */
fscanf(filenm,"%d/",&singlebook[a].due_day);
/*output the value of singlebook[a].due_day into the file which is
pointed by filenm*/
fscanf(filenm,"%d/",&singlebook[a].due_month);