This programming assignment will be graded by taking your class definition file
ID: 3859388 • Letter: T
Question
This programming assignment will be graded by taking your class definition file (Library.cpp) and linking with a test driver program which will exhaustively test the Library class. Below you will find two functions which can be used in your Library class.
Build Library
getnextline
1.0 Overview Madame Pince, the head librarian at Hogwarts has expressed an interest in the new "Computational Magic" to Professor Dumbledore and has asked if it would be possible to obtain a program which would catalog and store information on all of the books in the Hogwarts Library. Professor Dumbledore has requested just such a utility program which will be implemented as a binary tree. 2.0 Requirements The student shall define, develop, document, prototype, test, and modify as required the software system. 2.1 This software system shall define a class, called Library which maintains a Binary Tree of instances of a structure called Book as defined in section 2.3. 2.2 The Library class shall implement all the functionality of a binary tree and shall contain variables and functions as described below: 2.2.1 Member variables:--this class shall contain one private member variable. This shall be a pointer to a Book structure and shall be named m_pRoot. The variable m_pRoot shall point to the first instance of Book in the tree. 2.2.2 Library(), ~Library--these functions are the default constructor and destructor. The destructor function shall delete all instances of Book from the tree by calling the recursive function destroyTree passing in the root. 2.2.3 bool buildLibrary(char *fileName)--this function takes a single argument, a character array giving the name of a data file (provided by the instructor). It will open the data file and read all data from the data file, create Book structures to hold the data, and call the addBook() function to add each book to the database. This function shall be provided by the instructor. This function shall be public. 2.2.4 bool addBook(Book *newBook)--this function takes a single argument, a pointer to a Book structure. It will then add this book to the binary tree of books. This function shall use the book number of the book as the key for insertion into the binary tree. It will return true if the book was successfully added to the tree or false if it failed to add the book. This function shall be public. 2.2.5 Book *removeBook(int bookNum)--this function takes a book identification number as it's only argument. It shall locate the book in the tree of books and remove this book from the binary tree. It will set the left and right pointers of the removed Book structure to NULL and return a pointer to the book. If the item was not found in the tree it shall return NULL. This function shall be public.Remember that if the node to be removed from the tree has two children it actually get's overwritten. So in this case you will need to create a duplicate Book structure, and copy the data out of the one to be overwritten. Then after completing the deletion for a node with two children return the pointer to the new duplicate Book. 2.2.6 Book *getBookByNumber(int bookNum)--this function takes a book identification number as its' only argument. It will then locate this book in the tree of books and return a pointer to the book. If the book was not found it shall return NULL. You may assume, in this case, that it is OK to return a pointer to a book in the tree without worrying about it giving access to other items in the tree. This function shall be public 2.2.7 Book *getBookByTitle(char *title)--this function takes a book title as a character array as its' only argument. It just calls the private overloaded getbookByTitle() function and returns whatever that call returns. This function shall be public 2.2.8 Book *getBookByTitle(char *title, Book *rt)--this function takes a book title as a character array, and a pointer to the root of a sub-tree as its' two arguments. It will then locate this book in the tree of books and return a pointer to the book. If the book was not found it shall return NULL. This must be a variation on the recursive traversal of a binary tree algorithm. (Note: It will take some careful thought to be sure this one works correctly. We will discuss this function in class.) You may assume, in this case, that it is OK to return a pointer to a book in the tree without worrying about it giving access to other items in the tree. This function shall be private 2.2.9 void printLibrary()--this is a public function which will just call the private function printAll() as defined in section 2.2.10. 2.2.10 void printOne(Book *book)--this function shall take a pointer to a Book structure and print on the screen all information in the structure. This shall include the book identification number, book title, and author. This function shall be private as it should only be called by the printAll() function defined in section 2.2.10. 2.2.11 void printAll(Book *rt)--this shall be a private function which is called by the public function printLibrary(). It takes a single argument, a pointer to the root of a tree. It will perform an in-order recursive traversal of the tree and print all information in each book in the tree. It can call the function printOne() to print the information on the Book passed in as an argument. 2.2.12 bool getNextLine(char *line, int lineLen)-- this shall be a private function which can be called by the buildLibrary() function. It will read the next data line from the file referenced by the inFile argument and place it in the character array pointed to by the line argument. This function will be provided by the instructor. 2.2.13 void destroyTree(Book *rt)--this shall be a private function which can be called by the class destructor. It will recursively traverse the tree and delete all nodes from the tree. 2.3 This software system shall define a structure called Book which contains all information to define a book in the Hogwarts library. Code defining this structure shall be stored in a header file called Book.h. A Book.h file is included in the zip file which can be downloaded from the link given below. 2.3.1 An int, called bookNumber. This variable shall be used as the key. 2.3.2 A character array, called Title capable of holding strings of up to 127 characters. This array shall hold the title of a book. 2.3.3 A character array, called Author capable of holding strings of up to 64 characters. This array shall hold the author's name. 2.3.4 Two pointers, called left and right which shall point to Book structures and allow the building of binary trees of Book structures. 2.4 The Library class file and its' associated header file must be capable of being compiled and linked in with a driver program for testing.
This programming assignment will be graded by taking your class definition file (Library.cpp) and linking with a test driver program which will exhaustively test the Library class. Below you will find two functions which can be used in your Library class.
Build Library
#include <iostream> #include <fstream> #include <string.h> #include <stdlib.h> using namespace std; //------------------------------------------------------------- // Function: buildLibrary() // Purpose: Build the library from a data file // Args: fileName - character array holding the name of the // datafile defining the library. // Returns; True if library was successsfully built. //------------------------------------------------------------- bool Library::buildLibrary(char *fileName) { ifstream inFile; Book *bk; char line[128]; inFile.open(fileName, ifstream::in); if(!inFile.is_open()) { // inFile.is_open() returns false if the file could not be found or // if for some other reason the open failed. cout << "Unable to open file " << fileName << ". Program terminating... "; return false; } //first time reading file: Set GraphNode ID and Data while (getNextLine(inFile, line, 127)) //while the next line is readable { bk = new Book(); bk->left = bk->right = NULL; bk->bookNumber = atoi(line); // Read the book title getNextLine(inFile, line, 127); strcpy(bk->Title, line); // Read the author getNextLine(inFile, line, 127); strcpy(bk->Author, line); // Add this book to the tree addBook(bk); } return true; } getnextline
/---------------------------------------------------------------- // Function: getNextLine() // Purpose: Read a line from the data file skipping blank lines // and comment lines beginning with # // Args: inFile - reference argument to an open ifstream object // to read from. // line - character array into which the data line is read // lineLen - maximum number of characters which can be read // into the array line // Returns: True if a successful read was done. If False is // returned then the array line will be zero length. //---------------------------------------------------------------- bool Library::getNextLine(ifstream &inFile, char *line, int lineLen) { int done = false; while(!done) { inFile.getline(line, lineLen); if(inFile.good()) // If a line was successfully read { if(strlen(line) == 0) // Skip any blank lines continue; else if(line[0] == '#') // Skip any comment lines continue; else done = true; // Got a valid data line so return with this line } else { strcpy(line, ""); return false; // Flag end of file with null string and return false } } // end while return true; // Flag successful read }
Explanation / Answer
#include <windows.h>
#include<stdio.h>
#include<conio.h> //contains delay(),getch(),gotoxy(),etc.
#include <stdlib.h>
#include<string.h> //contains strcmp(),strcpy(),strlen(),etc
#include<ctype.h> //contains toupper(), tolower(),etc
#include<dos.h> //contains _dos_getdate
#include<time.h>
#define RETURNTIME 15
//list of function prototype
char catagories[][15]={"Computer","Electronics","Electrical","Civil","Mechnnical","Architecture"};
void returnfunc(void);
void mainmenu(void);
void addbooks(void);
void deletebooks(void);
void editbooks(void);
void searchbooks(void);
void issuebooks(void);
void viewbooks(void);
void closeapplication(void);
int getdata();
int checkid(int);
int t(void);
//void show_mouse(void);
void Password();
void issuerecord();
void loaderanim();
COORD coord = {0, 0}; // sets coordinates to 0,0
//COORD max_buffer_size = GetLargestConsoleWindowSize(hOut);
COORD max_res,cursor_size;
void gotoxy (int x, int y)
{
coord.X = x; coord.Y = y; // X and Y coordinates
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
//list of global files that can be acceed form anywhere in program
FILE *fp,*ft,*fs;
//list of global variable
int s;
char findbook;
char password[10]={"codechamp"};
struct meroDate
{
int mm,dd,yy;
};
struct books
{
int id;
char studentname[20];
char name[20];
char Author[20];
int quantity;
float priceamount;
int count;
int rackno;
char *cat;
struct meroDate issued;
struct meroDate duedate;
};
struct books a;
int main()
{
Password();
getch();
return 0;
}
void mainmenu()
{
//loaderanim();
system("cls");
// textbackground(13);
int i;
gotoxy(20,3);
printf(" MAIN MENU");
printf(" ");
gotoxy(20,5);
printf("۲ 1. Add Books ");
gotoxy(20,7);
printf("۲ 2. Delete books");
gotoxy(20,9);
printf("۲ 3. Search Books");
gotoxy(20,11);
printf("۲ 4. Issue Books");
gotoxy(20,13);
printf("۲ 5. View Book list");
gotoxy(20,15);
printf("۲ 6. Edit Book's Record");
gotoxy(20,17);
printf("۲ 7. Close Application");
gotoxy(20,19);
printf("------------------------------------------");
gotoxy(20,20);
t();
gotoxy(20,21);
printf("Enter your choice:");
switch(getch())
{
case '1':
addbooks();
break;
case '2':
deletebooks();
break;
case '3':
searchbooks();
break;
case '4':
issuebooks();
break;
case '5':
viewbooks();
break;
case '6':
editbooks();
break;
case '7':
{
system("cls");
gotoxy(16,3);
printf("Thanks for using the Program..");
gotoxy(10,7);
printf("Exiting in 5 second...........>");
//flushall();
delay(5000);
exit(0);
}
default:
{
gotoxy(10,23);
printf("Wrong Entry!!Please re-entered correct option");
if(getch())
mainmenu();
}
}
}
void addbooks(void) //funtion that add books
{
system("cls");
int i;
gotoxy(20,5);
printf("SELECT CATEGOIES");
printf("");
gotoxy(20,7);
printf("۲ 1. Computer");
gotoxy(20,9);
printf("۲ 2. Electronics");
gotoxy(20,11);
printf("۲ 3. Electrical");
gotoxy(20,13);
printf("۲ 4. Civil");
gotoxy(20,15);
printf("۲ 5. Mechanical");
gotoxy(20,17);
printf("۲ 6. Architecture");
gotoxy(20,19);
printf("۲ 7. Back to main menu");
gotoxy(20,21);
printf("");
printf("");
gotoxy(20,22);
printf("Enter your choice:");
scanf("%d",&s);
if(s==7)
mainmenu() ;
system("cls");
fp=fopen("Bibek.dat","ab+");
if(getdata()==1)
{
a.cat=catagories[s-1];
fseek(fp,0,SEEK_END);
fwrite(&a,sizeof(a),1,fp);
fclose(fp);
gotoxy(21,14);
printf("The record is sucessfully saved");
gotoxy(21,15);
printf("Save any more?(Y / N):");
if(getch()=='n')
mainmenu();
else
system("cls");
addbooks();
}
}
void deletebooks() //function that delete items from file fp
{
system("cls");
int d;
char another='y';
while(another=='y') //infinite loop
{
system("cls");
gotoxy(10,5);
printf("Enter the Book ID to delete:");
scanf("%d",&d);
fp=fopen("Bibek.dat","rb+");
rewind(fp);
while(fread(&a,sizeof(a),1,fp)==1)
{
if(a.id==d)
{
gotoxy(10,7);
printf("The book record is available");
gotoxy(10,8);
printf("Book name is %s",a.name);
gotoxy(10,9);
printf("Rack No. is %d",a.rackno);
findbook='t';
}
}
if(findbook!='t')
{
gotoxy(10,10);
printf("No record is found modify the search");
if(getch())
mainmenu();
}
if(findbook=='t' )
{
gotoxy(10,9);
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(&a,sizeof(a),1,fp)==1)
{
if(a.id!=d)
{
fseek(ft,0,SEEK_CUR);
fwrite(&a,sizeof(a),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')
{
gotoxy(10,10);
printf("The record is sucessfully deleted");
gotoxy(10,11);
printf("Delete another record?(Y/N)");
}
}
else
mainmenu();
fflush(stdin);
another=getch();
}
}
gotoxy(10,15);
mainmenu();
}
void searchbooks()
{
system("cls");
int d;
printf("*****************************Search Books*********************************");
gotoxy(20,10);
printf("۲ 1. Search By ID");
gotoxy(20,14);
printf("۲ 2. Search By Name");
gotoxy( 15,20);
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':
{
system("cls");
gotoxy(25,4);
printf("****Search Books By Id****");
gotoxy(20,5);
printf("Enter the book id:");
scanf("%d",&d);
gotoxy(20,7);
printf("Searching........");
while(fread(&a,sizeof(a),1,fp)==1)
{
if(a.id==d)
{
delay(2);
gotoxy(20,7);
printf("The Book is available");
gotoxy(20,8);
printf("");
printf("");
gotoxy(20,9);
printf(" ID:%d",a.id);gotoxy(47,9);printf("");
gotoxy(20,10);
printf(" Name:%s",a.name);gotoxy(47,10);printf("");
gotoxy(20,11);
printf(" Author:%s ",a.Author);gotoxy(47,11);printf("");
gotoxy(20,12);
printf(" Qantity:%d ",a.quantity);gotoxy(47,12);printf(""); gotoxy(47,11);printf("");
gotoxy(20,13);
printf(" priceamount:Rs.%.2f",a.priceamount);gotoxy(47,13);printf("");
gotoxy(20,14);
printf(" Rack No:%d ",a.rackno);gotoxy(47,14);printf("");
gotoxy(20,15);
printf("");
printf("");
findbook='t';
}
}
if(findbook!='t') //checks whether conditiion enters inside loop or not
{
gotoxy(20,8);
printf("");
gotoxy(20,9);printf(""); gotoxy(38,9);printf("");
gotoxy(20,10);
printf("");
gotoxy(22,9);printf("No Record Found");
}
gotoxy(20,17);
printf("Try another search?(Y/N)");
if(getch()=='y')
searchbooks();
else
mainmenu();
break;
}
case '2':
{
char s[15];
system("cls");
gotoxy(25,4);
printf("****Search Books By Name****");
gotoxy(20,5);
printf("Enter Book Name:");
scanf("%s",s);
int d=0;
while(fread(&a,sizeof(a),1,fp)==1)
{
if(strcmp(a.name,(s))==0) //checks whether a.name is equal to s or not
{
gotoxy(20,7);
printf("The Book is available");
gotoxy(20,8);
printf("");
printf("");
gotoxy(20,9);
printf(" ID:%d",a.id);gotoxy(47,9);printf("");
gotoxy(20,10);
printf(" Name:%s",a.name);gotoxy(47,10);printf("");
gotoxy(20,11);
printf(" Author:%s",a.Author);gotoxy(47,11);printf("");
gotoxy(20,12);
printf(" Qantity:%d",a.quantity);gotoxy(47,12);printf("");
gotoxy(20,13);
printf(" priceamount:Rs.%.2f",a.priceamount);gotoxy(47,13);printf("");
gotoxy(20,14);
printf(" Rack No:%d ",a.rackno);gotoxy(47,14);printf("");
gotoxy(20,15);
printf("");
printf("");
d++;
}
}
if(d==0)
{
gotoxy(20,8);
printf("");
gotoxy(20,9);printf(""); gotoxy(38,9);printf("");
gotoxy(20,10);
printf("");
gotoxy(22,9);printf("No Record Found");
}
gotoxy(20,17);
printf("Try another search?(Y/N)");
if(getch()=='y')
searchbooks();
else
mainmenu();
break;
}
default :
getch();
searchbooks();
}
fclose(fp);
}
void issuebooks(void) //function that issue books from library
{
int t;
system("cls");
printf("********************************ISSUE SECTION**************************");
gotoxy(10,5);
printf("۲ 1. Issue a Book");
gotoxy(10,7);
printf("۲ 2. View Issued Book");
gotoxy(10,9);
printf("۲ 3. Search Issued Book");
gotoxy(10,11);
printf("۲ 4. Remove Issued Book");
gotoxy(10,14);
printf("Enter a Choice:");
switch(getch())
{
case '1': //issue book
{
system("cls");
int c=0;
char another='y';
while(another=='y')
{
system("cls");
gotoxy(15,4);
printf("***Issue Book section***");
gotoxy(10,6);
printf("Enter the Book Id:");
scanf("%d",&t);
fp=fopen("Bibek.dat","rb");
fs=fopen("Issue.dat","ab+");
if(checkid(t)==0) //issues those which are present in library
{
gotoxy(10,8);
printf("The book record is available");
gotoxy(10,9);
printf("There are %d unissued books in library ",a.quantity);
gotoxy(10,10);
printf("The name of book is %s",a.name);
gotoxy(10,11);
printf("Enter student name:");
scanf("%s",a.studentname);
// struct dosdate_t d; //for current date
// _dos_getdate(&d);
// a.issued.dd=d.day;
// a.issued.mm=d.month;
//a.issued.yy=d.year;
gotoxy(10,12);
printf("Issued date=%d-%d-%d",a.issued.dd,a.issued.mm,a.issued.yy);
gotoxy(10,13);
printf("The BOOK of ID %d is issued",a.id);
a.duedate.dd=a.issued.dd+RETURNTIME; //for return date
a.duedate.mm=a.issued.mm;
a.duedate.yy=a.issued.yy;
if(a.duedate.dd>30)
{
a.duedate.mm+=a.duedate.dd/30;
a.duedate.dd-=30;
}
if(a.duedate.mm>12)
{
a.duedate.yy+=a.duedate.mm/12;
a.duedate.mm-=12;
}
gotoxy(10,14);
printf("To be return:%d-%d-%d",a.duedate.dd,a.duedate.mm,a.duedate.yy);
fseek(fs,sizeof(a),SEEK_END);
fwrite(&a,sizeof(a),1,fs);
fclose(fs);
c=1;
}
if(c==0)
{
gotoxy(10,11);
printf("No record found");
}
gotoxy(10,15);
printf("Issue any more(Y/N):");
fflush(stdin);
another=getche();
fclose(fp);
}
break;
}
case '2': //show issued book list
{
system("cls");
int j=4;
printf("*******************************Issued book list******************************* ");
gotoxy(2,2);
printf("STUDENT NAME CATEGORY ID BOOK NAME ISSUED DATE RETURN DATE");
fs=fopen("Issue.dat","rb");
while(fread(&a,sizeof(a),1,fs)==1)
{
gotoxy(2,j);
printf("%s",a.studentname);
gotoxy(18,j);
printf("%s",a.cat);
gotoxy(30,j);
printf("%d",a.id);
gotoxy(36,j);
printf("%s",a.name);
gotoxy(51,j);
printf("%d-%d-%d",a.issued.dd,a.issued.mm,a.issued.yy );
gotoxy(65,j);
printf("%d-%d-%d",a.duedate.dd,a.duedate.mm,a.duedate.yy);
//struct dosdate_t d;
//_dos_getdate(&d);
gotoxy(50,25);
// printf("Current date=%d-%d-%d",d.day,d.month,d.year);
j++;
}
fclose(fs);
gotoxy(1,25);
returnfunc();
}
break;
case '3': //search issued books by id
{
system("cls");
gotoxy(10,6);
printf("Enter Book ID:");
int p,c=0;
char another='y';
while(another=='y')
{
scanf("%d",&p);
fs=fopen("Issue.dat","rb");
while(fread(&a,sizeof(a),1,fs)==1)
{
if(a.id==p)
{
issuerecord();
gotoxy(10,12);
printf("Press any key.......");
getch();
issuerecord();
c=1;
}
}
fflush(stdin);
fclose(fs);
if(c==0)
{
gotoxy(10,8);
printf("No Record Found");
}
gotoxy(10,13);
printf("Try Another Search?(Y/N)");
another=getch();
}
}
break;
case '4': //remove issued books from list
{
system("cls");
int b;
FILE *fg; //declaration of temporary file for delete
char another='y';
while(another=='y')
{
gotoxy(10,5);
printf("Enter book id to remove:");
scanf("%d",&b);
fs=fopen("Issue.dat","rb+");
while(fread(&a,sizeof(a),1,fs)==1)
{
if(a.id==b)
{
issuerecord();
findbook='t';
}
if(findbook=='t')
{
gotoxy(10,12);
printf("Do You Want to Remove it?(Y/N)");
if(getch()=='y')
{
fg=fopen("record.dat","wb+");
rewind(fs);
while(fread(&a,sizeof(a),1,fs)==1)
{
if(a.id!=b)
{
fseek(fs,0,SEEK_CUR);
fwrite(&a,sizeof(a),1,fg);
}
}
fclose(fs);
fclose(fg);
remove("Issue.dat");
rename("record.dat","Issue.dat");
gotoxy(10,14);
printf("The issued book is removed from list");
}
}
if(findbook!='t')
{
gotoxy(10,15);
printf("No Record Found");
}
}
gotoxy(10,16);
printf("Delete any more?(Y/N)");
another=getch();
}
}
default:
gotoxy(10,18);
printf("Wrong Entry!!");
getch();
issuebooks();
break;
}
gotoxy(1,30);
returnfunc();
}
void viewbooks(void) //show the list of book persists in library
{
int i=0,j;
system("cls");
gotoxy(1,1);
printf("*********************************Book List*****************************");
gotoxy(2,2);
printf(" CATEGORY ID BOOK NAME AUTHOR QTY priceamount RackNo ");
j=4;
fp=fopen("Bibek.dat","rb");
while(fread(&a,sizeof(a),1,fp)==1)
{
gotoxy(3,j);
printf("%s",a.cat);
gotoxy(16,j);
printf("%d",a.id);
gotoxy(22,j);
printf("%s",a.name);
gotoxy(36,j);
printf("%s",a.Author);
gotoxy(50,j);
printf("%d",a.quantity);
gotoxy(57,j);
printf("%.2f",a.priceamount);
gotoxy(69,j);
printf("%d",a.rackno);
printf(" ");
j++;
i=i+a.quantity;
}
gotoxy(3,25);
printf("Total Books =%d",i);
fclose(fp);
gotoxy(35,25);
returnfunc();
}
void editbooks(void) //edit information about book
{
system("cls");
int c=0;
int d,e;
gotoxy(20,4);
printf("****Edit Books Section****");
char another='y';
while(another=='y')
{
system("cls");
gotoxy(15,6);
printf("Enter Book Id to be edited:");
scanf("%d",&d);
fp=fopen("Bibek.dat","rb+");
while(fread(&a,sizeof(a),1,fp)==1)
{
if(checkid(d)==0)
{
gotoxy(15,7);
printf("The book is availble");
gotoxy(15,8);
printf("The Book ID:%d",a.id);
gotoxy(15,9);
printf("Enter new name:");scanf("%s",a.name);
gotoxy(15,10);
printf("Enter new Author:");scanf("%s",a.Author);
gotoxy(15,11);
printf("Enter new quantity:");scanf("%d",&a.quantity);
gotoxy(15,12);
printf("Enter new priceamount:");scanf("%f",&a.priceamount);
gotoxy(15,13);
printf("Enter new rackno:");scanf("%d",&a.rackno);
gotoxy(15,14);
printf("The record is modified");
fseek(fp,ftell(fp)-sizeof(a),0);
fwrite(&a,sizeof(a),1,fp);
fclose(fp);
c=1;
}
if(c==0)
{
gotoxy(15,9);
printf("No record found");
}
}
gotoxy(15,16);
printf("Modify another Record?(Y/N)");
fflush(stdin);
another=getch() ;
}
returnfunc();
}
void returnfunc(void)
{
{
printf(" Press ENTER to return to main menu");
}
a:
if(getch()==13) //allow only use of enter
mainmenu();
else
goto a;
}
int getdata()
{
int t;
gotoxy(20,3);
printf("Enter the Information Below");
gotoxy(20,4);
printf("");
printf("");
gotoxy(20,5);
printf("");gotoxy(46,5);printf("");
gotoxy(20,6);
printf("");gotoxy(46,6);printf("");
gotoxy(20,7);
printf("");gotoxy(46,7);printf("");
gotoxy(20,8);
printf("");gotoxy(46,8);printf("");
gotoxy(20,9);
printf("");gotoxy(46,9);printf("");
gotoxy(20,10);
printf("");gotoxy(46,10);printf("");
gotoxy(20,11);
printf("");gotoxy(46,11);printf("");
gotoxy(20,12);
printf("");
printf("");
gotoxy(21,5);
printf("Category:");
gotoxy(31,5);
printf("%s",catagories[s-1]);
gotoxy(21,6);
printf("Book ID: ");
gotoxy(30,6);
scanf("%d",&t);
if(checkid(t) == 0)
{
gotoxy(21,13);
printf("The book id already exists");
getch();
mainmenu();
return 0;
}
a.id=t;
gotoxy(21,7);
printf("Book Name:");gotoxy(33,7);
scanf("%s",a.name);
gotoxy(21,8);
printf("Author:");gotoxy(30,8);
scanf("%s",a.Author);
gotoxy(21,9);
printf("Quantity:");gotoxy(31,9);
scanf("%d",&a.quantity);
gotoxy(21,10);
printf("priceamount:");gotoxy(28,10);
scanf("%f",&a.priceamount);
gotoxy(21,11);
printf("Rack No:");gotoxy(30,11);
scanf("%d",&a.rackno);
return 1;
}
int checkid(int t) //check whether the book is exist in library or not
{
rewind(fp);
while(fread(&a,sizeof(a),1,fp)==1)
if(a.id==t)
return 0; //returns 0 if book exits
return 1; //return 1 if it not
}
int t(void) //for time
{
time_t t;
time(&t);
printf("Date and time:%s ",ctime(&t));
return 0 ;
}
void Password(void) //for password option
{
system("cls");
char d[25]="Password Protected";
char ch,pass[10];
int i=0,j;
//textbackground(WHITE);
//textcolor(RED);
gotoxy(10,4);
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] = '';
if(strcmp(pass,password)==0)
{
gotoxy(15,9);
//textcolor(BLINK);
printf("Password match");
gotoxy(17,10);
printf("Press any key to countinue.....");
getch();
mainmenu();
}
else
{
gotoxy(15,16);
printf("Warning!! Incorrect Password");
getch();
Password();
}
}
void issuerecord() //display issued book's information
{
system("cls");
gotoxy(10,8);
printf("The Book has taken by Mr. %s",a.studentname);
gotoxy(10,9);
printf("Issued Date:%d-%d-%d",a.issued.dd,a.issued.mm,a.issued.yy);
gotoxy(10,10);
printf("Returning Date:%d-%d-%d",a.duedate.dd,a.duedate.mm,a.duedate.yy);
}
void loaderanim()
{
int loader;
system("cls");
gotoxy(20,10);
printf("LOADING........");
printf(" ");
gotoxy(22,11);
for(loader=1;loader<20;loader++)
{
delay(100);printf("%c",219);}
}
//End of program
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.