Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please put each class in its own header (.h) and code (.cpp) file as well as a .cpp for main and, if needed,

Can you please put each class in its own header (.h) and code (.cpp) file as well as a .cpp for main and, if needed, a .h file for main if any other functions of constants are needed. This means i need 7 cpp files (6 classes and 1 main) and at least 6 header files (1 for each class) if you create a .h from this code. thank you

#include

#include

#include

#include

#include

#include

class book

{

char bnum[6]; //book number

char bname[50]; // book name

char aname[20]; // author's name

public:

void create_book()

{

cout<<" New book entry... ";

cout<<" Enter the book number.";

cin>>bnum;

cout<<" Enter the name of book ";

gets(bname);

cout<<" Enter the author's name ";

gets(aname);

cout<<" Book created..";

}

void show_book()

{

cout<<" "Book number. : "<

cout<<" Book name : ";

puts(bname);

cout<<"Author name :";

puts(aname);

}

void modify_book()

{

cout<<" "Book number. : "<

cout<<" Modify book name : ";

gets(bname);

cout<<" Modify Author's name of the book :";

gets(aname);

}

char* retbnum()

{

return bnum;

}

void report()

{cout<

};

// class ends here..........................................................................................

class patron

{

char admno[6]; // administrator number

char name[20];

char pabno[6]; // patron book number

int token;

public:

void create_patron()

{

clrscr();

cout<<" New patron entry... ";

cout" Please enter the admission number. ";

cin>>admno;

cout<<" Enter the name of the patron ";

gets(name);

token =0;

stb[0]='/0';

cout<<" Patron record created..";

}

//............................................................................

void show_patron()

{

cout<<" Admission nuber. : "<

cout<<" Patron Name : ";

puts(name);

cout<<"\Number of books issued : "<

if(token==1)

cout<<" Book number "<

}

//.............................................................................

void modify_patron()

{

cout<<" Admission number :"<

cout<<" Modify patron Name : ";

gets(name);

}

char* retadmno()

{

return admno;

}

char* retpabno()

{

return pabno;

}

int rettoken()

{

return token;

}

void addtoken()

{token=1;}

void resettoken()

{token=0;}

void getptbno(char t[]) // to get patron book number

{

strcpy(pabno, t); // to get patron book number

}

void report()

{cout<<"\t"<

};

//............................................................................

//book.h

fstream fp, fp1

book bk;

patron pa;

void write_book()

{

char choice;

fp.open("book.dat, ios::out|ios::app)" // to place the file pointer at the end of the file (when it is opened)

do

{

clrscr();

bk.create_book();

fp.write(char*)&bk, sizeof(book));

cout<<" Do you want to add more record..(y/n?)";

cin>>choice;

}while(choice=='y'||choice=='Y');

fp.close();

}

// patron.h

//............................................................................

void write_patron()

{

char choice;

fp.open("patron.dat", ios::out|ios::app);

do

{

pa.create_patron();

fp.write(char*)&pa, sizeof(patron));

cout<<" Do you want to add more record..(y/n?)";

cin>>choice;

}while(choice=='y'||choice=='Y');

fp.close();

}

//.............................................................................

void display_spb(char n[]) //declare the object

{

cout<<" Book details ";

int flag=0;

fp.open("book.dat", ios::in);

while(fp.read((char*)&bk, sizeof(book)))

{

if(strcmpi(bk.retbno(),num)==0)

{

bk.show_book();

flag=1;

}

}

fp.close();

if(flag==0)

cout<<" Book does not exist";

getchoice;

}

//...........................................................................

void display_sps(char num[])

{

cout<<" Patron details ";

int flag=0;

fp.open("patron.dat", ios::in);

while(fp.read((char*)&pa, sizeof(patron)))

{

if(strcmpi(pa.retbno(),num)==0)

{

pa.show_patron();

flag=1;

}

}

fp.close();

if(flag==0)

cout<<" Patron does not exist";

getchoice;

}

//..............................................................................

void modify_book()

{

char num[[6]];

int found=0;

clrscr();

cout<<" tModify book record....";

cout<<" tPlease enter the book number of the book";

cin>>num;

fp.open("book.dat", ios::in|ios::out);

while(fp.read((char*)&bk,sizeof(book)) && found==0)

{

if(strcmpi(bk.retbnum(), num)==0)

{

bk.show_book();

cout<<" Enter the new details of the book"<

bk.modify_book();

int pos=-1*sizeof(bk);

fp.write((char*)&bk,sizeof(book));

cout<<" t Record updated";

found=1;

}

}

fp.close();

if(found==0)

cout<<" Record not found ";

getchoice();

}

//..............................................................................

void delete_patron

{

char num[6];

int flag=0;

clrscr();

cout<<" tDelete patron...";

cout<<" Enter the admission number of the patron you want to delete :";

cin>>num;

fp.open("patron.dat",ios::in|ios::out);

fstream fp2;

fp2.open("Temp.dat",ios::out);

fp.seekg(0, ios::beg);

while(fp.read((char*)&pa,sizeof(patron)))

{

if(strcmpi(pa.retadmno(),num!=0)

fp2.write((char*)&pa,sizeof(patron));

else flag=1;

}

fp2.close();

fp.close();

remove("patron.dat");

rename("Temp.dat","patron.dat");

if(flag==1)

cout<<" tRecord deleted ..";

else

cout<<" Record not found";

getchoice();

}

//...........................................................................

void delete_book()

{

char num[6];

clrscr();

cout<<" tDelete book...";

cout<<" Enter the book number of the book you want to delete :";

cin>>num;

fp.open("book.dat",ios::in|ios::out);

fstream fp2;

fp2.open("Temp.dat",ios::out);

fp.seekg(0,ios::beg);

while(fp.read((char*)&pa,sizeof(book)))

{

if(strcmpi(pa.retbnum(),num!=0)

{

fp2.write((char*)&bk,sizeof(book));

}

}

fp2.close();

fp.close();

remove("book.dat");

rename("Temp.dat","book.dat");

cout<<" tRecord deleted ..";

getchoice();

}

//..............................................................................

void display_allp() // to display all patrons in the system

{

clrscr();

fp.open("patron.dat",ios::in);

if(!fp)

{

cout<<"ERROR!!! FILE COULD NOT BE OPEN ";

getchoice();

return;

}

cout<<" \t\tPatron list ";

cout<<"========================== ";

cout<<\tAdmission number. "<

cout<<"========================== ";

while(fp.read((char*)&pa, sizeof(patron)))

{

pa.report();

}

fp.close();

getchoice;

}

//.............................................................................

void display_allb() // to display all books in the system

{

clrscr();

fp.open("book.dat",ios::in);

if(!fp)

{

cout<<"ERROR!!! FILE COULD NOT BE OPEN ";

getchoice();

return;

}

cout<<" \t\tBook list ";

cout<<"========================== ";

cout<<\tBook number. "<

cout<<"========================== ";

while(fp.read((char*)&pa, sizeof(book)))

{

bk.report();

}

fp.close();

getchoice;

}

//...........................................................................

void book_issue()

{

char pn[6], bn[6]; // patron number and book number

int found=0, flag=0;

clrscr();

cout<<" Book issue ...";

cout<<" Please enter the patron's admission number.";

cin>>pn;

fp.open("patron.dat",ios::in|ios::out);

fp1.open("book.dat",ios::in|ios::out);

while(fp.read((char*)&pa, sizeof(patron)) && found==0)

{

if(strcmpi(pa.retadmno(),pn)==0)

{

found=1;

if(pa.rettoken()==0)

{

cout<<" Enter the book number.";

cin>>bn;

while(fp1.read((char*)&bk,sizeof(book))&& flag==0)

{

if(strcmpi(bk.retbno(), bn)==0)

{

bk.show_book();

flag=1;

pa.addtoken();

pa.getpabno(bk.retbno());

int pos=-1*sizeof(pa);

fp.seekp(pos, ios::cur);

fp.erite((char*)&pa,sizeof(patron));

cout<<" t Book issued successfully Please not: Write current date on the backside of book and submit within 15 days otherwise subject to fine for each day after 15 days period";

}

}

if(flag==0)

cout<<"Book number does not exist";

}

else

cout<<"You have not returned the last book";

}

}

if(found==0)

cout<<"Patron record does not exist...";

getchoice();

fp.close();

fp1.close();

//.......................................................................

void book_return()

{

char pn[6], bn[6];

int found=0, flag=0, day, fine;

clrscr();

cout<<" Book return ...";

cout<<" Please enter the patron's admission number.";

cin>>pn;

fp.open("patron.dat",ios::in|ios::out);

fp1.open("book.dat",ios::in|ios::out);

while(fp.read((char*)&pa, sizeof(patron)) && found==0)

{

if(strcmpi(pa.retadmno(),pn)==0)

{

found=1;

if(pa.rettoken()==1)

{

while(fp1.read((char*)&bk,sizeof(book))&& flag==0)

{

if(strcmpi(bk.retbnum(), pa.retpabnum())==0)

{

bk.show_book();

flag=1;

cout" Book returned in number of days";

cin>>day;

if(day>15)

{

fine=(day-15)*1;

cout<<" Fine has returned RS. "<

}

pa.resettoken();

int pos=-1*sizeof(pa);

fp.seekp(pos, ios::cur);

fp.write((char*)&pa, sizeof(patron));

cout<<" t Book returned successfully";

}

}

if(flag==0)

cout<<"Book number does not exist";

}

else

cout<<"No book is issued..please check!!";

}

}

if(found==0)

cout<<"Patron record does not exist..";

getchoice();

fp.close();

fp1.close();

}

//.........................................................................

void intro()

{

clrscr();

gotoxy(35,11);

cout<<"LIBRARY";

gotoxy(35,14);

cout<<"MANAGEMENT";

gotoxy(35,17);

cout<<"SYSTEM";

cout<<" ************************************************";

cout<<" University of North Texas ";

cout<<" CSCE 1040 Homework 4 ";

cout<<" Name: Gersom Adu ";

cout<<" Email: gersomadu@my.unt.edu ";

cout<<" Instructor: David Keathly ";

cout<<" ************************************************";

getchoice();

}

//................................................................................................

void admin_menu()

{

clrscr();

int choice2;

cout<<" tADMINISTRATOR MENU";

cout<<" t1.CREATE PATRON RECORD";

cout<<" t2. DISPLAY ALL PATRONS RECORD";

cout<<" t3.DISPLAY SPECIFIC PATRON RECORD";

cout<<" t4.MODIFY PATRON RECORD";

cout<<" t5.DELETE PATRON RECORD";

cout<<" t6.CREATE BOOK";

cout<<" t7.DISPLAY ALL BOOKS ";

cout<<" t8.DISPLAY SPECIFIC BOOK ";

cout<<" t9.MODIFY BOOK ";

cout<<" t10.DELETE BOOK";

cout<<" t11.BACK TO MAIN MENU";

cout<<" tPlease enter your choice(1-11) ";

cin>>choice2;

switch(choice2)

{

case 1: clrscr();

write_patron();

break;

case 2: display_alls();

break;

case 3: char num[6];

clrscr();

cout<<" tPlease enter the admission number";

cin>>num;

display_sps(num);

break;

case 4: modify_patron();

break;

case 5: delete_pstron();

break;

case 6: clrscr();

write_book();

break;

case 7: display_allb();

break;

case 8: {

char num[6];

clrscr();

cout<<" tPlease ennter the book number. ";

cin>>num;

display_spb(num);

break;

}

case 9: modify_book();

break;

case 10: delete_book();

break;

case 11: return;

default:cout<<"\a";

}

admin_menu

}

//................................................................................................

void main()

{

char choice;

intro();

do

{

clrscr();

cout<<" tMAIN MENU";

cout<<" t01. BOOK ISSUE";

cout<<" t02. BOOK DEPOSIT";

cout<<" t03. ADMINISTRATOR MENU";

cout<<" t04. EXIT";

cout<<" tPlease select your option (1-4) ";

choice=getche();

switch(choice)

{

case '1' :clrscr();

book_issue();

break;

case '2' :book_deposit();

break;

case '3' :admin_menu();

break;

case '4' :exit(0);

default :cout<<"\a";

}

}while(choice!='4');

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

using signal flow graph

Answered: 1 week ago