Can you please separate this code into 10 .cpp and 10-11 *.h files //***********
ID: 3828797 • Letter: C
Question
Can you please separate this code into 10 .cpp and 10-11 *.h files
//***************************************************************
// HEADER FILE USED IN PROJECT
//****************************************************************
#include<fstream>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<stdlib.h>
#include <string.h>
//#include<stdio.h>
using namespace std;
//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************
class book
{
char bno[6];
char bname[50];
char aname[20];
public:
void create_book()
{
cout<<" NEW BOOK ENTRY... ";
cout<<" Enter The book no.";
cin>>bno;
cout<<" Enter The Name of The Book ";
cin>>bname;
cout<<" Enter The Author's Name ";
cin>>aname;
cout<<" Book Created..";
}
void show_book()
{
cout<<" Book no. : "<<bno;
cout<<" Book Name : ";
puts(bname);
cout<<"Author Name : ";
puts(aname);
}
void modify_book()
{
cout<<" Book no. : "<<bno;
cout<<" Modify Book Name : ";
cin>>bname;
cout<<" Modify Author's Name of Book : ";
cin>>aname;
}
char* retbno()
{
return bno;
}
void report()
{cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;}
}; // class ends here
class student
{
char admno[6];
char name[20];
char stbno[6];
int token;
public:
void create_student()
{
cout<<" NEW STUDENT ENTRY... ";
cout<<" Enter The admission no. ";
cin>>admno;
cout<<" Enter The Name of The Student ";
cin>>name;
token=0;
stbno[0]='';
cout<<" Student Record Created..";
}
void show_student()
{
cout<<" Admission no. : "<<admno;
cout<<" Student Name : ";
puts(name);
cout<<" No of Book issued : "<<token;
if(token==1)
cout<<" Book No "<<stbno;
}
void modify_student()
{
cout<<" Admission no. : "<<admno;
cout<<" Modify Student Name : ";
cin>>name;
}
char* retadmno()
{
return admno;
}
char* retstbno()
{
return stbno;
}
int rettoken()
{
return token;
}
void addtoken()
{token=1;}
void resettoken()
{token=0;}
void getstbno(char t[])
{
strcpy(stbno,t);
}
void report()
{cout<<" "<<admno<<setw(20)<<name<<setw(10)<<token<<endl;}
}; // class ends here
//***************************************************************
// global declaration for stream object, object
//****************************************************************
fstream fp,fp1;
book bk;
student st;
//***************************************************************
// function to write in file
//****************************************************************
void write_book()
{
char ch;
fp.open("book.dat",ios::out|ios::app);
do
{
bk.create_book();
fp.write((char*)&bk,sizeof(book));
cout<<" Do you want to add more record..(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}
void write_student()
{
char ch;
fp.open("student.dat",ios::out|ios::app);
do
{
st.create_student();
fp.write((char*)&st,sizeof(student));
cout<<" Do you want to add more record..(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}
//***************************************************************
// function to read specific record from file
//****************************************************************
void display_spb(char n[])
{
cout<<" BOOK DETAILS ";
int flag=0;
fp.open("book.dat",ios::in);
while(fp.read((char*)&bk,sizeof(book)))
{
if(std::strcpy(bk.retbno(),n)==0)
{
bk.show_book();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<" Book does not exist";
return;
}
void display_sps(char n[])
{
cout<<" STUDENT DETAILS ";
int flag=0;
fp.open("student.dat",ios::in);
while(fp.read((char*)&st,sizeof(student)))
{
if((std::strcpy(st.retadmno(),n)==0))
{
st.show_student();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<" Student does not exist";
return;
}
//***************************************************************
// function to modify record of file
//****************************************************************
void modify_book()
{
char n[6];
int found=0;
cout<<" MODIFY BOOK RECORD.... ";
cout<<" Enter The book no. of The book";
cin>>n;
fp.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&bk,sizeof(book)) && found==0)
{
if(std::strcpy(bk.retbno(),n)==0)
{
bk.show_book();
cout<<" Enter The New Details of book"<<endl;
bk.modify_book();
int pos=-1*sizeof(bk);
fp.seekp(pos,ios::cur);
fp.write((char*)&bk,sizeof(book));
cout<<" Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<" Record Not Found ";
return;
}
void modify_student()
{
char n[6];
int found=0;
cout<<" MODIFY STUDENT RECORD... ";
cout<<" Enter The admission no. of The student";
cin>>n;
fp.open("student.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(std::strcpy(st.retadmno(),n)==0)
{
st.show_student();
cout<<" Enter The New Details of student"<<endl;
st.modify_student();
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<" Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<" Record Not Found ";
return;
}
//***************************************************************
// function to delete record of file
//****************************************************************
void delete_student()
{
char n[6];
int flag=0;
cout<<" DELETE STUDENT...";
cout<<" Enter The admission no. of the Student You Want To Delete : ";
cin>>n;
fp.open("student.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&st,sizeof(student)))
{
if(std::strcpy(st.retadmno(),n)!=0)
fp2.write((char*)&st,sizeof(student));
else
flag=1;
}
fp2.close();
fp.close();
remove("student.dat");
rename("Temp.dat","student.dat");
if(flag==1)
cout<<" Record Deleted ..";
else
cout<<" Record not found";
return;
}
void delete_book()
{
char n[6];
cout<<" DELETE BOOK ...";
cout<<" Enter The Book no. of the Book You Want To Delete : ";
cin>>n;
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*)&bk,sizeof(book)))
{
if(std::strcpy(bk.retbno(),n)!=0)
{
fp2.write((char*)&bk,sizeof(book));
}
}
fp2.close();
fp.close();
remove("book.dat");
rename("Temp.dat","book.dat");
cout<<" Record Deleted ..";
return;
}
//***************************************************************
// function to display all students list
//****************************************************************
void display_alls()
{
fp.open("student.dat",ios::in);
if(!fp)
{
cout<<" ERROR!!! FILE COULD NOT BE OPEN ";
return;
}
cout<<" STUDENT LIST ";
cout<<"================================================================== ";
cout<<" Admission No."<<setw(10)<<"Name"<<setw(20)<<"Book Issued ";
cout<<"================================================================== ";
while(fp.read((char*)&st,sizeof(student)))
st.report();
fp.close();
return;
}
//***************************************************************
// function to display Books list
//****************************************************************
void display_allb()
{
fp.open("book.dat",ios::in);
if(fp==0)
{
cout<<" ERROR!!! FILE COULD NOT BE OPEN ";
return;
}
cout<<" Book LIST ";
cout<<"========================================================================= ";
cout<<" Book Number"<<setw(20)<<"Book Name"<<setw(25)<<"Author ";
cout<<"========================================================================= ";
while(fp.read((char*)&bk,sizeof(book)))
bk.report();
fp.close();
return;
}
//***************************************************************
// function to issue book
//****************************************************************
void book_issue()
{
char sn[6],bn[6];
int found=0,flag=0;
cout<<" BOOK ISSUE ...";
cout<<" Enter The student's admission no.";
cin>>sn;
fp.open("student.dat",ios::in|ios::out);
fp1.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(!std::strcpy(st.retadmno(),sn))
{
found=1;
if(!st.rettoken())
{
cout<<" Enter the book no. ";
cin>>bn;
while(fp1.read((char*)&bk,sizeof(book))&& !flag)
{
if(!std::strcpy(bk.retbno(),bn))
{
bk.show_book();
flag=1;
st.addtoken();
st.getstbno(bk.retbno());
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<" Book issued successfully Please Note: Write the current date in backside of your book and submit it within 15 days. Fine Rs. 1 for each day after 15 days period";
}
}
if(flag==0)
cout<<" Book no does not exist";
}
else
cout<<" !!!!You have not returned the last book!!!! ";
}
}
if(found==0)
cout<<" Student record not exist...";
return;
fp.close();
fp1.close();
}
//***************************************************************
// function to deposit book
//****************************************************************
void book_deposit()
{
char sn[6],bn[6];
int found=0,flag=0,day,fine;
cout<<" BOOK DEPOSIT ...";
cout<<" Enter The studentís admission no.";
cin>>sn;
fp.open("student.dat",ios::in|ios::out);
fp1.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && !found)
{
if(!std::strcpy(st.retadmno(),sn))
{
found=1;
if(st.rettoken()==1)
{
while(fp1.read((char*)&bk,sizeof(book))&& !flag)
{
if(std::strcpy(bk.retbno(),st.retstbno())==0)
{
bk.show_book();
flag=1;
cout<<" Book deposited in no. of days";
cin>>day;
if(day>15)
{
fine=(day-15)*1;
cout<<" Fine has to deposited Rs. "<<fine;
}
st.resettoken();
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<" Book deposited successfully";
}
}
if(!flag)
cout<<" Book no does not exist";
}
else
cout<<" No book is issued..please check!!";
}
}
if(!found)
cout<<" Student record not exist...";
return;
fp.close();
fp1.close();
}
//***************************************************************
// INTRODUCTION FUNCTION
//****************************************************************
void intro(){
for(int i=0;i<179;i++){
cout<<"*";
}
cout<<" University of North Texas ";
cout<<" CSCE 1040 Homework 4 ";
cout<<" Name: n/a ";
cout<<" Email: n/a ";
cout<<" Instructor: n/a " <<endl;
for(int i=0;i<179;i++){
cout<<"*";
}
cout<<" PRESENTS";
cout<<" ******************************* ";
cout<<" ** LIBRARY MANAGEMENT SYSTEM **";
cout<<" ******************************* ";
for(int i=0;i<179;i++){
cout<<"*";
}
return;
}
//***************************************************************
// ADMINISTRATOR MENU FUNCTION
//****************************************************************
void admin_menu()
{
int ch2;
cout<<" ADMINISTRATOR MENU";
cout<<" 1.CREATE STUDENT RECORD";
cout<<" 2.DISPLAY ALL STUDENTS RECORD";
cout<<" 3.DISPLAY SPECIFIC STUDENT RECORD ";
cout<<" 4.MODIFY STUDENT RECORD";
cout<<" 5.DELETE STUDENT RECORD";
cout<<" 6.CREATE BOOK ";
cout<<" 7.DISPLAY ALL BOOKS ";
cout<<" 8.DISPLAY SPECIFIC BOOK ";
cout<<" 9.MODIFY BOOK ";
cout<<" 10.DELETE BOOK ";
cout<<" 11.BACK TO MAIN MENU";
cout<<" Please Enter Your Choice (1-11) ";
cin>>ch2;
switch(ch2)
{
case 1: write_student();
break;
case 2: display_alls();
break;
case 3: char num[6];
cout<<" Please Enter The Admission No. ";
cin>>num;
display_sps(num);
break;
case 4: modify_student();
break;
case 5: delete_student();
break;
case 6: write_book();
break;
case 7: display_allb();
break;
case 8: {
char num[6];
cout<<" Please Enter The book No. ";
cin>>num;
display_spb(num);
break;
}
case 9: modify_book();
break;
case 10: delete_book();
break;
case 11: return;
default:cout<<"";
}
admin_menu();
}
//***************************************************************
// THE MAIN FUNCTION OF PROGRAM
//****************************************************************
int main()
{
char ch;
intro();
do{
cout<<" MAIN MENU";
cout<<" 1. BOOK ISSUE";
cout<<" 2. BOOK DEPOSIT";
cout<<" 3. ADMINISTRATOR MENU";
cout<<" 4. EXIT";
cout<<" Please Select Your Option (1-4) ";
cin>>ch;
switch(ch)
{
case '1': book_issue();
break;
case '2': book_deposit();
break;
case '3': admin_menu();
break;
case '4': exit(0);
default :cout<<"";
}
}while(ch!='4');
return 0;
}
Can you please separate this code into 10 .cpp and 10-11 *.h files
Explanation / Answer
#include<fstream>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<stdlib.h>
#include <string.h>
//#include<stdio.h>
using namespace std;
class book
{
char bno[6];
char bname[50];
char aname[20];
public:
void create_book()
{
cout<<" NEW BOOK ENTRY... ";
cout<<" Enter The book no.";
cin>>bno;
cout<<" Enter The Name of The Book ";
cin>>bname;
cout<<" Enter The Author's Name ";
cin>>aname;
cout<<" Book Created..";
}
void show_book()
{
cout<<" Book no. : "<<bno;
cout<<" Book Name : ";
puts(bname);
cout<<"Author Name : ";
puts(aname);
}
void modify_book()
{
cout<<" Book no. : "<<bno;
cout<<" Modify Book Name : ";
cin>>bname;
cout<<" Modify Author's Name of Book : ";
cin>>aname;
}
char* retbno()
{
return bno;
}
void report()
{cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;}
}; // class ends here
class student
{
char admno[6];
char name[20];
char stbno[6];
int token;
public:
void create_student()
{
cout<<" NEW STUDENT ENTRY... ";
cout<<" Enter The admission no. ";
cin>>admno;
cout<<" Enter The Name of The Student ";
cin>>name;
token=0;
stbno[0]='';
cout<<" Student Record Created..";
}
void show_student()
{
cout<<" Admission no. : "<<admno;
cout<<" Student Name : ";
puts(name);
cout<<" No of Book issued : "<<token;
if(token==1)
cout<<" Book No "<<stbno;
}
void modify_student()
{
cout<<" Admission no. : "<<admno;
cout<<" Modify Student Name : ";
cin>>name;
}
char* retadmno()
{
return admno;
}
char* retstbno()
{
return stbno;
}
int rettoken()
{
return token;
}
void addtoken()
{token=1;}
void resettoken()
{token=0;}
void getstbno(char t[])
{
strcpy(stbno,t);
}
void report()
{cout<<" "<<admno<<setw(20)<<name<<setw(10)<<token<<endl;}
}; // class ends here
//***************************************************************
// global declaration for stream object, object
//****************************************************************
fstream fp,fp1;
book bk;
student st;
//***************************************************************
// function to write in file
//****************************************************************
void write_book()
{
char ch;
fp.open("book.dat",ios::out|ios::app);
do
{
bk.create_book();
fp.write((char*)&bk,sizeof(book));
cout<<" Do you want to add more record..(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}
void write_student()
{
char ch;
fp.open("student.dat",ios::out|ios::app);
do
{
st.create_student();
fp.write((char*)&st,sizeof(student));
cout<<" Do you want to add more record..(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}
//***************************************************************
// function to read specific record from file
//****************************************************************
void display_spb(char n[])
{
cout<<" BOOK DETAILS ";
int flag=0;
fp.open("book.dat",ios::in);
while(fp.read((char*)&bk,sizeof(book)))
{
if(std::strcpy(bk.retbno(),n)==0)
{
bk.show_book();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<" Book does not exist";
return;
}
void display_sps(char n[])
{
cout<<" STUDENT DETAILS ";
int flag=0;
fp.open("student.dat",ios::in);
while(fp.read((char*)&st,sizeof(student)))
{
if((std::strcpy(st.retadmno(),n)==0))
{
st.show_student();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<" Student does not exist";
return;
}
//***************************************************************
// function to modify record of file
//****************************************************************
void modify_book()
{
char n[6];
int found=0;
cout<<" MODIFY BOOK RECORD.... ";
cout<<" Enter The book no. of The book";
cin>>n;
fp.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&bk,sizeof(book)) && found==0)
{
if(std::strcpy(bk.retbno(),n)==0)
{
bk.show_book();
cout<<" Enter The New Details of book"<<endl;
bk.modify_book();
int pos=-1*sizeof(bk);
fp.seekp(pos,ios::cur);
fp.write((char*)&bk,sizeof(book));
cout<<" Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<" Record Not Found ";
return;
}
void modify_student()
{
char n[6];
int found=0;
cout<<" MODIFY STUDENT RECORD... ";
cout<<" Enter The admission no. of The student";
cin>>n;
fp.open("student.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(std::strcpy(st.retadmno(),n)==0)
{
st.show_student();
cout<<" Enter The New Details of student"<<endl;
st.modify_student();
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<" Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<" Record Not Found ";
return;
}
//***************************************************************
// function to delete record of file
//****************************************************************
void delete_student()
{
char n[6];
int flag=0;
cout<<" DELETE STUDENT...";
cout<<" Enter The admission no. of the Student You Want To Delete : ";
cin>>n;
fp.open("student.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&st,sizeof(student)))
{
if(std::strcpy(st.retadmno(),n)!=0)
fp2.write((char*)&st,sizeof(student));
else
flag=1;
}
fp2.close();
fp.close();
remove("student.dat");
rename("Temp.dat","student.dat");
if(flag==1)
cout<<" Record Deleted ..";
else
cout<<" Record not found";
return;
}
void delete_book()
{
char n[6];
cout<<" DELETE BOOK ...";
cout<<" Enter The Book no. of the Book You Want To Delete : ";
cin>>n;
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*)&bk,sizeof(book)))
{
if(std::strcpy(bk.retbno(),n)!=0)
{
fp2.write((char*)&bk,sizeof(book));
}
}
fp2.close();
fp.close();
remove("book.dat");
rename("Temp.dat","book.dat");
cout<<" Record Deleted ..";
return;
}