DESCRIPTION: This is a lab about inheritance from an Intermediate C++ class. I w
ID: 3560119 • Letter: D
Question
DESCRIPTION: This is a lab about inheritance from an Intermediate C++ class. I will offer 6000 points for this assignment. Since chegg has a limit of 1500 points I will post 3 more pages with the same problem and will reward you after you reply to each one of them. I will provide the link to each of the pages after a response in the comments. I have posted the files onto google drive here:
https://drive.google.com/file/d/0BxIs5ORUcIhIV2YyTjJBMVdwNGs/edit?usp=sharing
If you wish to contact me, use my email : pmboyy@yahoo.com ---This is where you will be mailing the program.
I need this in 3 days so please send me an email if you have any questions.
Here are the instructions:
1. Break the BookData Class into Two Classes
Currently the BookData class contains all the data about a book in the store
Explanation / Answer
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<iomanip.h>
//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************
class book data
{
char Book Name[6];
char Isbn no.[50];
char Author Name[20];
char Publisher[50];
public:
void create_book()
{
cout<<" NEW BOOK ENTRY... ";
cout<<" Enter The Name of The Book ";
gets( Book Name);
cout<<" Enter The Isbn no.";
cin>> Isbn no;
cout<<" Enter The Author's Name ";
gets(Author Name);
cout<<" Enter The Publisher ";
gets( Publisher);
cout<<" Book Created..";
}
void show_book()
{
cout<<" Book Name : ";
puts(nBook Name );
cout<<" Enter The Isbn no.";
cin>> Isbn no;
cout<<"Author Name : ";
puts(Author Name );
}
char* retbno()
{
return bno;
}
void report()
{cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;}
}; //class ends here
class InventoryBook
{
char Date Added[6];
char Qty on Hand[20];
char Wholesale[6];
char retail[6];
public:
void create_inventory()
{
clrscr();
cout<<"Inventory Books Entry... ";
cout<<" Enter Date Added. ";
cin>>datadd;
cout<<" Enter The Qty";
cin>>qt;
cout<<" EnterWholesale. ";
cin>>whsl;
cout<<" Enter Retail. ";
void set_Empty()
{
cout<<" Book Isbn no. : "<<isbn;
cout<<" Book Name : ";
gets(bname);
cout<<" Author's Name of Book : ";
gets(Author name);
}
token=0;
stbno[0]='/0';
cout<<" is Empty..";
}
void Remove_book()
{
cout<<" Book Isbn no. : "<<isbn;
cout<<" Remove Book Name : ";
gets(bname);
cout<<" Remove Author's Name of Book : ";
gets(Author name);
}
token=0;
stbno[0]='/0';
cout<<" Books Has Removed..";
}
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;
//***************************************************************
// 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();
}
//***************************************************************
// 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();
}
//***************************************************************
// 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();
}
//***************************************************************
// function to delete record of file
//****************************************************************
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 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 sold book
//****************************************************************
void book_sold()
{
char sn[6],bn[6];
int found=0,flag=0;
clrscr();
cout<<" BOOK sold ...";
cout<<" Enter The BOOK ISBN no.";
cin>>sn;
fp.open("BOOK.dat",ios::in|ios::out);
fp1.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(BOOK)) && 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(BOOK));
cout<<" Book sold successfully Please Note: Write current date
in backside of book and submit within 15% sales tax of a book's price
}
}
if(flag==0)
cout<<"Book no does not exist";
}
else
cout<<"You have not purchased any Book";
}
}
if(found==0)
cout<<"Books record not exist...";
getch();
fp.close();
fp1.close();
}
//***************************************************************
// function to deposit book
//****************************************************************
void qty_sold()
{
char sn[6],bn[6];
int found=0,flag=0,day;
clrscr();
cout<<" BOOK SOLD ...";
cout<<" Enter The Book ISBN No.";
cin>>sn;
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 soldd in no. of days";
cin>>day;
if(day>15)
{
fine=(day-15)*1;
cout<<" Tax has to deposited Rs. "<<tax;
}
st.resettoken();
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(BOOks));
cout<<" entire sale successfully";
}
}
if(flag==0)
cout<<"Book no does not exist";
}
else
cout<<"No book isPurchased by you..please check!!";
}
}
}
//***************************************************************
// 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');
}
//Define some mutators...
void SetFirst(string First) { FirstName = First; }
void SetLast(string Last) { LastName = Last; }
//...and some accessors...
string GetFirst() { return FirstName; }
string GetLast() { return LastName; }
};
ShortName::ShortName()
{
FirstName = "";
LastName = "";
}
ShortName::ShortName(string First, string Last)
{
FirstName = First;
LastName = Last;
}
//Define a list class...
class ShortNameList {
vector<ShortName> List; //Create a specific sized list...
public:
ShortNameList() {;} //Nothing for it to do at this point...
void AddRecord(string, string);
void ShowList();
};
void ShortNameList::AddRecord( string First, string Last)
{
ShortName NameBuffer;
NameBuffer.SetFirst(First);
NameBuffer.SetLast(Last);
List.push_back(NameBuffer);
}
void ShortNameList::ShowList()
{
int K;
for(K = 0 ; K < List.size() ; K++)
cout << List[K].GetFirst() << " " List[K].GetLast() << endl;
}
class ShortNameUI {
ShortNameList Collection;
public:
ShortNameUI() {;}
void Menu();
void AddNewRecord();
void RunIT();
};
//This gives us options...
void ShortNameUI::Menu()
{
cout << "Choices..." << endl;
cout << "====================================================================" << endl;
cout << "\tAdd.........allows the user to enter names." << endl;
cout << "\tDisplay......shows the names." << endl;
cout << "\tQuit.........terminates the program" << endl;
cout << "====================================================================" << endl;
}
void ShortNameUI::RunIT()
{
string Command;
while(true) {
Menu();
cout << "Command: ";
getline(cin, Command);
if(Command == "Quit")
break;
else if(Command == "Add")
AddNewRecord();
else if(Command == "Display")
Collection.ShowList();
}
}
void ShortNameUI::AddNewRecord()
{
string First, Last;
cout << "Enter Names Below, Stop To Quit" << endl;
while(true) {
cout << "First Name: ";
getline(cin, First);
if(First == "Stop")
break;
cout << "Last Name: ";
getline(cin, Last);
if(Last == "Stop")
break;
Collection.AddRecord(First, Last);
}
}
int main()
{
ShortNameUI NameList;
NameList.RunIT();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.