#include<fstream.h>
#include<iomanip.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<iomanip.h>
//-----------------------------------------------------------------\par
\par
\par
class inventory\par
\{\par
\tab char name[25];\par
\tab int code,copy;\par
\tab float cost;\par
\tab char stock[3];\par
\tab char datestr[9];\par
\tab char timestr[9];\par
\par
\tab public:\par
\tab\tab void rdata(void);\par
\tab\tab void wdata(void);\par
\tab\tab void menu(void);\par
\tab\tab void display(void);\par
\tab\tab void mainpage(void);\par
\tab\tab void check(void);\par
\tab\tab void purchase(void);\par
\tab\tab void tranrdata(void);\par
\tab\tab void tranwdata(void);\par
\tab\tab void displaytran(void);\par
\tab\tab void date(void);\par
\};\par
//-----------------------------------------------------------------\par
\par
\par
void inventory::rdata(void)\par
\{\par
\tab cout<<"\\n\\n\\t ENTER THE DETAILS OF THE BOOK :";\par
\par
\tab cout<<"\\n\\n\\t ENTER THE BOOK NAME ::";cin>>name;\par
\par
\tab cout<<"\\n\\n\\t ENTER THE CODE OF THAT BOOK ::";cin>>code;\par
\par
\tab cout<<"\\n\\n\\t ENTER THE COST OF THE BOOK ::";cin>>cost;\par
\par
\tab cout<<"\\n\\n\\t ENTER THE STOCK OF THE BOOK ::";cin>>stock;\par
\tab\par
\tab cout<<"\\n\\n\\t ENTER THE NO. OF COPIES ::";cin>>copy;\par
\par
\par
\}\par
//------------------------------------------------------------------\par
void inventory::tranrdata(void)\par
\{\par
\tab cout<<"\\n\\n\\t ENTER THE DETAILS OF THE BOOK ::";\par
\par
\tab cout<<"\\n\\n\\t ENTER THE BOOK NAME ::";cin>>name;\par
\par
\tab cout<<"\\n\\n\\t ENTER THE COST OF THE BOOK ::";cin>>cost;\par
\par
\tab cout<<"\\n\\n\\t ENTER THE NO. OF COPIES ::";cin>>copy;\par
\}\par
//------------------------------------------------------------------\par
void inventory::date (void)\par
\{\par
\par
\par
\tab _strdate(datestr);\par
\tab cout<<"\\n\\n\\t Date ::\\t"<<datestr;\par
\tab _strtime( timestr );\par
\tab cout<<"\\t\\tTime ::\\t"<<timestr;\par
\par
\par
\}\par
\par
\par
//------------------------------------------------------------------\par
void inventory::wdata(void)\par
\{ \par
\tab cout<<setw(10)<<name<<"\\t\\t"<<code<<"\\t\\t"<<cost<<"\\t\\t"<<stock<<"\\t\\t"<<copy<<endl;\par
\}\par
//------------------------------------------------------------------\par
void inventory::tranwdata(void)\par
\{\par
\tab cout<<setw(10)<<name<<"\\t\\t"<<cost<<"\\t\\t"<<copy<<"\\t\\t"<<datastr<<endl;\par
\}\par
//------------------------------------------------------------------\par
void inventory::menu()\par
\{\par
\tab system("cls");\par
\tab date();\par
\tab cout<<"\\n\\n\\t------MENU-FILE HANDLING------";\par
\par
\tab cout<<"\\n\\n\\t (1) ADD NEW RECORDS";\par
\par
\tab cout<<"\\n\\n\\t (2) DISPLAY RECORDS";\par
\par
\tab cout<<"\\n\\n\\t (3) MODIFY RECORDS";\par
\par
\tab cout<<"\\n\\n\\t (4) PURCHASE";\par
\par
\tab cout<<"\\n\\n\\t (5) TRANSACTION ENTRY";\par
\par
\tab cout<<"\\n\\n\\t (6) TRANSACTION DETAILS";\par
\par
\tab cout<<"\\n\\n\\t (7) EXIT";\par
\par
\}\par
\par
\par
//--------------------------------------------------------------------\par
void inventory::display()\par
\par
\{\par
\par
\tab cout<<"\\n\\n--------------------------------------------------------------------";\par
\par
\par
\tab cout<<"\\n\\nBOOK NAME CODE COST STOCK NO. OF COPY ";\par
\par
\par
\tab cout<<"\\n\\n---------------------------------------------------------------------";\par
\par
\par
\tab cout<<"\\n\\n";\par
\}\par
//---------------------------------------------------------------------\par
void inventory::displaytran()\par
\par
\par
\{\par
\par
\par
\tab cout<<\\n\\n----------------------------------------------------------------------";\par
\par
\par
\tab cout<<\\n\\n BOOK NAME COST NO. OF COPY DATE ";\par
\par
\par
cout<<\\n\\n----------------------------------------------------------------------";\par
\par
\par
\tab cout<<"\\n\\n";\par
\}\par
//----------------------------------------------------------------------\par
void inventory::mainpage()\par
\{\par
\par
\tab char name1[10],password[10];\par
\tab system("cls");\par
\tab cout<<"\\n\\n\\n\\n\\t";\par
\tab cout<<"\\n\\n\\t\\t\\t\\3\\3\\5\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3";\par
cout<<"\\n\\t\\t\\t\\3\\t\\t\\t\\t\\t\\3";\par
\tab cout<<"\\n\\t\\t\\t\\3\\tWELCOME TO OUR BOOK SHOP\\t\\3";\par
\tab cout<<"\\n\\t\\t\\t\\3\\t\\t\\t\\t\\t\\3";\par
\tab cout<<"\\n\\t\\t\\t\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3\\3";\par
\tab cout<<"\\n\\n\\n\\t\\t\\tEnter your name here\\t:";\par
\tab cin>>name1;\par
\tab cout<<"\\n\\n\\n\\t\\t\\tEnter the password here\\t:";\par
\tab cin>>password;\par
\}\par
//-----------------------------------------------------------------------\par
\par
void inventory::check(void)\par
\par
\{\par
\par
\par
\par
\par
\tab int x;\par
\tab x=strcmp("yes",stock);\par
\tab if(x!=0)\par
\tab\tab cout<<"\\n\\n\\t The required book is not available";\par
\tab else\par
\tab\tab cout<<"\\n\\n\\t The required book is available";\par
\par
\par
\}\par
//------------------------------------------------------------------------\par
void inventory::purchase(void)\par
\{\par
\par
\tab int no;\par
\tab cout<<"\\n\\n\\tENTER THE NO OF COPIES YOU WANT\\t::";cin>>no;\par
\tab copy=copy-no;\par
\tab char st[3]="no";\par
\tab if (copy==0)\par
\tab\tab strcpy(stock,st);\par
\}\par
//------------------------------------------------------------------------\par
\par
\par
int main()\par
\{\par
\par
\tab inventory item;\par
\tab fstream item;\par
\tab fstream file1;\par
\tab int choice;\par
\tab char ans;\par
\tab char ch;\par
\tab item.mainpage();\par
\tab system("cls");\par
\par
\par
\tab while(1)\par
\par
\par
\tab\{\par
\tab\tab file.open("stock1.dat",ios::ate|ios::in|ios::out|ios::binary);\par
\par
\par
\tab\tab item.menu();\par
\tab\tab system("colour df");//purple\par
\tab\tab cout<<"\\n\\n\\t ENTER YOUR CHOICE (1-7)::";\par
\tab\tab cin>>choice;\par
\tab\tab switch(choice)\par
\tab\tab\{\par
\par
case1:\par
\par
\tab\tab\{\par
\par
\tab\tab\tab do\par
\par
\tab\tab\tab\{\par
\tab\tab\tab\tab item.rdata();\par
\tab\tab\tab\tab file.write((char*) & item,sizeof(item));\par
\tab\tab\tab\tab cout<<"\\n\\n\\t WANT TO ADD ANY MORE RECORDS(Y/N)::";\par
\tab\tab\tab\tab cin>>ans;\par
\tab\tab\tab\}while(ans=='Y'|| ans=='y');\par
\tab\tab\tab //find number of objects in a file\par
\tab\tab\tab int last=file1.tellg();\par
\tab\tab\tab int n=last/sizeof(item);\par
\tab\tab\tab cout<<"TOTAL NO. OF RECORDS::"<<n<<"\\n";\par
\tab\tab\tab cout<<"\\nCURRENT RECORD";\par
\tab\tab\tab item.display();\par
\tab\tab\tab file.read((char *) & item,sizeof(item));\par
\tab\tab\tab item.wdata();\par
\tab\tab\tab cout<<"\\n Press any key to see menu...\\n"<<flush;\par
\tab\tab\tab getch();\par
\tab\tab\tab break;\par
\tab\tab\}\par
\tab\tab case 2:\par
\tab\tab\tab\par
\tab\tab\tab\{\par
\tab\tab\tab\tab item.display();\par
\tab\tab\tab\tab file.seekg(0);\par
\tab\tab\tab\tab file.seekg(0,ios::beg);\par
\tab\tab\tab\tab while(file.read((char *) & item,sizeof(item)))\par
\tab\tab\tab\tab\{\par
\tab\tab\tab\tab\tab item.wdata();\par
\tab\tab\tab\tab\}\par
\tab\tab\tab\tab cout<<"\\n\\n----------------------------------------------------------------";\par
\tab\tab\tab\tab cout<<"\\n Press any key to see menu...\\n"<<flush;\par
\tab\tab\tab\tab getch();\par
\tab\tab\tab\tab break;\par
\tab\tab\tab\}\par
\tab\tab case 3:\par
\tab\tab\tab\par
\tab\tab\tab\{\par
\tab\tab\tab\tab system("color cf");//red\par
\tab\tab\tab\tab cout<<"enter object number to be updated\\n";\par
\tab\tab\tab\tab int object;\par
\tab\tab\tab\tab cin.get(ch);\par
\tab\tab\tab\tab int location=(object-1)*sizeof(item);\par
\tab\tab\tab\tab if(file.eof())filr.clear();\par
\tab\tab\tab\tab cout<<"enter the new of values of the object\\n";\par
\tab\tab\tab\tab item.rdata();\par
\tab\tab\tab\tab cin.get(ch);\par
\tab\tab\tab\tab file.write((char *) & item,sizeof(item));\par
\tab\tab\tab\tab cout<<"\\n Press any key to see menu...\\n"<<flush;\par
\tab\tab\tab\tab getch();\par
\tab\tab\tab\tab break;\par
\par
\tab\tab\tab\}\par
\tab\tab case 4:\par
\par
\tab\tab\tab\{\par
\tab\tab\tab\tab system("color 91");//blue\par
\tab\tab\tab\tab system("color 9f");//text color white\par
\tab\tab\tab\tab cout<<"\\n DO YOU WANT TO BUY BOOKS(Y/N)";\par
\tab\tab\tab\tab cin>>ans;\par
\tab\tab\tab\tab if (ans=='y')\par
\tab\tab\tab\tab\{\par
\tab\tab\tab\tab\tab cout<<"\\nENTER THE OBJECT NUMBER HERE";\par
\tab\tab\tab\tab\tab int object;\par
\tab\tab\tab\tab\tab cin>>object;\par
\tab\tab\tab\tab\tab cin.get(ch);\par
\tab\tab\tab\tab\tab int location=(object-1)*sizeo(item);\par
\tab\tab\tab\tab\tab if(file.eof())file.clear();\par
\tab\tab\tab\tab\tab file.seekp(location);\par
\tab\tab\tab\tab\tab file.read((char *) & item,sizeof(item));\par
\tab\tab\tab\tab\tab item.check();\par
\tab\tab\tab\tab\tab item.display();\par
\tab\tab\tab\tab\tab item.wdata();\par
\tab\tab\tab\tab\tab item.purchase();\par
\tab\tab\tab\tab\tab cout<<"\\n\\n----------------------------------------------------------";\par
\tab\tab\tab\tab\tab file.seekp(location);\par
\tab\tab\tab\tab\tab file.write((char *) & item,sizeof(item));\par
\tab\tab\tab file1.write((char *) & item,sizeof(item));\par
\tab\tab\tab\tab\tab cout<<"\\n Press any key to see menu...\\n"<<flush;\par
\tab\tab\tab\tab\tab getch();\par
\par
\par
\tab\tab\tab\tab\}\par
\tab\tab\tab\tab break;\par
\tab\tab\tab\}\par
\tab\tab case 5:\par
\par
\tab\tab\tab\{\par
\tab\tab\tab\tab do\par
\par
\tab\tab\tab\tab\{\par
\tab\tab\tab\tab\tab file1.open("transaction.dat",ios::ate|ios::in|ios::out|ios::binary);\par
\tab\tab\tab\tab\tab item.tranrdata();\par
\tab\tab\tab\tab\tab file1.write((char *) & item,sizeof(item));\par
\tab\tab\tab\tab\tab cout<<"\\n\\n\\tWANT TO ADD ANYMORE RECORDS(Y/N)::";\par
\tab\tab\tab\tab cin>>ans;\par
\tab\tab\tab\tab\}while(ans=='Y'|| ans=='y');\par
\tab\tab\tab\tab int last=file.tellg();\par
\tab\tab\tab\tab int n=last/sizeof(item);\par
\tab\tab\tab\tab cout<<"TOTAL NO. OF TRANSACTIONS::"<<n<<"\\n";\par
\tab\tab\tab\tab cout<<"\\n Press any key to see menu...\\n"<<flush;\par
\tab\tab\tab\tab getch();\par
\tab\tab\tab\tab file1.close();\par
\tab\tab\tab\tab break;\par
\tab\tab\tab\}\par
\tab\tab case 6:\par
\par
\tab\tab\tab\{\par
\tab\tab\tab\tab file1.open("transaction.dat",ios::ate|ios::in|ios::out|ios::binary);\par
\tab\tab\tab\tab item.displaytran();\par
\tab\tab\tab\tab file1.seekg(0);\par
\tab\tab\tab\tab file1.seekg(0,ios::beg);\par
\tab\tab\tab\tab while(file1.read((char *) & item,sizeof(item)))\par
\tab\tab\tab\tab\{\par
\tab\tab\tab\tab\tab item.tranwdata();\par
\tab\tab\tab\tab\}\par
\tab\tab\tab\tab cout<<"\\n\\n----------------------------------------------------------------------";\par
\tab\tab\tab\tab cout<<"\\n Press any key to see menu...\\n"<<flush;\par
\tab\tab\tab\tab getch();\par
\tab\tab\tab\tab file1.close();\par
\par
\tab\tab\tab\tab break;\par
\tab\tab\tab\}\par
\tab\tab case 7:\par
\par
\par
\tab\tab\tab cout<<"\\ndo you want to exit,press(y/n)";\par
\tab\tab\tab cin>>ans;\par
\tab\tab\tab if(ans=='y'||ans=='Y')\par
\tab\tab\tab\{\par
\par
\par
\tab\tab\tab\tab return 0;\par
\tab\tab\tab\}break;\par
\par
\par
\tab\tab default:cout<<"\\n\\t\\tError input,try again";\par
\tab\tab\tab\}\par
\par
\tab\tab\tab file close();\par
\tab\tab\tab\}\par
\tab\tab\tab\}\par
}

Wow that's cool, i'll take it, are u sure there is no error?..
Don't forget to use code tag..

Comments
lol good answer :)

That's cool..
Are u sure there is no error..
Cause i can't fix it..
Dont forget to use code tag..
Thanks..

This article has been dead for over six months. Start a new discussion instead.