SlideShare a Scribd company logo
1 of 35
(C++ programming)
menu:
* quit, book show, book change, book remove, book insert,
member show, member change, member remove, member insert,
borrow, return.
*Store the book and member information to the “book.txt” and
“member.txt” file
* Store the borrow and return information to the “manage.txt”
file
Solution
#include<iostream.h>
#include<string.h>
#include<iomanip.h>
#include<fstream.h>
#include<strstream.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<process.h>
#include<conio.h>
#include<ctype.h>
void create_book(void);
void create_member(void);
void search_book(char [][3],int );
void search_member(char [][3],int);
void book_issue(char [][3],char[][3],int,int,int [],char,char, int
[]);
void book_return(char [][3],char[][3],int,int,int [],char,char, int
[]);
char due_date(void);
char date_format(void);
void
check_due_date(char[],int,char[][3],int,char[][3],char[][5]);
int main ()
{
char pass[20];
top:
clrscr();
for(int star = 0 ; star < 80 ; star++)
cout << "_";
cout << "" << setw(50) << "Welcome to The Library :" <<
setw(29) << "";
for(int star1 = 0 ; star1 < 80 ; star1++)
cout << "_";
cout << endl;
cout << "Please Enter the Password to Gain Access to This
Program :";
cin >> pass;
if(pass == "project")
{
cin.ignore();
char date;
date = date_format(); //Calling function for date
clrscr();
top2:
int choice_section; //Choice of section inside the library
(admin/library)
int choice_database; //Choice of database in the admin
section(seeing lists, adding books etc)
int choice_lib; //Choice of database in the library section
int choice_issue; //Choice for searching or entering code
of the book while issuing it
int count_book[100]; //number of books each user has
issued
int user_issue[100][5]; //member code and the code of the
book that the user has issued
int user_count[100]={0}; //number of books issued by user
int avail_book[100]; //book availibilty(1 when available
and 0 when not available)
for (int i = 0 ; i < 100 ; i++)
{
avail_book[i] = 1;
count_book[i] = 1;
}
char pass[20]; //password for entering in the library
char pass_admin[20]; //password for entering in the admin
section of the library
char book[100][3]; //array for storing a book's code with its
name, author, publisher etc
char member[100][3]; //array for storing a member's code
with his/her name, address etc
char username; //username of member
char date_book[100]; //date on which the book was issued
char date_member[100][5]; //date on which a particular
member issued a book
char due_date[100]; //due date of book (date on which the
book is to be returned)
char due_date_member[100][5]; //date on which a particular
member has to return a book
int access_number = 1; //a unique book code for every book
int membership_number = 1; //a unique member code for
every member
int access_number_enter; //book code entered by the user
while issuing/returning it
int membership_book_issue[100] = {0}; //code of the
member who has issued the book
void read_books();
void read_members();
void book_avail();
void member_status();
//CLEARING SCREEN
clrscr();
//main options
for (int star = 0 ; star < 49 ; star++)
cout<<"_";
cout << endl;
cout << "tTo Access the Admin Section Press 1t tTo
Access The Library Section Press 2 t tTo Quit Program
Press 3 tt" << endl;
for (int star2= 0 ; star2< 49 ; star2++)
cout << "_";
cout<<endl;
cout << "Enter your choice(1, 2 or 3): ";
cin >> choice_section;
cin.ignore();
if (choice_section == 3)
goto end;
if (choice_section == 1)
{
cout << "Enter the Admin Password ";
cin >> pass_admin;
cin.ignore();
if (pass_admin == "admin")
{
clrscr();
for (int star = 0 ; star < 65 ; star++)
cout << "_";
cout << endl;
cout << "" << setw(35) << "Welcome" << setw(29)
<< "" << endl;
cout << "tTo Enter New Books in Database press
1ttt tTo Enter New Members in Member Database Press
2t tTo See The List of All Members press 3ttt tTo See
The List of All Books Press 4ttt tTo Go Back To The
Previous Menu Press 5:tt" << endl;
for (int star3 = 0 ; star3 < 65 ; star3++)
cout << "_";
cout << endl;
cout << "Enter your choice(1-5): ";
cin >> choice_database;
cin.ignore();
clrscr();
if (choice_database == 1)
{
create_book(); //CALLING FUNCTION CREATE
BOOK
}
else if (choice_database == 2)
{
create_member(); //CALLING FUNCTION CREATE
MEMBER
}
else if (choice_database == 3)
{
cout << "member_name" << "ttt" <<
"member_address" << "ttt" << "UserName" << "t"
<< endl;
for(int i = 0 ; i < membership_number; i++)
{
//here i represents respective member code
cout << member[i][0] << "ttt" <<
member[i][1] << "ttt" << member[i][2] << "t" << endl;
if (i == 15)
system("pause");
}
system ("pause" );
}
else if (choice_database == 4)
{
cout << "book_name" << "tt" << " Author_1_Name"
<< "t" << "Author_2_Name" << "tt" << "code" <<
endl;
for(int i = 1 ; i < access_number ; i++)
{
//here i represents book code
cout << book[i][0] << "tt" << book[i][1] <<
"tt" << book[i][2] << "tt" << i << "t" << endl;
//program will display 10 books and then wait for
user to press any key before it continues
if(i == 10)
system ("pause");
}
system ("pause");
}
else if (choice_database == 5)
goto top2;
else
{
cout << "Wrong Choice "<< endl;
clrscr();
goto top2;
}
}
else
{
cout<<"Wrong Password Entered ";
system ("pause");
clrscr();
goto top2;
}
}
else if(choice_section == 2)
{
clrscr();
for (int star = 0 ; star < 57 ; star++)
cout << "_";
cout << endl;
cout << "tTo Search For a Books Code Press 1tt tTo
Search For A Member Press 2ttt tTo Issue A Book Press
3tttt tTo Return a Book Press 4ttt tTo Check
Status Of A member Press 5tt tTo Check Staus Of A Book
Press 6tt tTo Check If Any Book Is Due Today Press 7t
tTo Go Back To The Previous Menue Press 8t"<<endl;
for (int star4 = 0 ; star4 < 57 ; star4++)
cout << "_";
cout << endl;
cout << "Enter your choice (1-8): ";
cin >> choice_lib;
cin.ignore();
clrscr();
if (choice_lib == 1 || choice_lib == 2 || choice_lib == 3 ||
choice_lib == 4 || choice_lib == 5 || choice_lib == 6 ||
choice_lib == 7 || choice_lib ==8) {
if (choice_lib == 8)
goto top2;
if (choice_lib == 1)
{
search_book (book,access_number); //CALIING
SEARCH BOOK FUNCTION
goto top2;
}
if (choice_lib == 2)
{
search_member (member,membership_number);
//CALIING SEARCH MEMBER FUNCTION
goto top2;
}
if (choice_lib == 3)
{
cout << "If You know the Code of the Book Press 1 to
enter it If You Want to Search for the book first press 2" <<
endl;
cout << "Enter your choice (1-2): ";
cin >> choice_issue;
cin.ignore();
if (choice_issue == 2)
{
search_book (book,access_number);
}
cout << "Enter The Username of The Member Who
Wants to Issue the Book :";
get(username);
cout << "Enter the Book Code :";
cin >> access_number_enter;
cin.ignore();
// if the code entered by the user is more than the total
number of book codes in memory give an error
if (access_number_enter > access_number-1)
{
cout << " Wrong Book Code Entered" << endl;
}
else
book_issue (book,member, access_number_enter,
membership_number, count_book, date, username, avail_book);
system ("pause");
goto top2;
}
if(choice_lib == 4)
{
cout << "If You Want to Enter The Code of the Book
Press 1 If You Want to Search for the book First press 2" <<
endl;
cin >> choice_issue;
cin.ignore();
if (choice_issue == 2)
{
search_book (book, access_number);
}
cout << "Enter The Username of The Member Who
Wants to Return the Book :";
get(username);
cout << "Enter the Book Code :";
cin >> access_number_enter;
cin.ignore();
if (access_number_enter > access_number-1)
{
cout << " Wrong Book Code Entered" << endl;
}
else
book_return (book, member, access_number_enter,
membership_number, count_book, date, username, avail_book);
system ("pause");
clrscr();
goto top2;
}
if (choice_lib == 5)
{
int user_code_found, choice_member;
cout << "To Enter username Of The Member You Want
to Check Status Of Press 1 To Search For The Member
Press2:"<< endl;
cin >> choice_member;
cin.ignore();
if(choice_member== 2)
{
search_member(member, membership_number);
goto member;
}
if(choice_member== 1)
{
member:
cout << "Enter The username :";
get(username);
int check = 0;for (user_code_found = 1 ;
user_code_found < membership_number ; user_code_found++)
{
if (member[user_code_found][2] == username)
{
check = 1;
break;
}
else
check = 0;
}
if (check == 0)
{
cout << " Wrong username " << endl;
}
else
{
int i;
if (user_count[user_code_found] > 1)
{
cout << member[user_code_found][0] << endl;
cout << "Book Name" << setw(25) << "Date Issued "
<< setw(25) << "Due Date" << endl;
for (i = 1 ; i <= user_count[user_code_found]-1 ; i++)
{
cout << book[user_issue[user_code_found][i]][0] << setw(20)
<< date_member[user_code_found][i] << setw(20) <<
due_date_member[user_code_found][i] << endl;
}
system("pause");
goto top2;
}
else
{
cout << " No Books Have Been Issued by " <<
member[user_code_found][0] << endl;
system("pause");
goto top2;
}
}
}
else
{
cout << "Wrong Choice Entered" << endl;
system ("pause");
clrscr();
goto top2;
}
}
if (choice_lib == 6)
{
int choice_book_status;
cout << "If You Want To Enter The Code of The Book
Press 1 If You Want To Search For The Book Press 2" <<
endl;
cin >> choice_book_status;
cin.ignore();
if (choice_book_status == 2)
{
search_book (book, access_number);
}
else if(choice_book_status == 1)
{
cout << "Enter The Code of The Book :";
cin >> access_number_enter;
//checking if the book code is valid
if(access_number_enter > access_number-1)
cout << "Wrong access_number entered ";
else
{
// 1 represents that book is available
if (avail_book[access_number_enter] == 1)
{
// printing the name of the book (stored in
subscript [0])
cout << book[access_number_enter][0] << " is
available" << endl;
}
//0 represents that book is not available
else if (avail_book[access_number_enter] == 0)
{
//printing the name of the book and to whome it
has been issued to and when
cout << book[access_number_enter][0] << "
Has Been Issued to " << member
[membership_book_issue[access_number_enter]][0] << " On "
<< date_book[access_number_enter] << " Till The Due Date :"
<< due_date[access_number_enter] << endl;
}
}
}
system ("pause");
clrscr();
goto top2;
}
if (choice_lib == 7)
{
check_due_date (due_date, access_number, book,
membership_number, member, due_date_member);
system("pause");
goto top2;
}
}
else
{
cout << "Wrong Choice Entered " << endl;
system ("pause");
clrscr();
goto top2;
}
}
else
{
cout << "Wrong Choice Entered :";
system ("pause");
clrscr();
goto top2;
}
}
else
{
cout << "Wrong Password Entered" << endl << endl <<
endl; system("pause");
clrscr();
goto top;
}
end:
system ("pause");
return 0;
//end of main program
}
void create_book(void)
{
char book_name, author_1_name, author_2_name;
char choice;
ofstream OutBook;
//opening the book txt file
OutBook.open ("books.txt", ios::app);
do
{
//inputing the info about the book
cout << "Enter Book Name :";
getline (cin, book_name);
cout << "Enter first Aurthors Name :";
getline (cin, author_1_name);
cout << "Enter second authors name :";
getline (cin, author_2_name);
//storing it in the file
OutBook << book_name << "#" << author_1_name << "$"
<< author_2_name<< endl;
cout << "If You Want to Enter Another Book press Y else
Press N :";
cin >> choice;
cin.ignore();
choice = tolower(choice);
//creating a seperate txt file for the book to store its data in
ostrstream os;
os << book_name << ".txt";
ofstream OutBookAvail( os.str().c_str() );
OutBookAvail << 1 << "$" << 0 << "&" << "1/1/2010"
<< "*"<< "2/1/2010" << endl;
OutBookAvail.close();
} while (choice == 'y');
OutBook.close();
}
void create_member(void)
{
char choice;
char member_name, address, user_name;
ofstream OutMember;
//opening member txt file
OutMember.open ("member.txt",ios::app);
do
{
cout << "Enter members Name :";
getline (cin, member_name);
cout << "Enter members address :";
getline (cin, address);
cout << "Enter The Username :";
getline (cin, user_name);
//storing necessary data in it
OutMember << member_name << "#" << address <<
"$" << user_name << endl;
cout << "Enter Y if You want to Enter Data of Another
member else Press N :";
cin >> choice;
cin.ignore();
//creating a seperate txt file for the member
ostrstream ss;
ss << member_name << ".txt";
ofstream OutMemberAvail ( ss.str().c_str(),ios::app );
OutMemberAvail << 0 << "$" << "1/1/2010" << '*' <<
"2/2/2010" << endl;
OutMemberAvail.close();
} while (choice == 'y');
}
void search_book(char book[][3], int access_number)
{
clrscr();
int i, j, length1, length2, match = 0;
char book_search, book_new;
cout << "Enter The Name of The Book You Want to Search
:";
getline (cin, book_search);
cout << " Following Are The Books That Matched Your
Given Book Name" << endl;
cout << "book name" << "tt" << " author 1 name" <<
"t" << "author 2 name" << "tt" << "code" << endl;
for ( i = 1 ; i <= access_number ; i++)
{
length2 = book_search.length();
length1 = book[i][0].length();
match = 0;
// runs till the length of the book name entered for
searching
for (j = 0 ; j < length2-1 ; j++)
{
// runs till the length of book name in database
for (int k = 0 ; k < length1-1 ; k++)
{
//lowering all charecters for easy access
book[i][0][k] = tolower(book[i][0][k]);
book_search[j] = tolower(book_search[j]);
// if they are equal then counter match increases by 1
if (book[i][0][k] == book_search[j])
{
match++;
break;
}
}
}
//if match is greater than 1 less then the length of the name
given by user .
if (match >= length2-1)
{
//printing the book name author and code .. here i
represents the book code
cout << book[i][0] << "tt" << book[i][1] <<
"tt" << book[i][2] << "tt" << i << "t" << endl;
}
}
system ("pause");
}
void search_member(char member[][3],int
membership_number)
{
// searching member by same criteria as well
clrscr();
int i, j, length1, length2, match = 0;
char member_search, member_new;
cout << "Enter The Name of The Member You Want to
Search :";
getline (cin, member_search);
cout << " Following Are The Members That Matched Your
Given Book Name" << endl;
cout << "member name" << "ttt" << "address" <<
"ttt" << "UserName" << "t" << endl;
for (i = 1 ; i <= membership_number-1 ; i++)
{
length2 = member_search.length();
length1 = member[i][0].length();
match = 0;
//runs till length of the name entered for search
for (j = 0 ; j < length2-1 ; j++)
{
// runs till length of the name in database
for (int k = 0 ; k < length1-1 ; k++)
{
member[i][0][k] = tolower(member[i][0][k]);
member_search[j] = tolower(member_search[j]);
if (member[i][0][k] == member_search[j])
{
match++;
break;
}
}
}
if (match >= length2-1)
{
cout << member[i][0] << "ttt" << member[i][1]
<< "ttt" << member[i][2] << "t" << endl;
}
}
system ("pause");
clrscr();
}
void book_issue(char book [][3], char member[][3], int
access_number, int membership_number, int count_book[], char
date, char username, int avail_book[])
{
int check = 0;
// 0 represents that book isn't available. checking if it is or
not
if (avail_book[access_number] == 0)
{
cout << "Book Is Not Available " << endl;
}
else
{
int i;
for (i = 1 ; i < membership_number ; i++)
{
// searching for the user whose username has been entered
if (member[i][2] == username)
{
check = 1;
break;
}
else
check = 0;
}
if (check == 0)
{
cout << " Wrong User Name " << endl;
}
else
{
// here i represents member code . if that member has
already issued 4 books i.e his counter is more than 4 it gives an
error
if (count_book[i] > 4)
cout << " You Have Issued 4 Books Already, Please
Return a Book to get More Books Issued" << endl;
else
{
// setting the availbility status of that book to 0 (0
represents its not available)
avail_book[access_number] = 0;
//using due date function to store the due date
char date_due = due_date();
//displaying book name and who has issued it and other info
cout << book[access_number][0] << " By " <<
book[access_number][1] << " Has Been Issued to " <<
member[i][0] << " on " << date << " Till The Due Date :" <<
date_due << endl;
//increasing the count of the student by 1
count_book[i]++;
//opening the txt file of the respective book
ostrstream os;
os << book[access_number][0] << ".txt";
ofstream OutBookAvail ( os.str().c_str() );
OutBookAvail << avail_book[access_number] << "$" << i <<
"&" << date << "*" << date_due << endl;
OutBookAvail.close();
ostringstream ss;
ss << member[i][0] << ".txt";
ofstream OutMemberAvail ( ss.str().c_str(),ios::app );
OutMemberAvail << access_number << "$" << date << "*"
<< date_due << endl;
OutMemberAvail.close();
}
}
}
}
void book_return(char book [][3], char student[][3], int
access_number, int membership_number, int count_book[], char
date, char username, int avail_book[])
{
int check = 0;
// if the status of book is 1 it means it hasent been issued
yet
if (avail_book[access_number] == 1)
{
cout << "The Book Hasent Been Issued yet" << endl;
}
else
{
int i;
int check = 0;
//searching for the member with the given username
for (i = 1 ; i < membership_number ; i++)
{
if (member[i][2] == username)
{
check = 1;
break;
}
else
check = 0;
}
if (check == 0)
{
cout << " Wrong User Name " << endl;
}
else
{
// opening the book file and storing the data in it
temporary
int temp_user, temp_avail;
char temp_Date, temp_Due_Date;
ostringstream os;
os << book[access_number][0] << ".txt";
ifstream BAvail( os.str().c_str() );
while (!BAvail.eof())
{
BAvail >> temp_avail;
BAvail.ignore();
// code of the user who has issued the book
BAvail >> temp_user;
BAvail.ignore();
getline (BAvail, temp_Date,'*');
getline(BAvail, temp_Due_Date);
}
// if the username of the user wanting tor return the book
matches with the user whose code is stored in the book's txt
file then program continues
if (temp_user == i)
{
count_book[i]--;
avail_book[access_number] = 1;
cout << book[access_number][0] << " by " <<
book[access_number][1] << " Issued on : " << temp_Date <<
" has been returned by " << member[i][0] << " on " << date
<< endl;
//opening the text file of the book;
ostringstream os;
os << book[access_number][0] << ".txt";
ofstream OutBookAvail( os.str().c_str() );
//setting the values back to default as they were when we
created the new text file
OutBookAvail << 1 << "$" << 0 << "&" << "1/1/2010"
<< "*" << "2/1/2010" << endl;
OutBookAvail.close();
int temp_code, temp_count;
char temp_date;
//opening the members txt file.
ostringstream ss;
ss << member[i][0] << ".txt";
ifstream mAvail( ss.str().c_str(),ios::app );
// reading the data
// storing book code
mAvail >> temp_code;
mAvail.ignore();
//temp date
getline (mAvail, temp_date);
while (!mAvail.eof())
{
// if the code of the book is equal to the code of the book
returned then its not copied hence removing the code of the
book that has been returned
if (temp_code == access_number)
{
}
else
{
// storing data of other books in a new temp txt file
ostringstream ss;
ss << member[i][0] << "_temp.txt";
ofstream OutMemberAvail( ss.str().c_str(),ios::app);
OutMemberAvail << temp_code << "$" << temp_date <<
endl;
OutMemberAvail.close();
}
mAvail >> temp_code;
mAvail.ignore();
getline (mAvail, temp_date);
}
mAvail.close();
ostringstream ds;
//removing the text file of the student
ds << member[i][0] << ".txt";
remove ( ds.str().c_str());
ostringstream es;
es << member[i][0] << "_temp.txt";
ostringstream ps;
ps << member[i][0] << ".txt";
//renaming the temporary file to the original . in this way we
have modified the txt file of the member removing data of the
book returned and it only contain data of books that are still
issed to him (if any)
rename ( es.str().c_str(),ps.str().c_str());
}
// if the username given does not match with the username of
member stored in the books txt file while issuing than it gives
an error
else
cout << " The Book Has Not Been Issued By This User :"
<< endl;
}
}
}
char due_date(void)
{
char due_date;
int date = 0, month = 0 , year = 0;
//calling date from computer
char date_cal[9];
_strdate (date_cal);
ofstream OutFile;
OutFile.open("date.txt");
//storing it into date.txt
OutFile << date_cal;
OutFile.close();
ifstream InFile;
//reading date.txt and storing days months and year seperatly
in different int
InFile.open ("date.txt");
InFile >> month;
//to ignore /
InFile.ignore();
InFile >> date;
// to ignore /
InFile.ignore();
InFile >> year;
// calculating for feburary
if (month == 2)
{
//checking if leap year
if (year%400 == 0 || (year%100 != 0 && year%4 == 0))
{
//making necesarry calculations
if (date <= 8)
date = date+21;
else if(date > 8)
{
date = (date+21) - 29;
month = month++;
}
}
else if (date <= 7)
date = date+21;
else if (date > 7)
{
date = (date+21) - 28;
month = month++;
if (month > 12)
{
//resetting month to 1 and increasing year month is
greater than 12
month = 1;
year++;
}
}
}
/

More Related Content

Similar to (C++ programming)menu quit, book show, book change, book remo.docx

#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
 
assign4assign4_part1bonnie.c This is a file system ben.docx
assign4assign4_part1bonnie.c  This is a file system ben.docxassign4assign4_part1bonnie.c  This is a file system ben.docx
assign4assign4_part1bonnie.c This is a file system ben.docx
festockton
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6
fisher.w.y
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
Siva Arunachalam
 
Open Selector
Open SelectorOpen Selector
Open Selector
jjdelc
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
calderoncasto9163
 
#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf
inbox5
 

Similar to (C++ programming)menu quit, book show, book change, book remo.docx (20)

Computer Science investigatory project class 12
Computer Science investigatory project class 12Computer Science investigatory project class 12
Computer Science investigatory project class 12
 
Notes for SQLite3 Usage
Notes for SQLite3 UsageNotes for SQLite3 Usage
Notes for SQLite3 Usage
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
 
Entity Framework Core: tips and tricks
Entity Framework Core: tips and tricksEntity Framework Core: tips and tricks
Entity Framework Core: tips and tricks
 
Delete statement in PHP
Delete statement in PHPDelete statement in PHP
Delete statement in PHP
 
#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
 
c programming
c programmingc programming
c programming
 
Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6Rootkit on linux_x86_v2.6
Rootkit on linux_x86_v2.6
 
Coding - L30-L31-Array of structures.pptx
Coding - L30-L31-Array of structures.pptxCoding - L30-L31-Array of structures.pptx
Coding - L30-L31-Array of structures.pptx
 
assign4assign4_part1bonnie.c This is a file system ben.docx
assign4assign4_part1bonnie.c  This is a file system ben.docxassign4assign4_part1bonnie.c  This is a file system ben.docx
assign4assign4_part1bonnie.c This is a file system ben.docx
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding Horrors
 
A Skeptics guide to functional style javascript
A Skeptics guide to functional style javascriptA Skeptics guide to functional style javascript
A Skeptics guide to functional style javascript
 
Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6Rootkit on Linux X86 v2.6
Rootkit on Linux X86 v2.6
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 
23. CodeIgniter sessions
23. CodeIgniter sessions23. CodeIgniter sessions
23. CodeIgniter sessions
 
Open Selector
Open SelectorOpen Selector
Open Selector
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdfAbstract Base Class (C++ Program)Create an abstract base class cal.pdf
Abstract Base Class (C++ Program)Create an abstract base class cal.pdf
 
#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf
 

More from ajoy21

Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
ajoy21
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
ajoy21
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
ajoy21
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
ajoy21
 

More from ajoy21 (20)

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docx
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docx
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docx
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docx
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docx
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docx
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docx
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docx
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docx
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docx
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docx
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docx
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docx
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
Krashi Coaching
 

Recently uploaded (20)

Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Benefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxBenefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
Chapter 7 Pharmacosy Traditional System of Medicine & Ayurvedic Preparations ...
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 

(C++ programming)menu quit, book show, book change, book remo.docx

  • 1. (C++ programming) menu: * quit, book show, book change, book remove, book insert, member show, member change, member remove, member insert, borrow, return. *Store the book and member information to the “book.txt” and “member.txt” file * Store the borrow and return information to the “manage.txt” file Solution #include<iostream.h> #include<string.h> #include<iomanip.h> #include<fstream.h> #include<strstream.h> #include<time.h> #include<stdio.h> #include<stdlib.h> #include<process.h> #include<conio.h> #include<ctype.h>
  • 2. void create_book(void); void create_member(void); void search_book(char [][3],int ); void search_member(char [][3],int); void book_issue(char [][3],char[][3],int,int,int [],char,char, int []); void book_return(char [][3],char[][3],int,int,int [],char,char, int []); char due_date(void); char date_format(void); void check_due_date(char[],int,char[][3],int,char[][3],char[][5]); int main () { char pass[20]; top: clrscr(); for(int star = 0 ; star < 80 ; star++) cout << "_"; cout << "" << setw(50) << "Welcome to The Library :" << setw(29) << ""; for(int star1 = 0 ; star1 < 80 ; star1++) cout << "_"; cout << endl; cout << "Please Enter the Password to Gain Access to This
  • 3. Program :"; cin >> pass; if(pass == "project") { cin.ignore(); char date; date = date_format(); //Calling function for date clrscr(); top2: int choice_section; //Choice of section inside the library (admin/library) int choice_database; //Choice of database in the admin section(seeing lists, adding books etc) int choice_lib; //Choice of database in the library section int choice_issue; //Choice for searching or entering code of the book while issuing it int count_book[100]; //number of books each user has issued int user_issue[100][5]; //member code and the code of the book that the user has issued int user_count[100]={0}; //number of books issued by user int avail_book[100]; //book availibilty(1 when available and 0 when not available) for (int i = 0 ; i < 100 ; i++) {
  • 4. avail_book[i] = 1; count_book[i] = 1; } char pass[20]; //password for entering in the library char pass_admin[20]; //password for entering in the admin section of the library char book[100][3]; //array for storing a book's code with its name, author, publisher etc char member[100][3]; //array for storing a member's code with his/her name, address etc char username; //username of member char date_book[100]; //date on which the book was issued char date_member[100][5]; //date on which a particular member issued a book char due_date[100]; //due date of book (date on which the book is to be returned) char due_date_member[100][5]; //date on which a particular member has to return a book int access_number = 1; //a unique book code for every book int membership_number = 1; //a unique member code for every member int access_number_enter; //book code entered by the user while issuing/returning it int membership_book_issue[100] = {0}; //code of the member who has issued the book
  • 5. void read_books(); void read_members(); void book_avail(); void member_status(); //CLEARING SCREEN clrscr(); //main options for (int star = 0 ; star < 49 ; star++) cout<<"_"; cout << endl; cout << "tTo Access the Admin Section Press 1t tTo Access The Library Section Press 2 t tTo Quit Program Press 3 tt" << endl; for (int star2= 0 ; star2< 49 ; star2++) cout << "_"; cout<<endl; cout << "Enter your choice(1, 2 or 3): "; cin >> choice_section; cin.ignore(); if (choice_section == 3) goto end; if (choice_section == 1) { cout << "Enter the Admin Password "; cin >> pass_admin;
  • 6. cin.ignore(); if (pass_admin == "admin") { clrscr(); for (int star = 0 ; star < 65 ; star++) cout << "_"; cout << endl; cout << "" << setw(35) << "Welcome" << setw(29) << "" << endl; cout << "tTo Enter New Books in Database press 1ttt tTo Enter New Members in Member Database Press 2t tTo See The List of All Members press 3ttt tTo See The List of All Books Press 4ttt tTo Go Back To The Previous Menu Press 5:tt" << endl; for (int star3 = 0 ; star3 < 65 ; star3++) cout << "_"; cout << endl; cout << "Enter your choice(1-5): "; cin >> choice_database; cin.ignore(); clrscr(); if (choice_database == 1) { create_book(); //CALLING FUNCTION CREATE BOOK
  • 7. } else if (choice_database == 2) { create_member(); //CALLING FUNCTION CREATE MEMBER } else if (choice_database == 3) { cout << "member_name" << "ttt" << "member_address" << "ttt" << "UserName" << "t" << endl; for(int i = 0 ; i < membership_number; i++) { //here i represents respective member code cout << member[i][0] << "ttt" << member[i][1] << "ttt" << member[i][2] << "t" << endl; if (i == 15) system("pause"); } system ("pause" ); } else if (choice_database == 4) { cout << "book_name" << "tt" << " Author_1_Name" << "t" << "Author_2_Name" << "tt" << "code" <<
  • 8. endl; for(int i = 1 ; i < access_number ; i++) { //here i represents book code cout << book[i][0] << "tt" << book[i][1] << "tt" << book[i][2] << "tt" << i << "t" << endl; //program will display 10 books and then wait for user to press any key before it continues if(i == 10) system ("pause"); } system ("pause"); } else if (choice_database == 5) goto top2; else { cout << "Wrong Choice "<< endl; clrscr(); goto top2; } } else { cout<<"Wrong Password Entered ";
  • 9. system ("pause"); clrscr(); goto top2; } } else if(choice_section == 2) { clrscr(); for (int star = 0 ; star < 57 ; star++) cout << "_"; cout << endl; cout << "tTo Search For a Books Code Press 1tt tTo Search For A Member Press 2ttt tTo Issue A Book Press 3tttt tTo Return a Book Press 4ttt tTo Check Status Of A member Press 5tt tTo Check Staus Of A Book Press 6tt tTo Check If Any Book Is Due Today Press 7t tTo Go Back To The Previous Menue Press 8t"<<endl; for (int star4 = 0 ; star4 < 57 ; star4++) cout << "_"; cout << endl; cout << "Enter your choice (1-8): "; cin >> choice_lib; cin.ignore(); clrscr(); if (choice_lib == 1 || choice_lib == 2 || choice_lib == 3 ||
  • 10. choice_lib == 4 || choice_lib == 5 || choice_lib == 6 || choice_lib == 7 || choice_lib ==8) { if (choice_lib == 8) goto top2; if (choice_lib == 1) { search_book (book,access_number); //CALIING SEARCH BOOK FUNCTION goto top2; } if (choice_lib == 2) { search_member (member,membership_number); //CALIING SEARCH MEMBER FUNCTION goto top2; } if (choice_lib == 3) { cout << "If You know the Code of the Book Press 1 to enter it If You Want to Search for the book first press 2" << endl; cout << "Enter your choice (1-2): "; cin >> choice_issue; cin.ignore(); if (choice_issue == 2)
  • 11. { search_book (book,access_number); } cout << "Enter The Username of The Member Who Wants to Issue the Book :"; get(username); cout << "Enter the Book Code :"; cin >> access_number_enter; cin.ignore(); // if the code entered by the user is more than the total number of book codes in memory give an error if (access_number_enter > access_number-1) { cout << " Wrong Book Code Entered" << endl; } else book_issue (book,member, access_number_enter, membership_number, count_book, date, username, avail_book); system ("pause"); goto top2; } if(choice_lib == 4) { cout << "If You Want to Enter The Code of the Book Press 1 If You Want to Search for the book First press 2" <<
  • 12. endl; cin >> choice_issue; cin.ignore(); if (choice_issue == 2) { search_book (book, access_number); } cout << "Enter The Username of The Member Who Wants to Return the Book :"; get(username); cout << "Enter the Book Code :"; cin >> access_number_enter; cin.ignore(); if (access_number_enter > access_number-1) { cout << " Wrong Book Code Entered" << endl; } else book_return (book, member, access_number_enter, membership_number, count_book, date, username, avail_book); system ("pause"); clrscr(); goto top2; } if (choice_lib == 5)
  • 13. { int user_code_found, choice_member; cout << "To Enter username Of The Member You Want to Check Status Of Press 1 To Search For The Member Press2:"<< endl; cin >> choice_member; cin.ignore(); if(choice_member== 2) { search_member(member, membership_number); goto member; } if(choice_member== 1) { member: cout << "Enter The username :"; get(username); int check = 0;for (user_code_found = 1 ; user_code_found < membership_number ; user_code_found++) { if (member[user_code_found][2] == username) { check = 1; break; }
  • 14. else check = 0; } if (check == 0) { cout << " Wrong username " << endl; } else { int i; if (user_count[user_code_found] > 1) { cout << member[user_code_found][0] << endl; cout << "Book Name" << setw(25) << "Date Issued " << setw(25) << "Due Date" << endl; for (i = 1 ; i <= user_count[user_code_found]-1 ; i++) { cout << book[user_issue[user_code_found][i]][0] << setw(20) << date_member[user_code_found][i] << setw(20) << due_date_member[user_code_found][i] << endl; } system("pause"); goto top2; } else
  • 15. { cout << " No Books Have Been Issued by " << member[user_code_found][0] << endl; system("pause"); goto top2; } } } else { cout << "Wrong Choice Entered" << endl; system ("pause"); clrscr(); goto top2; } } if (choice_lib == 6) { int choice_book_status; cout << "If You Want To Enter The Code of The Book Press 1 If You Want To Search For The Book Press 2" << endl; cin >> choice_book_status; cin.ignore();
  • 16. if (choice_book_status == 2) { search_book (book, access_number); } else if(choice_book_status == 1) { cout << "Enter The Code of The Book :"; cin >> access_number_enter; //checking if the book code is valid if(access_number_enter > access_number-1) cout << "Wrong access_number entered "; else { // 1 represents that book is available if (avail_book[access_number_enter] == 1) { // printing the name of the book (stored in subscript [0]) cout << book[access_number_enter][0] << " is available" << endl; } //0 represents that book is not available else if (avail_book[access_number_enter] == 0) { //printing the name of the book and to whome it
  • 17. has been issued to and when cout << book[access_number_enter][0] << " Has Been Issued to " << member [membership_book_issue[access_number_enter]][0] << " On " << date_book[access_number_enter] << " Till The Due Date :" << due_date[access_number_enter] << endl; } } } system ("pause"); clrscr(); goto top2; } if (choice_lib == 7) { check_due_date (due_date, access_number, book, membership_number, member, due_date_member); system("pause"); goto top2; } } else { cout << "Wrong Choice Entered " << endl; system ("pause");
  • 18. clrscr(); goto top2; } } else { cout << "Wrong Choice Entered :"; system ("pause"); clrscr(); goto top2; } } else { cout << "Wrong Password Entered" << endl << endl << endl; system("pause"); clrscr(); goto top; } end: system ("pause"); return 0; //end of main program } void create_book(void)
  • 19. { char book_name, author_1_name, author_2_name; char choice; ofstream OutBook; //opening the book txt file OutBook.open ("books.txt", ios::app); do { //inputing the info about the book cout << "Enter Book Name :"; getline (cin, book_name); cout << "Enter first Aurthors Name :"; getline (cin, author_1_name); cout << "Enter second authors name :"; getline (cin, author_2_name); //storing it in the file OutBook << book_name << "#" << author_1_name << "$" << author_2_name<< endl; cout << "If You Want to Enter Another Book press Y else Press N :"; cin >> choice; cin.ignore(); choice = tolower(choice); //creating a seperate txt file for the book to store its data in ostrstream os;
  • 20. os << book_name << ".txt"; ofstream OutBookAvail( os.str().c_str() ); OutBookAvail << 1 << "$" << 0 << "&" << "1/1/2010" << "*"<< "2/1/2010" << endl; OutBookAvail.close(); } while (choice == 'y'); OutBook.close(); } void create_member(void) { char choice; char member_name, address, user_name; ofstream OutMember; //opening member txt file OutMember.open ("member.txt",ios::app); do { cout << "Enter members Name :"; getline (cin, member_name); cout << "Enter members address :"; getline (cin, address); cout << "Enter The Username :"; getline (cin, user_name); //storing necessary data in it
  • 21. OutMember << member_name << "#" << address << "$" << user_name << endl; cout << "Enter Y if You want to Enter Data of Another member else Press N :"; cin >> choice; cin.ignore(); //creating a seperate txt file for the member ostrstream ss; ss << member_name << ".txt"; ofstream OutMemberAvail ( ss.str().c_str(),ios::app ); OutMemberAvail << 0 << "$" << "1/1/2010" << '*' << "2/2/2010" << endl; OutMemberAvail.close(); } while (choice == 'y'); } void search_book(char book[][3], int access_number) { clrscr(); int i, j, length1, length2, match = 0; char book_search, book_new; cout << "Enter The Name of The Book You Want to Search :"; getline (cin, book_search); cout << " Following Are The Books That Matched Your
  • 22. Given Book Name" << endl; cout << "book name" << "tt" << " author 1 name" << "t" << "author 2 name" << "tt" << "code" << endl; for ( i = 1 ; i <= access_number ; i++) { length2 = book_search.length(); length1 = book[i][0].length(); match = 0; // runs till the length of the book name entered for searching for (j = 0 ; j < length2-1 ; j++) { // runs till the length of book name in database for (int k = 0 ; k < length1-1 ; k++) { //lowering all charecters for easy access book[i][0][k] = tolower(book[i][0][k]); book_search[j] = tolower(book_search[j]); // if they are equal then counter match increases by 1 if (book[i][0][k] == book_search[j]) { match++; break; } }
  • 23. } //if match is greater than 1 less then the length of the name given by user . if (match >= length2-1) { //printing the book name author and code .. here i represents the book code cout << book[i][0] << "tt" << book[i][1] << "tt" << book[i][2] << "tt" << i << "t" << endl; } } system ("pause"); } void search_member(char member[][3],int membership_number) { // searching member by same criteria as well clrscr(); int i, j, length1, length2, match = 0; char member_search, member_new; cout << "Enter The Name of The Member You Want to Search :"; getline (cin, member_search); cout << " Following Are The Members That Matched Your
  • 24. Given Book Name" << endl; cout << "member name" << "ttt" << "address" << "ttt" << "UserName" << "t" << endl; for (i = 1 ; i <= membership_number-1 ; i++) { length2 = member_search.length(); length1 = member[i][0].length(); match = 0; //runs till length of the name entered for search for (j = 0 ; j < length2-1 ; j++) { // runs till length of the name in database for (int k = 0 ; k < length1-1 ; k++) { member[i][0][k] = tolower(member[i][0][k]); member_search[j] = tolower(member_search[j]); if (member[i][0][k] == member_search[j]) { match++; break; } } } if (match >= length2-1) {
  • 25. cout << member[i][0] << "ttt" << member[i][1] << "ttt" << member[i][2] << "t" << endl; } } system ("pause"); clrscr(); } void book_issue(char book [][3], char member[][3], int access_number, int membership_number, int count_book[], char date, char username, int avail_book[]) { int check = 0; // 0 represents that book isn't available. checking if it is or not if (avail_book[access_number] == 0) { cout << "Book Is Not Available " << endl; } else { int i; for (i = 1 ; i < membership_number ; i++) { // searching for the user whose username has been entered
  • 26. if (member[i][2] == username) { check = 1; break; } else check = 0; } if (check == 0) { cout << " Wrong User Name " << endl; } else { // here i represents member code . if that member has already issued 4 books i.e his counter is more than 4 it gives an error if (count_book[i] > 4) cout << " You Have Issued 4 Books Already, Please Return a Book to get More Books Issued" << endl; else { // setting the availbility status of that book to 0 (0 represents its not available) avail_book[access_number] = 0;
  • 27. //using due date function to store the due date char date_due = due_date(); //displaying book name and who has issued it and other info cout << book[access_number][0] << " By " << book[access_number][1] << " Has Been Issued to " << member[i][0] << " on " << date << " Till The Due Date :" << date_due << endl; //increasing the count of the student by 1 count_book[i]++; //opening the txt file of the respective book ostrstream os; os << book[access_number][0] << ".txt"; ofstream OutBookAvail ( os.str().c_str() ); OutBookAvail << avail_book[access_number] << "$" << i << "&" << date << "*" << date_due << endl; OutBookAvail.close(); ostringstream ss; ss << member[i][0] << ".txt"; ofstream OutMemberAvail ( ss.str().c_str(),ios::app ); OutMemberAvail << access_number << "$" << date << "*" << date_due << endl; OutMemberAvail.close(); } } }
  • 28. } void book_return(char book [][3], char student[][3], int access_number, int membership_number, int count_book[], char date, char username, int avail_book[]) { int check = 0; // if the status of book is 1 it means it hasent been issued yet if (avail_book[access_number] == 1) { cout << "The Book Hasent Been Issued yet" << endl; } else { int i; int check = 0; //searching for the member with the given username for (i = 1 ; i < membership_number ; i++) { if (member[i][2] == username) { check = 1; break; }
  • 29. else check = 0; } if (check == 0) { cout << " Wrong User Name " << endl; } else { // opening the book file and storing the data in it temporary int temp_user, temp_avail; char temp_Date, temp_Due_Date; ostringstream os; os << book[access_number][0] << ".txt"; ifstream BAvail( os.str().c_str() ); while (!BAvail.eof()) { BAvail >> temp_avail; BAvail.ignore(); // code of the user who has issued the book BAvail >> temp_user; BAvail.ignore(); getline (BAvail, temp_Date,'*'); getline(BAvail, temp_Due_Date);
  • 30. } // if the username of the user wanting tor return the book matches with the user whose code is stored in the book's txt file then program continues if (temp_user == i) { count_book[i]--; avail_book[access_number] = 1; cout << book[access_number][0] << " by " << book[access_number][1] << " Issued on : " << temp_Date << " has been returned by " << member[i][0] << " on " << date << endl; //opening the text file of the book; ostringstream os; os << book[access_number][0] << ".txt"; ofstream OutBookAvail( os.str().c_str() ); //setting the values back to default as they were when we created the new text file OutBookAvail << 1 << "$" << 0 << "&" << "1/1/2010" << "*" << "2/1/2010" << endl; OutBookAvail.close(); int temp_code, temp_count; char temp_date; //opening the members txt file. ostringstream ss;
  • 31. ss << member[i][0] << ".txt"; ifstream mAvail( ss.str().c_str(),ios::app ); // reading the data // storing book code mAvail >> temp_code; mAvail.ignore(); //temp date getline (mAvail, temp_date); while (!mAvail.eof()) { // if the code of the book is equal to the code of the book returned then its not copied hence removing the code of the book that has been returned if (temp_code == access_number) { } else { // storing data of other books in a new temp txt file ostringstream ss; ss << member[i][0] << "_temp.txt"; ofstream OutMemberAvail( ss.str().c_str(),ios::app); OutMemberAvail << temp_code << "$" << temp_date << endl; OutMemberAvail.close();
  • 32. } mAvail >> temp_code; mAvail.ignore(); getline (mAvail, temp_date); } mAvail.close(); ostringstream ds; //removing the text file of the student ds << member[i][0] << ".txt"; remove ( ds.str().c_str()); ostringstream es; es << member[i][0] << "_temp.txt"; ostringstream ps; ps << member[i][0] << ".txt"; //renaming the temporary file to the original . in this way we have modified the txt file of the member removing data of the book returned and it only contain data of books that are still issed to him (if any) rename ( es.str().c_str(),ps.str().c_str()); } // if the username given does not match with the username of member stored in the books txt file while issuing than it gives an error else cout << " The Book Has Not Been Issued By This User :"
  • 33. << endl; } } } char due_date(void) { char due_date; int date = 0, month = 0 , year = 0; //calling date from computer char date_cal[9]; _strdate (date_cal); ofstream OutFile; OutFile.open("date.txt"); //storing it into date.txt OutFile << date_cal; OutFile.close(); ifstream InFile; //reading date.txt and storing days months and year seperatly in different int InFile.open ("date.txt"); InFile >> month; //to ignore / InFile.ignore(); InFile >> date;
  • 34. // to ignore / InFile.ignore(); InFile >> year; // calculating for feburary if (month == 2) { //checking if leap year if (year%400 == 0 || (year%100 != 0 && year%4 == 0)) { //making necesarry calculations if (date <= 8) date = date+21; else if(date > 8) { date = (date+21) - 29; month = month++; } } else if (date <= 7) date = date+21; else if (date > 7) { date = (date+21) - 28; month = month++; if (month > 12)
  • 35. { //resetting month to 1 and increasing year month is greater than 12 month = 1; year++; } } } /