//****** General comments: // #Try to avoid the use of global variable (ch, var,var2) // #Use significient name. Not var1,var2. Something like objBook, objLibrairy. // #Separate you classes into different files. So book would be in a file called Book.h. To include it simply add #include "Book.h" // #Depending of the scope of the program, using an array of books would be usefull. However, if the user is only able to do 1 transaction at the time, // keep it as it is. // #I've change you main a bit so user can Exit. // #Don't forget to validate each entry when using char[x]. What happend if the user enter more than 50characters for the names? // #Why not using string instead of char*? #include #include #include #include using namespace std; int ch; void entry_book(); void issue_book(); void return_book(); void search(); void search_book(); char *tym(); class book { public: char b_name[50],b_pub[20],b_pur[12]; long int b_no; public: friend istream &operator >> (istream &in,book &temp); friend ostream &operator << (ostream &out,book &temp); friend ofstream &operator << (ofstream &bookout,book &temp); friend ifstream &operator >> (ifstream &bookin,book &temp); }var; class library:public book { public: char *i_dat,*r_dat,stud_name[20],clas[10]; long int b_no; public: friend ostream &operator<<(ostream &out,library & temp); friend ofstream &operator<<(ofstream &libout,library &temp); friend ifstream &operator>>(ifstream &libin,library &temp); }var2; char *tym() { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); return ( asctime (timeinfo) ); } void entry_book() { cout<<"\nEnter Book No:"; cin>>var.b_no; cout<<"\nEnter Book name:"; cin>>var.b_name; cout<<"\nPub Name:"; cin>>var.b_pub; cout<<"\nPurchase date:"; cin>>var.b_pur; ofstream book_file; book_file.open ("book.txt"); book_file<>temp_no; ifstream book_file2; ofstream lib_file; book_file2.open("book.txt"); book_file2>>var; while(!book_file2.eof()) { if(temp_no==var.b_no) { var2.i_dat=tym(); cout<<"\nEnter Student Name:"; cin>>var2.stud_name; cout<<"\nEnter Class:"; cin>>var2.clas; lib_file.open("library.txt"); lib_file<>var; } book_file2.close(); } //************ Use significient name, chr and chr1 doesn't mean anything to me... void return_book() { int temp_no,temp_ptr=0; char chr[10],chr1[10]; //string r_date; cout<<"\nEnter the Book Number:"; cin>>temp_no; ifstream lib_file2; ofstream lib_file3; lib_file2.open("library.txt"); lib_file2>>var2; lib_file2.seekg(0); while(!lib_file2.eof()) { if(temp_no==var2.b_no) { var2.r_dat=tym(); //temp_ptr=lib_file2.tellg(); lib_file2.get(chr[0]); while(strcmp(chr,"-")!=0) temp_ptr++; lib_file3.seekp(temp_ptr); lib_file3<<*var2.r_dat; temp_ptr+=2; lib_file3<<" R \n"; } } } //******I would suggest you to load all the books in an array when start the program. And then, make a new file at the end of the program. It will run faster. void search_book() { int temp_no; cout<<"\nEnter the Book Number:"; cin>>temp_no; ifstream book_file3; book_file3.open("book.txt"); book_file3>>var; while(!book_file3.eof()) { if(temp_no==var.b_no) { cout<<"\nBook No:"<>ch; switch(ch) { case 1: { entry_book(); break; } //Do this for the rest of your switch. case 2:issue_book(); case 3:return_book(); case 4:search_book(); case 0:break; //If you want your program to run until the user want to quit. default:cout<<"\n Wrong choice.only 1-4 is valid."; } }while(ch != 0) }