SlideShare a Scribd company logo
// C programming 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 User. 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 title (read). Ask for author.
Generate a book ID by adding one to the current largest book ID. Add the record of the new
book into library with generated book ID, title, author, possession="library", checked out
date="null" and due date="null". After that, print message "book*** added successfully!"
and go to step 5). Provide options "t" for "" and "b" for "Back to main menu". (If "", go to
step 1))
Solution
#include
#include
#include //contains delay(),getch()etc.
#include
#include //contains strcmp(),strcpy(),strlen(),etc
#include //contains toupper(), tolower(),etc
#include //contains _dos_getdate
#include
#define RETURNTIME 15
FILE *fp,*ft,*fs;
struct l_Date
{
int mm,dd,yy;
};
struct record
{
int bookid;
char title[20];
char Author[20];
char possession[20];
struct l_Date checkedout_date;
struct l_Date due_date;
};
struct record r;
void main()
{
clrscr();
int i;
printf(" a. Add Books ");
printf("b. Delete books");
printf("c. Search Books");
printf("d. Issue Books");
printf("e. View Book list");
printf("f. Edit Book's Record");
printf("g. Close Application");
printf("Enter your choice:");
switch(getch())
{
case 'a':
addbooks();
break;
case 'b':
deletebooks();
break;
case 'c':
searchbooks();
break;
case 'd':
issuebooks();
break;
case 'e':
viewbooks();
break;
case 'f':
editbooks();
break;
case 'g':
{
clrscr();
printf("application is closing.. ");
exit(0);
}
default:
{
printf(" Please re-entered correct option");
}
}
}
void addbooks(void) //funtion to add books
{
int i;
fp=fopen("Bibek.dat","ab+");
fseek(fp,0,SEEK_END);
fwrite(&r,sizeof(r),1,fp);
fclose(fp);
printf("The record is sucessfully saved");
printf("add any more?(t / b):");//t to try again and b to back
if(getch()=='b')
else
addbooks();
}
}
void deletebooks() //function delete record from file fp
{
int d;
char another='y';
while(another=='y') //infinite loop
{
printf("Enter the Book ID to delete:");
scanf("%d",&d);
fp=fopen("Bibek.dat","rb+");
rewind(fp);
while(fread(&r,sizeof(r),1,fp)==1)
{
if(r.bookid==d)
{
printf("The book record is available");
printf("Book name is %s",r.title);
}
}
if(findbook!='t')
{
gotoxy(10,10);
printf("No record is found modify the search");
}
if(findbook=='t' )
{
printf("Do you want to delete it?(Y/N):");
if(getch()=='y')
{
ft=fopen("test.dat","wb+"); //temporary file for delete
rewind(fp);
while(fread(&r,sizeof(r),1,fp)==1)
{
if(r.id!=d)
{
fseek(ft,0,SEEK_CUR);
fwrite(&r,sizeof(r),1,ft); //write all in tempory file except that
} //we want to delete
}
fclose(ft);
fclose(fp);
remove("Bibek.dat");
rename("test.dat","Bibek.dat"); //copy all item from temporary file to fp except that
fp=fopen("Bibek.dat","rb+"); //we want to delete
if(findbook=='t')
{
printf("The record is sucessfully deleted");
printf("Delete another record?(Y/N)");
}
}
else
another=getch();
}
}
}
void searchbooks()
{
int d;
printf("*****************************Search
Books*********************************");
printf(" 1. Search By ID");
printf("2. Search By Name");
printf("Enter Your Choice");
fp=fopen("Bibek.dat","rb+"); //open file for reading propose
rewind(fp); //move pointer at the begining of file
switch(getch())
{
case '1':
{
printf("****Search Books By Id****");
printf("Enter the book id:");
scanf("%d",&d);
printf("Searching........");
while(fread(&r,sizeof(r),1,fp)==1)
{
if(r.id==d)
{
printf("The Book is available");
printf(" ID:%d",r.bookid);
printf(" Name:%s",r.title);
printf(" %s ",r.Author);
findbook='t';
}
}
if(findbook!='t') //checks whether conditiion enters inside loop or not
{
printf("aNo Record Found");
}
printf("Try another search?(Y/N)");
if(getch()=='y')
searchbooks();
else
break;
}
case '2':
{
char s[15];
printf("****Search Books By Name****");
printf("Enter Book Name:");
scanf("%s",s);
int d=0;
while(fread(&r,sizeof(r),1,fp)==1)
{
if(strcmp(r.title,(s))==0)
{
printf("The Book is available");
printf(" ID:%d",r.bookid);
printf(" Name:%s",r.title);gotoxy(47,10);
printf(" Author:%s",r.Author);
printf("possession:%s",r.possession);
d++;
}
}
if(d==0)
{printf("aNo Record Found");
}
printf("Try another search?(Y/N)");
if(getch()=='y')
searchbooks();
else
break;
}
default :
getch();
searchbooks();
}
fclose(fp);
}
void editbooks(void) //edit information about book
{
int c=0;
int d,e;
printf("****Edit Books Section****");
char another='y';
while(another=='y')
{
printf("Enter Book Id to be edited:");
scanf("%d",&d);
fp=fopen("Bibek.dat","rb+");
while(fread(&r,sizeof(r),1,fp)==1)
{
if(checkid(d)==0)
{
printf("The book is availble");
printf("The Book ID:%d",r.bookid);
printf("Enter new name:");scanf("%s",r.title);
printf("Enter new Author:");scanf("%s",r.Author);
printf("The record is modified");
fseek(fp,ftell(fp)-sizeof(r),0);
fwrite(&r,sizeof(r),1,fp);
fclose(fp);
c=1;
}
if(c==0)
{
printf("No record found");
}
}
printf("Modify another Record?(Y/N)");
fflush(stdin);
another=getch() ;
}
returnfunc();
}
void returnfunc(void)
{
{
printf(" Press ENTER to return to main menu");
}
if(getch()==13) //allow only use of enter
mainmenu();
else
goto r;
}
int getdata()
{
int t;
printf("Enter the Information Below");
printf("Category:");
printf("%s",catagories[s-1]);
printf("Book ID:t");
scanf("%d",&t);
if(checkid(t) == 0)
{
printf("aThe book id already existsa");
getch();
return 0;
}
r.bookid=t;
printf("Book Name:");
scanf("%s",r.title);
printf("Author:");
scanf("%s",r.Author);
printf("Possession:");
scanf("%d",&r.possession);
return 1;
}
int checkid(int t) //check whether the book is exist in library or not
{
rewind(fp);
while(fread(&r,sizeof(r),1,fp)==1)
if(r.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 ;
}
void Password(void)
{
char d[25]="Password Protected";
char ch,pass[10];
int i=0,j;
for(j=0;j<20;j++)
{
delay(50);
printf("*");
}
for(j=0;j<20;j++)
{
delay(50);
printf("%c",d[j]);
}
for(j=0;j<20;j++)
{
delay(50);
printf("*");
}
gotoxy(10,10);
gotoxy(15,7);
printf("Enter Password:");
while(ch!=13)
{
ch=getch();
if(ch!=13 && ch!=8){
putch('*');
pass[i] = ch;
i++;
}
}
pass[i] = '0';
if(strcmp(pass,password)==0)
{
;
printf("Password match");
printf("Press any key to countinue.....");
mainmenu();
}
else
{
printf("aWarning!! Incorrect Password");
getch();
Password();
}
}
void issuerecord() //display issued book's information
{
printf("The Book has taken by Mr. %s",a.stname);
printf("Issued Date:%d-%d-%d",r.issued.dd,r.checkout_date.mm,r.checkout_date.yy);
printf("Returning Date:%d-%d-%d",r.due_date.dd,r.due_date.mm,r.due_date.yy);
}

More Related Content

Similar to C programming Create a system managing a mini library system. Eve.pdf

XML and Web Services
XML and Web ServicesXML and Web Services
XML and Web Services
Henry Osborne
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in python
Lifna C.S
 
Library Managment System - C++ Program
Library Managment System - C++ ProgramLibrary Managment System - C++ Program
Library Managment System - C++ Program
Muhammad Danish Badar
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
shahidqamar17
 
#include stdafx.h#include iostream#include Stringusing.pdf
#include stdafx.h#include iostream#include Stringusing.pdf#include stdafx.h#include iostream#include Stringusing.pdf
#include stdafx.h#include iostream#include Stringusing.pdf
anokhilalmobile
 
File mangement
File mangementFile mangement
File mangement
Jigarthacker
 
Xquery basics tutorial
Xquery basics  tutorialXquery basics  tutorial
Xquery basics tutorial
Divya Bodkhe
 
.Net (F # ) Records, lists
.Net (F # ) Records, lists.Net (F # ) Records, lists
.Net (F # ) Records, lists
DrRajeshreeKhande
 
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdfbuildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
lallababa
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
kinan keshkeh
 

Similar to C programming Create a system managing a mini library system. Eve.pdf (10)

XML and Web Services
XML and Web ServicesXML and Web Services
XML and Web Services
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in python
 
Library Managment System - C++ Program
Library Managment System - C++ ProgramLibrary Managment System - C++ Program
Library Managment System - C++ Program
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
 
#include stdafx.h#include iostream#include Stringusing.pdf
#include stdafx.h#include iostream#include Stringusing.pdf#include stdafx.h#include iostream#include Stringusing.pdf
#include stdafx.h#include iostream#include Stringusing.pdf
 
File mangement
File mangementFile mangement
File mangement
 
Xquery basics tutorial
Xquery basics  tutorialXquery basics  tutorial
Xquery basics tutorial
 
.Net (F # ) Records, lists
.Net (F # ) Records, lists.Net (F # ) Records, lists
.Net (F # ) Records, lists
 
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdfbuildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
 

More from fazanmobiles

H&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
H&M The Challenges of Global Expansion and the Move to adopt Intern.pdfH&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
H&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
fazanmobiles
 
C++ ProgrammingYou are to develop a program to read Baseball playe.pdf
C++ ProgrammingYou are to develop a program to read Baseball playe.pdfC++ ProgrammingYou are to develop a program to read Baseball playe.pdf
C++ ProgrammingYou are to develop a program to read Baseball playe.pdf
fazanmobiles
 
Discuss the differences between a lists regular iterator, which su.pdf
Discuss the differences between a lists regular iterator, which su.pdfDiscuss the differences between a lists regular iterator, which su.pdf
Discuss the differences between a lists regular iterator, which su.pdf
fazanmobiles
 
Feasibility is an important issue in security system formulation. Wh.pdf
Feasibility is an important issue in security system formulation. Wh.pdfFeasibility is an important issue in security system formulation. Wh.pdf
Feasibility is an important issue in security system formulation. Wh.pdf
fazanmobiles
 
CopyPaste the sentence into the text box. Then, insert punctuat.pdf
CopyPaste the sentence into the text box. Then, insert punctuat.pdfCopyPaste the sentence into the text box. Then, insert punctuat.pdf
CopyPaste the sentence into the text box. Then, insert punctuat.pdf
fazanmobiles
 
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdfestion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
fazanmobiles
 
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdfDr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
fazanmobiles
 
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdfCHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
fazanmobiles
 
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdfcan Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
fazanmobiles
 
An analyst has decided to capitalize the operating leases of Company.pdf
An analyst has decided to capitalize the operating leases of Company.pdfAn analyst has decided to capitalize the operating leases of Company.pdf
An analyst has decided to capitalize the operating leases of Company.pdf
fazanmobiles
 
Why is a visual analysis important in communicating findings in a bu.pdf
Why is a visual analysis important in communicating findings in a bu.pdfWhy is a visual analysis important in communicating findings in a bu.pdf
Why is a visual analysis important in communicating findings in a bu.pdf
fazanmobiles
 
what usually happens to autoimmune antibody-producing clones dur.pdf
what usually happens to autoimmune antibody-producing clones dur.pdfwhat usually happens to autoimmune antibody-producing clones dur.pdf
what usually happens to autoimmune antibody-producing clones dur.pdf
fazanmobiles
 
Why platinum and its compounds display a variety of colorSoluti.pdf
Why platinum and its compounds display a variety of colorSoluti.pdfWhy platinum and its compounds display a variety of colorSoluti.pdf
Why platinum and its compounds display a variety of colorSoluti.pdf
fazanmobiles
 
What is Vertical versus horizontal integration in healthcare W.pdf
What is Vertical versus horizontal integration in healthcare W.pdfWhat is Vertical versus horizontal integration in healthcare W.pdf
What is Vertical versus horizontal integration in healthcare W.pdf
fazanmobiles
 
What is the role of the financial system Name and describe two mark.pdf
What is the role of the financial system Name and describe two mark.pdfWhat is the role of the financial system Name and describe two mark.pdf
What is the role of the financial system Name and describe two mark.pdf
fazanmobiles
 
What is the difference between a paired artery and an unpaired arter.pdf
What is the difference between a paired artery and an unpaired arter.pdfWhat is the difference between a paired artery and an unpaired arter.pdf
What is the difference between a paired artery and an unpaired arter.pdf
fazanmobiles
 
What has Microsoft improved in Windows Server 2012 when it comes to .pdf
What has Microsoft improved in Windows Server 2012 when it comes to .pdfWhat has Microsoft improved in Windows Server 2012 when it comes to .pdf
What has Microsoft improved in Windows Server 2012 when it comes to .pdf
fazanmobiles
 
What are the steps for developing Developing a Project Scope Stateme.pdf
What are the steps for developing Developing a Project Scope Stateme.pdfWhat are the steps for developing Developing a Project Scope Stateme.pdf
What are the steps for developing Developing a Project Scope Stateme.pdf
fazanmobiles
 
True or False Questions1) Good technology transfer between pr.pdf
True or False Questions1) Good technology transfer between pr.pdfTrue or False Questions1) Good technology transfer between pr.pdf
True or False Questions1) Good technology transfer between pr.pdf
fazanmobiles
 
The symbiosis between plant roots and fungi is characterized byQu.pdf
The symbiosis between plant roots and fungi is characterized byQu.pdfThe symbiosis between plant roots and fungi is characterized byQu.pdf
The symbiosis between plant roots and fungi is characterized byQu.pdf
fazanmobiles
 

More from fazanmobiles (20)

H&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
H&M The Challenges of Global Expansion and the Move to adopt Intern.pdfH&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
H&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
 
C++ ProgrammingYou are to develop a program to read Baseball playe.pdf
C++ ProgrammingYou are to develop a program to read Baseball playe.pdfC++ ProgrammingYou are to develop a program to read Baseball playe.pdf
C++ ProgrammingYou are to develop a program to read Baseball playe.pdf
 
Discuss the differences between a lists regular iterator, which su.pdf
Discuss the differences between a lists regular iterator, which su.pdfDiscuss the differences between a lists regular iterator, which su.pdf
Discuss the differences between a lists regular iterator, which su.pdf
 
Feasibility is an important issue in security system formulation. Wh.pdf
Feasibility is an important issue in security system formulation. Wh.pdfFeasibility is an important issue in security system formulation. Wh.pdf
Feasibility is an important issue in security system formulation. Wh.pdf
 
CopyPaste the sentence into the text box. Then, insert punctuat.pdf
CopyPaste the sentence into the text box. Then, insert punctuat.pdfCopyPaste the sentence into the text box. Then, insert punctuat.pdf
CopyPaste the sentence into the text box. Then, insert punctuat.pdf
 
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdfestion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
 
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdfDr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
 
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdfCHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
 
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdfcan Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
 
An analyst has decided to capitalize the operating leases of Company.pdf
An analyst has decided to capitalize the operating leases of Company.pdfAn analyst has decided to capitalize the operating leases of Company.pdf
An analyst has decided to capitalize the operating leases of Company.pdf
 
Why is a visual analysis important in communicating findings in a bu.pdf
Why is a visual analysis important in communicating findings in a bu.pdfWhy is a visual analysis important in communicating findings in a bu.pdf
Why is a visual analysis important in communicating findings in a bu.pdf
 
what usually happens to autoimmune antibody-producing clones dur.pdf
what usually happens to autoimmune antibody-producing clones dur.pdfwhat usually happens to autoimmune antibody-producing clones dur.pdf
what usually happens to autoimmune antibody-producing clones dur.pdf
 
Why platinum and its compounds display a variety of colorSoluti.pdf
Why platinum and its compounds display a variety of colorSoluti.pdfWhy platinum and its compounds display a variety of colorSoluti.pdf
Why platinum and its compounds display a variety of colorSoluti.pdf
 
What is Vertical versus horizontal integration in healthcare W.pdf
What is Vertical versus horizontal integration in healthcare W.pdfWhat is Vertical versus horizontal integration in healthcare W.pdf
What is Vertical versus horizontal integration in healthcare W.pdf
 
What is the role of the financial system Name and describe two mark.pdf
What is the role of the financial system Name and describe two mark.pdfWhat is the role of the financial system Name and describe two mark.pdf
What is the role of the financial system Name and describe two mark.pdf
 
What is the difference between a paired artery and an unpaired arter.pdf
What is the difference between a paired artery and an unpaired arter.pdfWhat is the difference between a paired artery and an unpaired arter.pdf
What is the difference between a paired artery and an unpaired arter.pdf
 
What has Microsoft improved in Windows Server 2012 when it comes to .pdf
What has Microsoft improved in Windows Server 2012 when it comes to .pdfWhat has Microsoft improved in Windows Server 2012 when it comes to .pdf
What has Microsoft improved in Windows Server 2012 when it comes to .pdf
 
What are the steps for developing Developing a Project Scope Stateme.pdf
What are the steps for developing Developing a Project Scope Stateme.pdfWhat are the steps for developing Developing a Project Scope Stateme.pdf
What are the steps for developing Developing a Project Scope Stateme.pdf
 
True or False Questions1) Good technology transfer between pr.pdf
True or False Questions1) Good technology transfer between pr.pdfTrue or False Questions1) Good technology transfer between pr.pdf
True or False Questions1) Good technology transfer between pr.pdf
 
The symbiosis between plant roots and fungi is characterized byQu.pdf
The symbiosis between plant roots and fungi is characterized byQu.pdfThe symbiosis between plant roots and fungi is characterized byQu.pdf
The symbiosis between plant roots and fungi is characterized byQu.pdf
 

Recently uploaded

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 

C programming Create a system managing a mini library system. Eve.pdf

  • 1. // C programming 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 User. 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 title (read). Ask for author. Generate a book ID by adding one to the current largest book ID. Add the record of the new book into library with generated book ID, title, author, possession="library", checked out date="null" and due date="null". After that, print message "book*** added successfully!" and go to step 5). Provide options "t" for "" and "b" for "Back to main menu". (If "", go to step 1)) Solution #include #include #include //contains delay(),getch()etc. #include #include //contains strcmp(),strcpy(),strlen(),etc #include //contains toupper(), tolower(),etc #include //contains _dos_getdate #include #define RETURNTIME 15 FILE *fp,*ft,*fs; struct l_Date {
  • 2. int mm,dd,yy; }; struct record { int bookid; char title[20]; char Author[20]; char possession[20]; struct l_Date checkedout_date; struct l_Date due_date; }; struct record r; void main() { clrscr(); int i; printf(" a. Add Books "); printf("b. Delete books"); printf("c. Search Books"); printf("d. Issue Books"); printf("e. View Book list"); printf("f. Edit Book's Record"); printf("g. Close Application"); printf("Enter your choice:"); switch(getch()) {
  • 3. case 'a': addbooks(); break; case 'b': deletebooks(); break; case 'c': searchbooks(); break; case 'd': issuebooks(); break; case 'e': viewbooks(); break; case 'f': editbooks(); break; case 'g': { clrscr(); printf("application is closing.. "); exit(0); } default: { printf(" Please re-entered correct option"); } } } void addbooks(void) //funtion to add books {
  • 4. int i; fp=fopen("Bibek.dat","ab+"); fseek(fp,0,SEEK_END); fwrite(&r,sizeof(r),1,fp); fclose(fp); printf("The record is sucessfully saved"); printf("add any more?(t / b):");//t to try again and b to back if(getch()=='b') else addbooks(); } } void deletebooks() //function delete record from file fp { int d; char another='y'; while(another=='y') //infinite loop { printf("Enter the Book ID to delete:"); scanf("%d",&d); fp=fopen("Bibek.dat","rb+"); rewind(fp); while(fread(&r,sizeof(r),1,fp)==1) { if(r.bookid==d) { printf("The book record is available"); printf("Book name is %s",r.title);
  • 5. } } if(findbook!='t') { gotoxy(10,10); printf("No record is found modify the search"); } if(findbook=='t' ) { printf("Do you want to delete it?(Y/N):"); if(getch()=='y') { ft=fopen("test.dat","wb+"); //temporary file for delete rewind(fp); while(fread(&r,sizeof(r),1,fp)==1) { if(r.id!=d) { fseek(ft,0,SEEK_CUR); fwrite(&r,sizeof(r),1,ft); //write all in tempory file except that } //we want to delete } fclose(ft); fclose(fp); remove("Bibek.dat"); rename("test.dat","Bibek.dat"); //copy all item from temporary file to fp except that fp=fopen("Bibek.dat","rb+"); //we want to delete if(findbook=='t') { printf("The record is sucessfully deleted"); printf("Delete another record?(Y/N)"); }
  • 6. } else another=getch(); } } } void searchbooks() { int d; printf("*****************************Search Books*********************************"); printf(" 1. Search By ID"); printf("2. Search By Name"); printf("Enter Your Choice"); fp=fopen("Bibek.dat","rb+"); //open file for reading propose rewind(fp); //move pointer at the begining of file switch(getch()) { case '1': { printf("****Search Books By Id****"); printf("Enter the book id:"); scanf("%d",&d); printf("Searching........"); while(fread(&r,sizeof(r),1,fp)==1) { if(r.id==d)
  • 7. { printf("The Book is available"); printf(" ID:%d",r.bookid); printf(" Name:%s",r.title); printf(" %s ",r.Author); findbook='t'; } } if(findbook!='t') //checks whether conditiion enters inside loop or not { printf("aNo Record Found"); } printf("Try another search?(Y/N)"); if(getch()=='y') searchbooks(); else break; } case '2': { char s[15]; printf("****Search Books By Name****"); printf("Enter Book Name:"); scanf("%s",s);
  • 8. int d=0; while(fread(&r,sizeof(r),1,fp)==1) { if(strcmp(r.title,(s))==0) { printf("The Book is available"); printf(" ID:%d",r.bookid); printf(" Name:%s",r.title);gotoxy(47,10); printf(" Author:%s",r.Author); printf("possession:%s",r.possession); d++; } } if(d==0) {printf("aNo Record Found"); } printf("Try another search?(Y/N)"); if(getch()=='y') searchbooks(); else break; } default : getch(); searchbooks();
  • 9. } fclose(fp); } void editbooks(void) //edit information about book { int c=0; int d,e; printf("****Edit Books Section****"); char another='y'; while(another=='y') { printf("Enter Book Id to be edited:"); scanf("%d",&d); fp=fopen("Bibek.dat","rb+"); while(fread(&r,sizeof(r),1,fp)==1) { if(checkid(d)==0) { printf("The book is availble"); printf("The Book ID:%d",r.bookid); printf("Enter new name:");scanf("%s",r.title); printf("Enter new Author:");scanf("%s",r.Author); printf("The record is modified"); fseek(fp,ftell(fp)-sizeof(r),0); fwrite(&r,sizeof(r),1,fp); fclose(fp); c=1; }
  • 10. if(c==0) { printf("No record found"); } } printf("Modify another Record?(Y/N)"); fflush(stdin); another=getch() ; } returnfunc(); } void returnfunc(void) { { printf(" Press ENTER to return to main menu"); } if(getch()==13) //allow only use of enter mainmenu(); else goto r; } int getdata() { int t; printf("Enter the Information Below"); printf("Category:"); printf("%s",catagories[s-1]); printf("Book ID:t");
  • 11. scanf("%d",&t); if(checkid(t) == 0) { printf("aThe book id already existsa"); getch(); return 0; } r.bookid=t; printf("Book Name:"); scanf("%s",r.title); printf("Author:"); scanf("%s",r.Author); printf("Possession:"); scanf("%d",&r.possession); return 1; } int checkid(int t) //check whether the book is exist in library or not { rewind(fp); while(fread(&r,sizeof(r),1,fp)==1) if(r.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));
  • 12. return 0 ; } void Password(void) { char d[25]="Password Protected"; char ch,pass[10]; int i=0,j; for(j=0;j<20;j++) { delay(50); printf("*"); } for(j=0;j<20;j++) { delay(50); printf("%c",d[j]); } for(j=0;j<20;j++) { delay(50); printf("*"); } gotoxy(10,10); gotoxy(15,7); printf("Enter Password:"); while(ch!=13) { ch=getch(); if(ch!=13 && ch!=8){ putch('*'); pass[i] = ch;
  • 13. i++; } } pass[i] = '0'; if(strcmp(pass,password)==0) { ; printf("Password match"); printf("Press any key to countinue....."); mainmenu(); } else { printf("aWarning!! Incorrect Password"); getch(); Password(); } } void issuerecord() //display issued book's information { printf("The Book has taken by Mr. %s",a.stname); printf("Issued Date:%d-%d-%d",r.issued.dd,r.checkout_date.mm,r.checkout_date.yy); printf("Returning Date:%d-%d-%d",r.due_date.dd,r.due_date.mm,r.due_date.yy); }