Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ You will create a class representing an Abstract Data Type for a library boo

ID: 3709758 • Letter: C

Question

C++

You will create a class representing an Abstract Data Type for a library book. This class will use several helper classes (via Class Aggregation [Gaddis Section 14.7]).

The helper classes, that you will write, are a date class, a name class, and a book class.

Each of your classes will include: constructors accessors mutators a display method which will use the accessor methods to (neatly) print its private data members. a method to clear the data fields.

The private data members of each class:

LibraryBook methods

constructors to create a LibraryBook object

accessors and mutators for each data member

(neatly) Print all information about this Library Book

print borrower and date information only if on loan

Loan the book:

parameters include borrowing date, due date, and borrower

Ensure that the due date is after the borrowing date
(else do nothing other than print an error message)

if already out on loan, do nothing other than printing a message to that effect
(can include due date).

Return the book:

Expunge the borrower name information and set isLoaned to false
(if not loaned do nothing and print a message to that effect)

Renew the book:

Update the borrowing date and due date.

bool isOverdue(Date) const {compares parameter Date with borrowed Date}

if not loaned, print a message to that effect and return false

The following are components of your test driver program and not the LibraryBook class.
However, they will use the LibraryBook class.

Declare a vector of LibraryBook objects, where each element corresponds to a different book.

Write a non-class function to read a set of Books from a file into the LibraryBook vector.
(This will save you from having to manually input this information every time you run your program.)

Using the LibraryBook vector, write the following set of non-class functions (which will use LibraryBook class methods)

Print all library book record information for books out on loan

Print all library book record information for books not out on loan

Print all library book record information for books overdue

Print the information for that library book record which has a specific ID number

Print an appropriate message if there is no library book having the specified ID number

Print all library book record information (if not out on loan, ignore date and borrower information)

Your test driver program should call these functions before, during, and after you perform some borrowing and returning transactions.

Feel free to add to this functionality, with a menuing system, with other functions that use the LibraryBook class, and/or print the library book information in order sorted by some key

Explanation / Answer

CODE :

#include<fstream.h>

#include<conio.h>

#include<stdio.h>

#include<process.h>

#include<string.h>

#include<iomanip.h>

//***************************************************************

// 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 ";

gets(bname);

cout<<" Enter The Author's Name ";

gets(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 : ";

gets(bname);

cout<<" Modify Author's Name of Book : ";

gets(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()

{

clrscr();

cout<<" NEW STUDENT ENTRY... ";

cout<<" Enter The admission no. ";

cin>>admno;

cout<<" Enter The Name of The Student ";

gets(name);

token=0;

stbno[0]='/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 : ";

gets(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

{

clrscr();

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(strcmpi(bk.retbno(),n)==0)

{

bk.show_book();

flag=1;

}

}

fp.close();

if(flag==0)

cout<<" Book does not exist";

getch();

}

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((strcmpi(st.retadmno(),n)==0))

{

st.show_student();

flag=1;

}

}

fp.close();

if(flag==0)

cout<<" Student does not exist";

getch();

}

//***************************************************************

// function to modify record of file

//****************************************************************

void modify_book()

{

char n[6];

int found=0;

clrscr();

cout<<" MODIFY BOOK REOCORD.... ";

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(strcmpi(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 ";

getch();

}

void modify_student()

{

char n[6];

int found=0;

clrscr();

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(strcmpi(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 ";

getch();

}

//***************************************************************

// function to delete record of file

//****************************************************************

void delete_student()

{

char n[6];

int flag=0;

clrscr();

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(strcmpi(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";

getch();

}

void delete_book()

{

char n[6];

clrscr();

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(strcmpi(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 ..";

getch();

}

//***************************************************************

// function to display all students list

//****************************************************************

void display_alls()

{

clrscr();

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

if(!fp)

{

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

getch();

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();

getch();

}

//***************************************************************

// function to display Books list

//****************************************************************

void display_allb()

{

clrscr();

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

if(!fp)

{

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

getch();

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();

getch();

}

//***************************************************************

// function to issue book

//****************************************************************

void book_issue()

{

char sn[6],bn[6];

int found=0,flag=0;

clrscr();

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(strcmpi(st.retadmno(),sn)==0)

{

found=1;

if(st.rettoken()==0)

{

cout<<" Enter the book no. ";

cin>>bn;

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

{

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

{

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 current date

in backside of book and submit 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...";

getch();

fp.close();

fp1.close();

}

//***************************************************************

// function to deposit book

//****************************************************************

void book_deposit()

{

char sn[6],bn[6];

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

clrscr();

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==0)

{

if(strcmpi(st.retadmno(),sn)==0)

{

found=1;

if(st.rettoken()==1)

{

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

{

if(strcmpi(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==0)

cout<<"Book no does not exist";

}

else

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

}

}

if(found==0)

cout<<"Student record not exist...";

getch();

fp.close();

fp1.close();

}

//***************************************************************

// INTRODUCTION FUNCTION

//****************************************************************

void intro()

{

clrscr();

gotoxy(35,11);

cout<<"LIBRARY";

gotoxy(35,14);

cout<<"MANAGEMENT";

gotoxy(35,17);

cout<<"SYSTEM";

cout<<" MADE BY : YOUR NAME";

cout<<" SCHOOL : SCHOOL NAME";

getch();

}

//***************************************************************

// ADMINISTRATOR MENU FUNCTION

//****************************************************************

void admin_menu()

{

clrscr();

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: clrscr();

write_student();break;

case 2: display_alls();break;

case 3:

char num[6];

clrscr();

cout<<" Please Enter The Admission No. ";

cin>>num;

display_sps(num);

break;

case 4: modify_student();break;

case 5: delete_student();break;

case 6: clrscr();

write_book();break;

case 7: display_allb();break;

case 8: {

char num[6];

clrscr();

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

//****************************************************************

void main()

{

char ch;

intro();

do

{

clrscr();

cout<<" MAIN MENU";

cout<<" 01. BOOK ISSUE";

cout<<" 02. BOOK DEPOSIT";

cout<<" 03. ADMINISTRATOR MENU";

cout<<" 04. EXIT";

cout<<" Please Select Your Option (1-4) ";

ch=getche();

switch(ch)

{

case '1':clrscr();

book_issue();

break;

case '2':book_deposit();

break;

case '3':admin_menu();

break;

case '4':exit(0);

default :cout<<"";

}

}while(ch!='4');

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote