Create a system managing a mini library system. Every book corresponds to a reco
ID: 3777053 • Letter: C
Question
Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named "mylibrary.txt". Each record consists of 6 fields (Book ID, Title, Author, Possession, checked out Date, Due Date) separated by comma: No comma '', "in title or author name. This mini library keeps the record for each book in the library. Different books can share the book "Title". But the "Book ID" for each book is unique. One author may have multiple books. Eg. Both book2 and book3 are written by author Possession field is "Library" means this book is kept in library, such as book #001. Otherwise, this book is checked out by the corresponding user. E.g. book #3 is checked out by User1. A user is allowed to check out up to 3 books. The "Checked out Date" field specifies the time of the latest checked out date. The loan period for each book is 30 days. "The Due Data" filed specifies the time the book should be returned. This system should provide a menu with following functionalities that the bookkeeper can choose from at the top-level menu: Ask for book ID. Examine if this book exists. If no, print a message "No such book!" and then go to 4). Otherwise, 3) Ask for current date and check if it is a legal date. If illegal, output "illegal input date" and go to step 7); otherwise, 4). Check if current date has passed "Due Date". If no, go to step 6). Otherwise, 5) Output the current fine to this book. Assume user has already paid for fine if it exists. Update the possession and date fields of the corresponding record. After that, print message "book*** return successfully!" and then go to 7). Provide options "t" for "" or "b" for "Back to main menu". (If "", go to step 1))Explanation / Answer
//list of header files
#include<stdio.h> //contains printf,scanf etc
#include<conio.h> //contains delay(),getch(),gotoxy(),etc.
#include <stdlib.h> // contains exit();
#include<string.h> //contains strcmp(),strcpy(),strlen(),etc
#include<ctype.h> //contains toupper(), tolower(),etc
#include<dos.h> //contains _dos_getdate
#include<time.h>
#include<bios.h>
struct Date
{
int mm,dd,yy;
};
struct books
{
int id;
char stname[20];
char name[20];
char Author[20];
int quantity;
float Price;
int count;
struct Date issued;
struct Date duedate;
};
main()
{
clrscr();
int p,c=0;
while(another=='y')
{
printf("Enter Book ID:");
scanf("%d",&p);
checkid(int t);
if(checkid(t) == 0)
{
printf("The book id already exists");
ask current date(int);
if(ask current date(valid date) == 0)
{
printf(" date is valid");
checkcurentpaseed();
}
else
printf(" date is not valid");
returnfunc()
else
printf(" no such book exits");
check currentdate();
int checkid(int t) //check whether the book is exist in library or not
{
rewind(fp);
while(fread(&a,sizeof(a),1,fp)==1)
if(a.id==t)
return 0; //returns 0 if book exits
return 1; //return 1 if it not
}
int t(void) //for time
{
time_t t;
time(&t);
printf("Date and time:%s ",ctime(&t));
return 0 ;
}
ask current date(int valid date);
int dd, mm, yy; /* given date */
int valid date; /* flag to indicate date validity */
clrscr();
printf("Enter date as dd/mm/yyyy: ");
scanf("%d/%d/%d", &dd, &mm, &yy);
/* determine validity of given date */
valid date= 0;
if (yy != 0) /* check year */
{
if (mm >= 1 && mm <= 12) /* check month */
{
/* determine number of days in given month */
int mdays;
if (mm == 2)
mdays = (yy % 4 == 0 && yy % 100 != 0 || yy % 400 == 0) ? 29 : 28;
else if (mm == 4 || mm == 6 || mm == 9 || mm == 11)
mdays = 30;
else mdays = 31;
if (dd >= 1 && dd <= mdays)
valid date= 1;
}
}
}
checkcurentpaseed()
{
struct dosdate_t d; //for current date
_dos_getdate(&d);
a.issued.dd=d.day;
a.issued.mm=d.month;
a.issued.yy=d.year;
printf("Issued date=%d-%d-%d",a.issued.dd,a.issued.mm,a.issued.yy);
printf("The BOOK of ID %d is issued",a.id);
a.duedate.dd=a.issued.dd+RETURNTIME; //for return date
a.duedate.mm=a.issued.mm;
a.duedate.yy=a.issued.yy;
if(a.duedate.dd>30)
{
a.duedate.mm+=a.duedate.dd/30;
a.duedate.dd-=30;
}
if(a.duedate.mm>12)
{
a.duedate.yy+=a.duedate.mm/12;
a.duedate.mm-=12;
}
if(a.duedate.dd<a.issued.dd)
{
printf("due date passed");
printf('the student already paid);
update()
printf('book**** return sucessfully);
returnfunction();
}
if(days>=15)
printf('the fine is:%d',days*1)
void returnfunction(void)
{
printf( "Selections: " );
scanf( "%d", &choice);
switch ( choice ) {
case 't': /* Note the colon, not a semicolon */
printf('tryagain')
break;
case 'b':
printf('back');
break;
default:
printf( "Bad choice, quitting! " );
break;
}
}
void update(void) //edit information about book
{
clrscr();
int c=0;
int d,e;
printf("****update Books Section****");
char another='y';
while(another=='y')
{
clrscr();
printf("Enter Book Id to be edited:");
scanf("%d",&d);
fp=fopen("mylaibrary.txt","rb+");
while(fread(&a,sizeof(a),1,fp)==1)
{
if(checkid(d)==0)
{
printf("The book is availble");
printf("The Book ID:%d",a.id);
printf("Enter new name:");scanf("%s",a.name);
printf("Enter new Author:");scanf("%s",a.Author);
printf("Enter new quantity:");scanf("%d",&a.quantity);
printf("Enter new price:");scanf("%f",&a.Price);
printf("Enter new rackno:");scanf("%d",&a.rackno);
printf("The record is modified");
fseek(fp,ftell(fp)-sizeof(a),0);
fwrite(&a,sizeof(a),1,fp);
fclose(fp);
c=1;
}
if(c==0)
{
printf("No record found");
}
}
printf("Modify another Record?(Y/N)");
fflush(stdin);
another=getch() ;
}
returnfunction();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.