// File:     MNGLIBRARY.H - This is the header file of MNGLIBRARY.CPP
// Purpose:  Class hierarchy - for manageability.

// Global Constants and Typedef's
const int MAXSTRING = 50;
const int LINESIZE  = 80;
typedef char string[MAXSTRING];

class LoanableItems {
  protected:
	  // data members
	  string acquisitionNum;
	  string availForLoan;
	  string dateIssued;
	  string dateDueback;
	  string membershipNum;

  public:
	  // member functions ...
	  // constructor - destructor
	  LoanableItems();
	  virtual ~LoanableItems();

	  // display
	  virtual void display();

	  // access
	  char *getAcqNum();
	  char *getAvailForLoan();

	  // modify
	  void setAcqNum(string);
	  virtual void readIn() {};             // not implemented at this level
	  void borrowRecord();
	  void returnRecord();
	  void setLoanable();        

	  // file in / file out
	  virtual void fileIn(ifstream&);
	  virtual void fileOut(ofstream&);
}; // end LoanableItems class

class Books : public LoanableItems {
  private:
	  // data members ...
	  string title;
	  string ISBN;
	  string author;
	  string binding;

  public:
	  // member functions ...
	  // display
	  virtual void display();

	  // modify
	  virtual void readIn();

	  // file in / file out
	  virtual void fileIn(ifstream&);
	  virtual void fileOut(ofstream&);
}; // end Books class

class Newspaper : public LoanableItems {
  private:
	  // data members ...
	  string title;
	  string dataOfPub;

  public:
	  // member functions ...
	  // display
	  virtual void display();

	  // modify
	  virtual void readIn();

	  // file in / file out
	  virtual void fileIn(ifstream&);
	  virtual void fileOut(ofstream&);
};  // end Newspaper class

class Journals : public LoanableItems {
  private:
	  // data members ...
	  string title;
	  string dataOfPub;
	  string volumeNum;
	  string issueNum;

  public:
	  // member functions ...
	  // display
	  virtual void display();

	  // modify
	  virtual void readIn();

	  // file in / file out
	  virtual void fileIn(ifstream&);
	  virtual void fileOut(ofstream&);
}; // end Journals class

class VideoCassettes : public LoanableItems {
  private:
	  // data members ...
	  string title;
	  string author_director;
	  string duration;

  public:
	  // member functions ...
	  // display
	  virtual void display();

	  // modify
	  virtual void readIn();

	  // file in / file out
	  virtual void fileIn(ifstream&);
	  virtual void fileOut(ofstream&);
}; // end VideoCassettes class

class AudioCassettes : public LoanableItems {
  private:
	  // data members ...
	  string title;
	  string author_director;
	  string duration;

  public:
	  // member functions ...
	  // display
	  virtual void display();

	  // modify
	  virtual void readIn();

	  // file in / file out
	  virtual void fileIn(ifstream&);
	  virtual void fileOut(ofstream&);
}; // end AudioCassettes class

class FloppyDisks : public LoanableItems {
  private:
	  // data members ...
	  string title;
	  string format;

  public:
	  // member functions ...
	  // display
	  virtual void display();

	  // modify
	  virtual void readIn();

	  // file in / file out
	  virtual void fileIn(ifstream&);
	  virtual void fileOut(ofstream&);
}; // end FloppyDisks class

class CDROMs : public LoanableItems {
  private:
	  // data members ...
	  string title;

  public:
	  // member functions ...
	  // display
	  virtual void display();

	  // modify
	  virtual void readIn();

	  // file in / file out
	  virtual void fileIn(ifstream&);
	  virtual void fileOut(ofstream&);
}; // end CDROMs class

// File:     MNGLIBRARY.CPP - This is the C file of MNGLIBRARY.H
// Purpose:  Class hierarchy - for manageability.

#include iostream.h
#include fstream.h
#include string.h
#include time.h
#include "mnglibrary.h"

// Constructor:		LoanableItems::LoanableItems()
// Purpose:			Creates a new LoanableItems object
LoanableItems::LoanableItems() {
	strcpy(dateIssued, "in library");
	strcpy(dateDueback, "in library");
	strcpy(membershipNum, "none");
}; // end LoanableItems::LoanableItems()

// Destructor:	LoanableItems::~LoanableItems()
// Purpose:		Destroys a LoanableItems object
LoanableItems::~LoanableItems() {
	; // Destructor ~LoanableItems() called automatically
}; // end Destructor::~LoanableItems()

// Function:	LoanableItems::display()
// Purpose:		to display the information of the loanableItem
void LoanableItems::display() {
	if(!(strcmp(availForLoan, "yes"))) {
		cout << "\nThe following is the state of the item:\n\n" ; 
       cout << "The data of issued : " << dateIssued << endl; 
       cout << "The data of due back : " << dateDueback << endl; 
       cout << "The person loaning membership: " << membershipNum << endl; 
    } else { 
       cout << "\nThis item is not available for loan!" << endl; 
    } 
}; // end LoanableItems::display() 

// Function: LoanableItems::getAcqNum() 
// Purpose: to get the acquisition number 
char *LoanableItems::getAcqNum() { 
  return acquisitionNum; 
}; // end LoanableItems::getAcqNum() 

// Function: LoanableItems::getAvailForLoan() 
// Purpose: to get the loanable rights 
char *LoanableItems::getAvailForLoan() { 
  return availForLoan; 
}; // end LoanableItems::setAcqNum() 

// Function: LoanableItems::setAcqNum() 
// Purpose: to set the acquisition number value 
void LoanableItems::setAcqNum(string aNum) { 
  strcpy(acquisitionNum, aNum); 
}; // end LoanableItems::setAcqNum() 

// Function: LoanableItems::borrowRecord() 
// Purpose: to record the current date of issued, the date of due back and 
// membership number of person loaning when the item is issued. 
void LoanableItems::borrowRecord() { 
  char tmpbuf[28]; 
  _strdate( tmpbuf ); 
  strcpy(dateIssued, tmpbuf); // get the current date 
  cout << "Please input the date due back: " ; 
  cin.getline(dateDueback, MAXSTRING);  
  cout << "Please input membership number of person loaning: "; 
  cin.getline(membershipNum, MAXSTRING); 
}; // end LoanableItems::borrowRecord() 

// Function: LoanableItems::returnRecord() 
// Purpose: to reset the date of issued, the date of due back and 
// membership number of person loaning when the item is return. 
void LoanableItems::returnRecord() { 
  strcpy(dateIssued, "in library"); 
  strcpy(dateDueback, "in library"); 
  strcpy(membershipNum, "none"); 
}; // end LoanableItems::returnRecord() 

// Function: LoanableItems::setLoanable() 
// Purpose: to set the loanable rights of the item in the library 
// Pre: availForLoan="uncertain" 
// Post: availForLoan="either" "yes" or "no" 
void LoanableItems::setLoanable() { 
  char ch; 
  do { cout<<"Please input the loanable select (1 loanable, 2 nonloanable):"; 
  cin>> ch;
		switch(ch) {
		case '1':
			strcpy(availForLoan, "yes");
            break;
		case '2':
			strcpy(availForLoan, "no");
            break;
		}
	} while ((ch!='1') && (ch!='2'));
}; // end LoanableItems::setLoanable()

// Function:	LoanableItems::fileIn()
// Purpose:		to build the receiver using the data stored in the file
void LoanableItems::fileIn(ifstream& infile) {
	infile.getline(availForLoan, MAXSTRING);
	infile.getline(dateIssued, MAXSTRING);
	infile.getline(dateDueback, MAXSTRING);
	infile.getline(membershipNum, MAXSTRING);
}; // end LoanableItems::fileIn()

// Function:	LoanableItems::fileOut()
// Purpose:		to write out a data of the book to the file
void LoanableItems::fileOut(ofstream& outfile) {
   outfile << availForLoan << endl; 
   outfile << dateIssued << endl; 
   outfile << dateDueback << endl; 
   outfile << membershipNum << endl; 
}; // end LoanableItems::fileOut() 

// Function: Books::display() 
// Purpose: to display the information of the book in the library 
void Books::display() { 
   cout << "\nThe following is the book's information:\n\n" ; 
   cout << "Acqisition number : " << acquisitionNum << endl; 
   cout << "Title : " << title << endl; 
   cout << "Author : " << author << endl; 
   cout << "ISBN : " << ISBN << endl; 
   cout << "Binding : " << binding << endl; 
   LoanableItems::display(); }; // end Books::display() 

// Function: Books::readIn() 
// Purpose: to prompt user for and get the data of the receiver 
void Books::readIn() {  
  char ch; cout << endl; 
  cin.get(); // no use of this 
  cout << "Enter the book's acquisition number:" << endl; 
  cin.getline(acquisitionNum, MAXSTRING); 
  cout << "Enter the book's title:" << endl; 
  cin.getline(title, MAXSTRING); 
  cout << "Enter the book's author:" << endl; 
  cin.getline(author, MAXSTRING); 
  cout << "Enter the book's ISBN:" << endl; 
  cin.getline(ISBN, MAXSTRING); 
  do { 
    cout<<"Enter the book's binding (1 hardback, 2 softback):"; 
    cin>> ch;
		switch(ch) {
		case '1':
			strcpy(binding,  "hardback");
            break;
		case '2':
			strcpy(binding,  "softback");
            break;
		}
	} while ((ch!='1') && (ch!='2'));
	LoanableItems::setLoanable();
} // end Books::readIn()

// Function:	Books::fileIn(string fileName)
// Purpose:		to build the receiver using the data stored in the file
void Books::fileIn(ifstream& infile) {
   	infile.getline(acquisitionNum, MAXSTRING);
   	infile.getline(title, MAXSTRING);
	infile.getline(author, MAXSTRING);
	infile.getline(ISBN, MAXSTRING);
	infile.getline(binding, MAXSTRING);
	LoanableItems::fileIn(infile);
}  // end Books::fileIn()

// Function:	Books::fileOut(ofstream& outfile)
// Purpose:		to write out a data of the book to the file
void Books::fileOut(ofstream& outfile) {
	outfile << acquisitionNum << endl; 
   outfile << title << endl; 
   outfile << author << endl; 
   outfile << ISBN << endl; 
   outfile << binding << endl; 
   LoanableItems::fileOut(outfile); 
} // end Books::fileOut() 

// Function: Newspaper::display() 
// Purpose: to display the information of the newspaper in the library 
void Newspaper::display() { 
  cout << "The following is the newspaper's information:\n\n" ; 
  cout << "Acquisition number : " << 
  acquisitionNum << endl; 
  cout << "Title : " << title << endl; 
  cout << "Data of Publication : " << 
  dataOfPub << endl; 
  LoanableItems::display(); }; // end Newspaper::display() 

// Function: Newspaper::readIn() 
// Purpose: to prompt user for and get the data of the receiver 
void Newspaper::readIn() { 
  cout << endl; 
  cin.get(); // no use of this 
  cout << "Enter the newspaper's acquisition number:" << endl; 
  cin.getline(acquisitionNum, MAXSTRING); 
  cout << "Enter the newspaper's title:" << endl; 
  cin.getline(title, MAXSTRING); 
  cout << "Enter the newspaper's data of publication:" << endl; 
  cin.getline(dataOfPub, MAXSTRING); 
  LoanableItems::setLoanable(); 
} // end Newspaper::readIn() 

// Function: Newspaper::fileIn(string fileName) 
// Purpose: to build the receiver using the data stored in the file 
void Newspaper::fileIn(ifstream& infile) { 
  infile.getline(acquisitionNum, MAXSTRING); 
  infile.getline(title, MAXSTRING); 
  infile.getline(dataOfPub, MAXSTRING); 
  LoanableItems::fileIn(infile); 
} // end Newspaper::fileIn() 

// Function: Newspaper::fileOut(ofstream& outfile) 
// Purpose: to write out a data of the newspaper to the file 
void Newspaper::fileOut(ofstream& outfile) { 
  outfile << 
  acquisitionNum << endl; 
  outfile << title << endl; 
  outfile << dataOfPub << endl; 
  LoanableItems::fileOut(outfile); 
} // end Newspaper::fileOut() 

// Function: Journals::display() 
// Purpose: to display the information of the journal in the library 
void Journals::display() { 
  cout << "The following is the journals's information:\n\n" ; 
  cout << "Acquisition number : " << acquisitionNum << endl; 
  cout << "Title : " << title << endl; 
  cout << "Data of Publication : " << dataOfPub << endl; 
  cout << "Volume Number : " << volumeNum << endl; 
  cout << "Issue Number : " << issueNum << endl; 
  LoanableItems::display(); 
}; // end Journals::display() 

// Function: Journals::readIn() 
// Purpose: to prompt user for and get the data of the receiver 
void Journals::readIn() { 
  cout << endl; cin.get(); // no use of this 
  cout << "Enter the journals's acquisition number:" << endl; 
  cin.getline(acquisitionNum, MAXSTRING); 
  cout << "Enter the journals's title:" << endl; 
  cin.getline(title, MAXSTRING); 
  cout << "Enter the journals's data of publication:" << endl; 
  cin.getline(dataOfPub, MAXSTRING); 
  cout << "Enter the journals's volume number:" << endl; 
  cin.getline(volumeNum, MAXSTRING); 
  cout << "Enter the journals's issue number:" << endl; 
  cin.getline(issueNum, MAXSTRING); 
  LoanableItems::setLoanable(); 
} // end Journals::readIn() 

// Function: Journals::fileIn(string fileName) 
// Purpose: to build the receiver using the data stored in the file 
void Journals::fileIn(ifstream& infile) { 
  infile.getline(acquisitionNum, MAXSTRING); 
  infile.getline(title, MAXSTRING); 
  infile.getline(dataOfPub, MAXSTRING); 
  infile.getline(volumeNum, MAXSTRING); 
  infile.getline(issueNum, MAXSTRING); 
  LoanableItems::fileIn(infile); 
} // end Journals::fileIn() 

// Function: Journals::fileOut(ofstream& outfile) 
// Purpose: to write out a data of the journal to the file 
void Journals::fileOut(ofstream& outfile) { 
  outfile << acquisitionNum << endl; 
  outfile << title << endl; 
  outfile << dataOfPub << endl; 
  outfile << volumeNum << endl; 
  outfile << issueNum << endl; 
  LoanableItems::fileOut(outfile); 
} // end Journals::fileOut() 

// Function: VideoCassettes::display() 
// Purpose: to display the information of the videoCassette in the library 
void VideoCassettes::display() { 
  cout << "The following is the video cassettes's information:\n\n" ; 
  cout << "Acquisition number : " << 
  acquisitionNum << endl; 
  cout << "Title : " << title << endl; 
  cout << "Author/Director : " << 
  author_director<< endl; 
  cout << "Duration : " << duration << endl; 
  LoanableItems::display(); 
}; // end VideoCassettes::display()  

// Function: VideoCassettes::readIn() 
// Purpose: to prompt user for and get the data of the receiver 
void VideoCassettes::readIn() { 
  cout << endl; 
  cin.get(); // no use of this 
  cout << "Enter the video cassettes's acquisition number:" << endl; 
  cin.getline(acquisitionNum, MAXSTRING); 
  cout << "Enter the video cassettes's title:" << endl; 
  cin.getline(title, MAXSTRING); 
  cout << "Enter the video cassettes's author/director:" << endl; 
  cin.getline(author_director, MAXSTRING); 
  cout << "Enter the video cassettes's duration:" << endl; 
  cin.getline(duration, MAXSTRING); LoanableItems::setLoanable(); 
} // end VideoCassettes::readIn() 

// Function: VideoCassettes::fileIn(string fileName) 
// Purpose: to build the receiver using the data stored in the file 
void VideoCassettes::fileIn(ifstream& infile) { 
  infile.getline(acquisitionNum, MAXSTRING); 
  infile.getline(title, MAXSTRING); 
  infile.getline(author_director, MAXSTRING); 
  infile.getline(duration, MAXSTRING); 
  LoanableItems::fileIn(infile); 
} // end VideoCassettes::fileIn() 

// Function: VideoCassettes::fileOut(ofstream& outfile) 
// Purpose: to write out a data of the videoCassette to the file 
void VideoCassettes::fileOut(ofstream& outfile) { 
  outfile << 
  acquisitionNum << endl; 
  outfile << title << endl; 
  outfile << author_director<< endl; 
  outfile << duration << endl; 
  LoanableItems::fileOut(outfile); 
} // end VideoCassettes::fileOut() 

// Function: AudioCassettes::display() 
// Purpose: to display the information of the audioCassette in the library 
void AudioCassettes::display() { 
  cout << "The following is the audio cassettes's information:\n\n" ; 
  cout << "Acquisition number : " << 
  acquisitionNum << endl; 
  cout << "Title : " << title << endl; 
  cout << "Author/Director : " << author_director<< endl; 
  cout << "Duration : " << duration << endl; 
  LoanableItems::display(); 
}; // end AudioCassettes::display() 

// Function: AudioCassettes::readIn() 
// Purpose: to prompt user for and get the data of the receiver 
void AudioCassettes::readIn() { 
  cout << endl; 
  cin.get(); // no use of this 
  cout << "Enter the audio cassettes's acquisition number:" << endl; 
  cin.getline(acquisitionNum, MAXSTRING); 
  cout << "Enter the audio cassettes's title:" << endl; 
  cin.getline(title, MAXSTRING); 
  cout << "Enter the audio cassettes's author/director:" << endl; 
  cin.getline(author_director, MAXSTRING); 
  cout << "Enter the audio cassettes's duration:" << endl; 
  cin.getline(duration, MAXSTRING); 
  LoanableItems::setLoanable(); 
} // end AudioCassettes::readIn() 

// Function: AudioCassettes::fileIn(string fileName) 
// Purpose: to build the receiver using the data stored in the file 
void AudioCassettes::fileIn(ifstream& infile) { 
  infile.getline(acquisitionNum, MAXSTRING); 
  infile.getline(title, MAXSTRING); 
  infile.getline(author_director, MAXSTRING); 
  infile.getline(duration, MAXSTRING); 
  LoanableItems::fileIn(infile); 
} // end AudioCassettes::fileIn() 

// Function: AudioCassettes::fileOut(ofstream& outfile) 
// Purpose: to write out a data of the AudioCassettes to the file 
void AudioCassettes::fileOut(ofstream& outfile) { 
  outfile << acquisitionNum << endl; 
  outfile << title << endl; 
  outfile << author_director<< endl; 
  outfile << duration << endl; 
  LoanableItems::fileOut(outfile); 
} // end AudioCassettes::fileOut() 

// Function: FloppyDisks::display() 
// Purpose: to display the information of the floppyDisk in the library 
void FloppyDisks::display() { 
  cout << "The following is the floppy disks's information:\n\n" ; 
  cout << "Acquisition number : " << 
  acquisitionNum << endl; 
  cout << "Title : " << title << endl; 
  cout << "Format : " << format << endl; 
  LoanableItems::display(); 
}; // end FloppyDisks::display() 

// Function: FloppyDisks::readIn() 
// Purpose: to prompt user for and get the data of the receiver 
void FloppyDisks::readIn() { 
  char ch; 
  cout << endl; 
  cin.get(); // no use of this 
  cout << "Enter the floppy disks's acquisition number:" << endl; 
  cin.getline(acquisitionNum, MAXSTRING); 
  cout << "Enter the floppy disks's title:" << endl; 
  cin.getline(title, MAXSTRING); 
  do { 
    cout<<"Enter the floppy disks's format (1 PC, 2 Mac):"; 
    cin>> ch;
		switch(ch) {
		case '1':
			strcpy(format,  "PC");
            break;
		case '2':
			strcpy(format,  "Mac");
            break;
		}
	} while ((ch!='1') && (ch!='2'));
	LoanableItems::setLoanable();
} // end FloppyDisks::readIn()

// Function:	FloppyDisks::fileIn(string fileName)
// Purpose:		to build the receiver using the data stored in the file
void FloppyDisks::fileIn(ifstream& infile) {
   	infile.getline(acquisitionNum, MAXSTRING);
   	infile.getline(title, MAXSTRING);
	infile.getline(format, MAXSTRING);
	LoanableItems::fileIn(infile);
}  // end FloppyDisks::fileIn()

// Function:	FloppyDisks::fileOut(ofstream& outfile)
// Purpose:		to write out a data of the FloppyDisks to the file
void FloppyDisks::fileOut(ofstream& outfile) {
	outfile << acquisitionNum << endl; 
   outfile << title << endl; 
   outfile << format << endl; 
   LoanableItems::fileOut(outfile); 
} // end FloppyDisks::fileOut() 

// Function: CDROMs::display() 
// Purpose: to display the information of the CD-ROM in the library 
void CDROMs::display() { 
  cout << "The following is the CD ROMs's information:\n\n" ; 
  cout << "Acquisition number : " << acquisitionNum << endl; 
  cout << "Title : " << title << endl; 
  LoanableItems::display(); 
}; // end CDROMs::display() 

// Function: CDROMs::readIn() 
// Purpose: to prompt user for and get the data of the receiver 
void CDROMs::readIn() { 
  cout << endl; 
  cin.get(); // no use of this 
  cout << "Enter the CD ROMs's acquisition number:" << endl; 
  cin.getline(acquisitionNum, MAXSTRING); 
  cout << "Enter the CD ROMs's title:" << endl; 
  cin.getline(title, MAXSTRING); LoanableItems::setLoanable(); 
} // end CDROMs::readIn() 

// Function: CDROMs::fileIn(string fileName) 
// Purpose: to build the receiver using the data stored in the file 
void CDROMs::fileIn(ifstream& infile) { 
  infile.getline(acquisitionNum, MAXSTRING); 
  infile.getline(title, MAXSTRING); 
   LoanableItems::fileIn(infile); 
} // end CDROMs::fileIn() 

// Function: CDROMs::fileOut(ofstream& outfile) 
// Purpose: to write out a data of the CD-ROM to the file 
void CDROMs::fileOut(ofstream& outfile) { 
  outfile << acquisitionNum << endl; 
  outfile << title << endl; 
  LoanableItems::fileOut(outfile); 
} // end CDROMs::fileOut() 

// Program name: MINIMLIBRARY 
// // Programmer: Li Yi and group members 
// Date: 8/5/1997 // // Purpose: 
// The program (for manageability) tries to illustrate one of OO technique 
// encapsulation. 
// // Overview 
// This program allows the user to add library item's data for a 
// library. It also allows the user to borrow or return or display 
// a library item. 
// // The program begins by presenting a main menu which you can select 
// one of operation you need. Then it will provide the submenu for 
// your selection. You finish you process by following the instructions 
// on each menu. 
// // Structure 
// The program is designed for class hierarchy 2 for manageability 
// // **Warning 
// The acquisition number should be unique in the library and the 
// program does no checks on the input acquisition number when you 
// add the item in the library. 

#include <iostream.h
#include <fstream.h
#include <string.h
#include <stdlib.h
#include "mnglibrary.h"

void main() {
	// data member ...
	char response ;

	// function prototypes ...
	char mainMenuGet();  // prompt the main menu and get the choice
	void borrowAnItem(); // borrow an item from stock
	void returnAnItem(); // return an item from stock
	void addAnItem();    // add an item to the stock
	void displayAnItem();// display an item on the screen

	// statements ...
	do {
		response = mainMenuGet();    // get the selection to menuChoice
		switch (response) {
			case '1':                // borrow an item
				borrowAnItem();
				break;
			case '2':                // return an item
				returnAnItem();
				break;
			case '3':                // add an item
				addAnItem();
        		break;
      	    case '4':                // display an item
        		displayAnItem();
        		break;
      	    case '5':                // exit
         	    break;
			default: 
              cout << "You must use 1,2,3,4,5!" << endl; 
       } 
    } while(response!="5" ); 
    }; // end main() 

// Function: mainMenuGet() 
// Purpose: Returns a main menu choice from user 
char mainMenuGet() { // local data ... 
  char response; // statements ... 
  system("cls"); 
  cout << endl; 
  cout << " Mini Perry Library System" << endl; 
  cout << "----------------------------------------------------" << endl; 
  cout << " You can use this system to borrow an item from" << endl; 
  cout << "library, and add an item to the libraries stock, and" << endl; 
  cout << " display an item, and return an item." << endl; 
  cout << endl; 
  cout << " 1. Borrow" << endl; 
  cout << " 2. Return" << endl; 
  cout << " 3. Add" << endl; 
  cout << " 4. Display" << endl; 
  cout << " 5. Exit" << endl; 
  cout << endl; 
  cout << "Please input your choice number(1,2,3,4,5): "; 
  cin>> response ;
	return response;
}  // end mainMenuGet()

// Function:    borrowAnItem()
// Purpose:     borrow an item from the stock
void borrowAnItem() {
	// local data ...
	int number;
	char choice;
	string aqustnNum, tmpfile="tmp.lib",filename;
	LoanableItems *anItemPtr ;
	
	// function prototype ...
	char promptMenu();  	// prompt each item in the library and get the choice
	LoanableItems *choseAnObj(char, char *); // get an item object and filename
	
	// statements ...
	while(1) {
		// prompt a borrow menu ...
		system("cls");
		cout << endl; 
       cout << "Borrow" << endl; 
       cout << "----------------------------------------------------" << endl; 
       cout << " You can borrow the following item from" << endl; 
       cout << " library, or <b to back the main menu." 			<< endl; 
       // get which item to be borrowed 
       choice="promptMenu();" // not correct select should be exit 
       if (!((choice="='1')||(choice=='2')||(choice=='3')||
           (choice=='6')" ||(choice="='4')||(choice=='5')||(choice=='6')||(choice=='7')))" 
          break; // get the item's acquisition number 
          cout << "Please input the aquisition number: " << endl; 
          cin.get(); cin.getline(aqustnNum, MAXSTRING); // get an item object and the stock filename 
          anItemPtr="choseAnObj(choice,filename);" 
          // open the item object store file for search and a temp file for modify 
          ifstream infile; 
          ofstream outfile; 
          infile.open(filename, ios::in); 
          outfile.open(tmpfile, ios::out); 
          // search the return item in the stock, if find, then change item data... 
          number="0;" // get item's number in the stock 
          while(1) { 
            anItemPtr> 
            fileIn(infile);
			if (strcmp(anItemPtr -> getAcqNum(),"")) {          // if not empty...
				if (strcmp(anItemPtr -> getAcqNum(),aqustnNum)) // if not needed,
					anItemPtr -> fileOut(outfile);              // store the tmp.
				else {                                          // if neede...
					if (!(strcmp(anItemPtr -> getAvailForLoan(),"no")))// nonloanable,
						break;                                  // exit search.
					else {										// loanable item,
						anItemPtr -> borrowRecord();            // record the date.
						anItemPtr -> fileOut(outfile);
						number++;
					}
				}
			}
			else                                                // if empty
				break;                                          // then finish
		}
		infile.close() ;
		outfile.close();
		
		// if the item is not loanable...
		if (number==0) {
			cout << endl; 
          cout << "Sorry! You can not borrow this from library." <<endl; 
          cout << "Please enter to continue: "; // just pause 
          cin.ignore(LINESIZE, '\n'); 
          continue; 
       }; // if find the return item in the stock, then update the stock. 
       infile.open(tmpfile, ios::in); 
       outfile.open(filename, ios::out); 
       do { 
          anItemPtr> fileIn(infile);
			if (strcmp(anItemPtr -> getAcqNum(),""))
				anItemPtr -> fileOut(outfile);
		} while (strcmp(anItemPtr -> getAcqNum(),""));
		infile.close() ;
		outfile.close();
	}
}	//	end borrowAnItem()

// Function:	returnAnItem()
// Purpose:		return an item to the stock
void returnAnItem() {
	// local data ...
	int number;
	char choice;
	string aqustnNum, tmpfile="tmp.lib", filename;
	LoanableItems *anItemPtr ;
	
	// function prototype ...
	char promptMenu();  	// prompt each item in the library and get the choice
	LoanableItems *choseAnObj(char, char *); // get an item object
	
	// statements ...
	while(1) {
		// prompt a return menu ...
		system("cls");
		cout << endl; 
       cout << "Return" << endl; 
       cout << "----------------------------------------------------" << endl; 
       cout << " You can return the following item to" << endl; 
       cout << "library, or any other key to back the main menu." << endl; 
       // get which item to be borrowed 
       choice="promptMenu();" 
       if (!((choice="='1')||(choice=='2')||(choice=='3')||
          (choice=='6')" ||(choice="='4')||(choice=='5')||(choice=='6')||(choice=='7')))" 
          break; // not correct select should be exit 
          // get an item object and the stock filename 
          anItemPtr="choseAnObj(choice,filename);" // get the item's acquisition number 
          cout << "Please input the aquisition number: " << endl; 
          cin.get(); 
          cin.getline(aqustnNum, MAXSTRING); 
          // open the item object store file for search and a temp file for modify 
          ifstream infile; 
          ofstream outfile; 
          infile.open(filename, ios::in); 
          outfile.open(tmpfile, ios::out); 
          // search the return item in the stock, if find, then change item data... 
          number="0;" // get item's number in the stock 
          while(1) { 
            anItemPtr> 
            fileIn(infile);
			if (strcmp(anItemPtr -> getAcqNum(),"")) {          // if not empty...
				if (strcmp(anItemPtr -> getAcqNum(),aqustnNum)) // if not needed..
					anItemPtr -> fileOut(outfile);              // store the tmp.
				else {                                          // if needed...
					anItemPtr -> returnRecord();        		// change the date
					anItemPtr -> fileOut(outfile);              // store the tmp.
					number++;
				}
			}
			else                                                // if empty
				break;                                          // then finish
		}                                                       // searching.
		infile.close() ;                                        // close the file.
		outfile.close();
		
		// if can not find the return item in the stock...
		if (number==0) {
			cout << endl; 
          cout << "Sorry! There is no this item in library." <<endl; 
          cout << "Please enter to continue: "; // just pause 
          cin.ignore(LINESIZE, '\n'); 
          continue; 
       }; // if find the return item in the stock, then update the stock. 
       infile.open(tmpfile, ios::in); 
       outfile.open(filename, ios::out); 
       while(1) { 
           anItemPtr> 
           fileIn(infile);
			if (strcmp(anItemPtr -> getAcqNum(),""))
				anItemPtr -> fileOut(outfile);
			else
				break;
		}
		infile.close() ;
		outfile.close();
	}
}	// end returnAnItem()

// Function:    addAnItem()
// Purpose:		add an item to the stock
void addAnItem() {
	// local data ...
	char choice;
	string filename;
	LoanableItems *anItemPtr ;

	// function prototype ...
	char promptMenu();  // prompt each item in the library
	LoanableItems *choseAnObj(char, char *); // get an item object

	// statements ...
	while(1) {
		// prompt the add an item menu and get the choice
		system("cls");
		cout << endl; 
       cout << "Add" << endl; 
       cout << "----------------------------------------------------" << endl; 
       cout << " You can add the following item to library," << endl; 
       cout << " or any other key to back the main menu." << endl; 
       choice="promptMenu();" // not correct select should be exit 
       if (!((choice="='1')||(choice=='2')||(choice=='3')||
            (choice=='6')" ||(choice="='4')||(choice=='5')||(choice=='6')||(choice=='7')))" 
         break; // get an item object 
       anItemPtr="choseAnObj(choice,filename);" 
       // input the reference data and set the loanable anItemPtr> 
       readIn();

		// store the item to the file
		ofstream outfile;
		outfile.open(filename, ios::out | ios::app);
		anItemPtr -> fileOut(outfile);
		outfile.close();
	}
}  // end addAnItem()

// Function:   displayAnItem()
// Purpose:    display an item on the screen
void displayAnItem() {
	// local data ...
	char choice;
	string aqustnNum, filename;
	LoanableItems *anItemPtr ;

	// function prototype ...
	char promptMenu();  	// prompt each item in the library and get the choice
	LoanableItems *choseAnObj(char, char *); // get an item object

	// statements ...
	while(1) {
		// prompt the add an item menu and get the choice
		system("cls");
		cout << endl; 
       cout << "Display" << endl; 
       cout << "----------------------------------------------------" << endl; 
       cout << " You can display the following item from" << endl; 
       cout << "library, or any other key to back the main menu." << endl; 
       choice="promptMenu();" // not correct select should be exit 
       if (!((choice="='1')||(choice=='2')||(choice=='3')||(choice=='6')" ||
            (choice="='4')||(choice=='5')||(choice=='6')||(choice=='7')))" 
          break; // get the item's acquisition number 
          cout << "Please input the aquisition number: " << endl; 
          cin.get(); 
          cin.getline(aqustnNum, MAXSTRING); // get an item object 
          anItemPtr="choseAnObj(choice,filename);" // open the store file and search 
          ifstream infile; 
          infile.open(filename, ios::in); 
          while(1) { 
            anItemPtr> 
            fileIn(infile);
			if (!(strcmp(anItemPtr -> getAcqNum(),aqustnNum)))
			{                                           // if find then
				system("cls");
     			anItemPtr -> display();       			// display the item.
				break;									// exit search.
			}
			if (!(strcmp(anItemPtr -> getAcqNum(),""))) // if not find
			{                                           // exit search
				cout << "Sorry! There is no this item in library."<<endl; 
              break; 
           } 
       } 
       infile.close() ; // just pause 
       cout << endl; 
       cout << "Please enter to continue: "; 
       cin.ignore(LINESIZE, '\n'); } } // end displayAnItem() 

// Function: promptMenu() 
// Purpose: prompt the item menu and get the choice 
char promptMenu() { 
    char ch; // statements ... 
    cout << endl; cout << " 1. Books" << endl; 
    cout << " 2. Newspaper" << endl; 
    cout << " 3. Journals" << endl; 
    cout << " 4. Video Cassettes" << endl; 
    cout << " 5. Audio Cassettes" << endl; 
    cout << " 6. Floppy Disks" << endl; 
    cout << " 7. CD ROMs" << endl; cout << endl; 
    cout << "Please input the item number (1,2,3,4,5,6,7): "; cin>> ch;
	return ch;
}  // end promptMenu()

// Function:    choseAnObj(char menuChoice, char *filename)
// Purpose:		return an point to the object and a filename
LoanableItems *choseAnObj(char menuChoice, char *filename) {
	LoanableItems *anItemPtr ;
	switch (menuChoice) {
	case '1' :
		anItemPtr = new Books;
		strcpy(filename, "books.lib");
		break;
	case '2' :
       	anItemPtr = new Newspaper;
		strcpy(filename, "newspaper.lib");
		break;
	case '3' :
       	anItemPtr = new Journals;
		strcpy(filename, "journals.lib");
		break;
	case '4' :
       	anItemPtr = new VideoCassettes;
		strcpy(filename, "videocassettes.lib");
		break;
	case '5' :
       	anItemPtr = new AudioCassettes;
		strcpy(filename, "audiocassettes.lib");
		break;
	case '6' :
       	anItemPtr = new FloppyDisks;
		strcpy(filename, "floppydisks.lib");
		break;
	case '7' :
		anItemPtr = new CDROMs;
		strcpy(filename, "cdroms.lib");
		break;
	}
	return anItemPtr;
}  // end choseAnObj(char menuChoice, char *filename)