Can you please put each class in its own header (.h) and code (.cpp) file as wel
ID: 3814093 • Letter: C
Question
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<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<iomanip.h>
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. : "<<bnum;
cout<<" Book name : ";
puts(bname);
cout<<"Author name :";
puts(aname);
}
void modify_book()
{
cout<<" "Book number. : "<<bnum;
cout<<" Modify book name : ";
gets(bname);
cout<<" Modify Author's name of the book :";
gets(aname);
}
char* retbnum()
{
return bnum;
}
void report()
{cout<<bnum,<<setw(30)<<bname<<setw(30)<<aname<<endl;}
};
// 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. : "<<admno;
cout<<" Patron Name : ";
puts(name);
cout<<"Number of books issued : "<<token;
if(token==1)
cout<<" Book number "<<pabno;
}
//.............................................................................
void modify_patron()
{
cout<<" Admission number :"<<admno;
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<<" "<<admno<<setw(20)<<name<<setw(10)<<token<<endl;}
};
//............................................................................
//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"<<endl;
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<<" Patron list ";
cout<<"========================== ";
cout<< Admission number. "<<setw(10)<<"Name"<<setw(20)<<"Book Issued ";
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<<" Book list ";
cout<<"========================== ";
cout<< Book number. "<<setw(20)<<"Book Name"<<setw(25)<<"Author ";
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. "<<fine;
}
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<<"";
}
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<<"";
}
}while(choice!='4');
<bnum; cout>admno;="" cout<<" enter="" the="" name="" of="" patron="" ";="" gets(name);="" token="0;" stb[0]="/0" ;="" cout<<" patron="" record="" created..";="" }="" ............................................................................="" void="" show_patron()="" {="" cout<<" admission="" nuber.="" :="" "<>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)" if(pa.rettoken()="=0)" book="" number.";="" cin>>bn;="" while(fp1.read((char*)&bk,sizeof(book))&&="" flag="=0)" if(strcmpi(bk.retbno(),="" bn)="=0)" bk.show_book();="" pa.addtoken();="" pa.getpabno(bk.retbno());="" int="" pos="-1*sizeof(pa);" fp.seekp(pos,="" ios::cur);="" fp.erite((char*)&pa,sizeof(patron));="" cout<<" t="" issued="" successfully please="" not:="" write="" current="" date="" on="" backside="" and="" submit="" within="" 15="" days="" otherwise="" subject="" to="" fine="" for="" each="" day="" after="" period";="" if(flag="=0)" cout<<"book="" number="" does="" not="" exist";="" else="" cout<<"you="" have="" returned="" last="" book";="" if(found="=0)" cout<<"patron="" exist...";="" getchoice();="" fp.close();="" fp1.close();="" .......................................................................="" book_return()="" char="" pn[6],="" bn[6];="" day,="" fine;="" clrscr();="" cout<<" book="" return="" ...";="" cout<<" please="" enter="" patron's="" admission="" cin>>pn;="" if(strcmpi(bk.retbnum(),="" pa.retpabnum())="=0)" cout" book="" in="" days";="" cin>>day;="" if(day>15)="" cout<<" fine="" has="" rs.="" "<>choice2;="" switch(choice2)="" case="" 1:="" write_patron();="" break;="" 2:="" display_alls();="" 3:="" num[6];="" cout<<" tplease="" number";="" cin>>num;="" display_sps(num);="" 4:="" modify_patron();="" 5:="" delete_pstron();="" 6:="" write_book();="" 7:="" display_allb();="" 8:="" ennter="" number.="" display_spb(num);="" 9:="" modify_book();="" 10:="" delete_book();="" 11:="" return;="" default:cout<<"";="" admin_menu="" ................................................................................................="" main()="" choice;="" intro();="" do="" cout<<" tmain="" menu";="" cout<<" t01.="" issue";="" cout<<" t02.="" deposit";="" cout<<" t03.="" administrator="" cout<<" t04.="" exit";="" cout<<" tplease="" select="" your="" option="" (1-4)="" choice="getche();" switch(choice)="" '1'="" :clrscr();="" book_issue();="" '2'="" :book_deposit();="" '3'="" :admin_menu();="" '4'="" :exit(0);="" default="" :cout<<"";="" }while(choice!="4" );
Explanation / Answer
Book is the main class in the above code and the 6 class files and the header files for each class that includes are :
book.cpp conio.h
patron.cpp math.h
delete_patron.cpp patron.h
intro.cpp iomanip.h
Adminmenu.cpp process.h
main.cpp stdio.h
writebook.cpp book.h