Beruflich Dokumente
Kultur Dokumente
DESCRIPTIONS
class eshop
The class contains data items; name of maximum 25 characters, icode, price and
disc of data types char, long int, float and float respectively. The object ob of the
class is used to write the information entered by the user into the binary file. The
class contains the functions getdata(), putdata( ), bdisplay( ), getname( ),
getcode( ) and getdisc( ). The function getdata( ) reads data from the user,
putdata( ) displays it and bdisplay( ) displays the record selected for billing.
getname( ), getcode( ) and getdisc( ) functions returns name, code and discount
respectively.
Binary file Eshop
The file is used to store the name, item-code, price and discount for each item.
The extension of the file is .dat. The data is stored as records using the concept
of class and are read from or written to the file according to need.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<fstream.h> // for file operations
#include<windows.h> // for using message box
#include<time.h> // for getting system time & date
class eshop
{
private:
/*
getting details of */
char name[25];
/*
different items */
~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n\t\t\t
ENTER DETAILS
";
cout<<"\n\t\t\t
``````````````````````````"<<endl;
cout<<"========================================";
cout<<"========================================";
gotoxy(0,5);
cout<<"\nEnter Item Name : ";
gets(name);
cout<<"\nEnter Item Code : ";
cin>>icode;
cout<<"\nEnter Price
: ";
cin>>price;
cout<<"\nEnter Discount
: ";
cin>>disc;
}
void putdata(int flag=0) // for displaying details
{
// according to value
if(flag==0)
// of flag
{
cout<<"\n\n "<<name;
gotoxy(30,wherey());
cout<<icode;
gotoxy(50,wherey());
cout<<"R.O. "<<price;
gotoxy(70,wherey());
cout<<disc<<"%";
}
if(flag==1)
{
cout<<"\n\n "<<name;
gotoxy(30,wherey());
cout<<icode;
gotoxy(50,wherey());
cout<<"R.O. "<<price;
gotoxy(70,wherey());
cout<<"R.O. "<<(price-((disc/100)*price));
}
}
double bdisplay() // for displaying bill
{
float nprice;
cout<<"\nItem Name
: "<<name;
if(disc>0.0)
{
nprice=price-((disc/100)*price);
cout<<"\nItem Price
: R.O. "<<nprice;
}
else
{
nprice=price;
cout<<"\nItem Price
: R.O. "<<nprice;
}
return(nprice);
}
char *getname()
{
return(name);
}
float getdisc()
{
return(disc);
}
long int getcode()
{
return(icode);
}
}ob;
{
MessageBox(0,"The File cannot be Created\t","ERROR!",0);
exit(0);
}
while(ch=='y'||ch=='Y')
{
ob.getdata();
fout.write((char *)&ob,sizeof(ob));
cout<<"\n\tDo You Want To Continue Entering Details? (Y/N) : ";
cin>>ch;
}
}
void modify() //modifying an items details
{
clrscr();
fstream finout;
long int pos; char ch='y',m_name[25],date[9],time[9];
cout<<"\nDate of Modification :: "<<_strdate(date);
cout<<"\nTime of Modification :: "<<_strtime(time);
finout.open("Eshop.dat",ios::in|ios::out|ios::binary);
if(!finout)
{
MessageBox(0,"The File doesn't exist","ERROR!",0);
exit(0);
}
while(ch=='y'||ch=='Y')
{
cout<<"\n\nENTER THE NAME OF THE ITEM TO BE MODIFIED : ";
gets(m_name);
pos=finout.tellg();
finout.read((char *)&ob,sizeof(ob));
while(finout)
{
if(strcmpi(ob.getname(),m_name)==0)
{
cout<<"\nEnter the NEW Details::\n";
ob.getdata();
finout.seekp(pos,ios::beg);
finout.write((char *)&ob,sizeof(ob));
}
pos=finout.tellg();
finout.read((char *)&ob,sizeof(ob));
}
cout<<"\nDo You Want to Continue Modifying Records? (Y/N): ";
cin>>ch;
}
finout.close();
}
exit(0);
}
gets(d_name);
fin.read((char *)&ob,sizeof(ob));
while(fin)
{
if(strcmpi(ob.getname(),d_name)==0)
{
cout<<"\n\tThe Record is Successfully Deleted..!";
found='y';
}
else
{
fout.write((char *)&ob,sizeof(ob));
}
fin.read((char *)&ob,sizeof(ob));
}
if(found=='n')
MessageBox(0,"Record Specified NOT Found","NOT FOUND",0);
fin.close(); fout.close();
remove("Eshop.dat");
rename("Temp.dat","Eshop.dat");
cout<<"\nDo You Want To Continue Deleting Records? (Y/N) : ";
cin>>ch;
}
}
void add() //adding a new item to file
{
clrscr();
fstream fout;
fout.open("Eshop.dat",ios::app|ios::binary);
char ch='y';
if(!fout)
{
MessageBox(0,"The File doesn't exist","ERROR!",0);
exit(0);
}
while(ch=='y'||ch=='Y')
{
ob.getdata();
fout.write((char *)&ob,sizeof(ob));
cout<<"\nDo You Want To Continue Adding Records? (Y/N) : ";
cin>>ch;
}
fout.close();
}
void display() // display all records
{
clrscr();
fstream
fin;
fin.open("Eshop.dat",ios::in|ios::binary);
if(!fin)
{
MessageBox(0,"The File doesn't exist","ERROR!",0);
exit(0);
}
cout<<"\n\t\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n\t\t\t
cout<<"\n\t\t\t
ITEM DETAILS
";
``````````````````````````"<<endl;
cout<<"========================================";
cout<<"========================================";
gotoxy(0,5);
cout<<"\n Item Name\t
cout<<"
Price\t\t
Item Code\t";
Discount\n";
cout<<"========================================";
cout<<"========================================";
fin.read((char *)&ob,sizeof(ob));
while(fin)
{
ob.putdata();
fin.read((char *)&ob,sizeof(ob));
}
fin.close();
}
void sp_offer() // display only those records
{
// with discount
fstream fin;
fin.open("Eshop.dat",ios::in|ios::binary);
if(!fin)
{
MessageBox(0,"The File doesn't exist","ERROR!",0);
exit(0);
}
clrscr();
cout<<"\n\t\t\t
~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n\t\t\t
cout<<"\n\t\t\t
SPECIAL OFFERS
";
``````````````````````````"<<endl;
cout<<"========================================";
cout<<"========================================";
gotoxy(0,5);
cout<<"\n Item Name\t
Item Code\t
";
}
void biller() // Displaying and calculating bill
{
clrscr();
char ch='y';
long int code;
double bill=0.0,result,r_amt;
fstream fin;
fin.open("Eshop.dat",ios::in|ios::binary);
if(!fin)
{
MessageBox(0,"The File doesn't exist","ERROR!",0);
exit(0);
}
cout<<"\n\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n\t\t\t
BILL
";
cout<<"\n\t\t\t``````````````````````````";
cout<<"\n========================================";
cout<<"========================================";
fin.read((char *)&ob,sizeof(ob));
while(ch=='y'||ch=='Y')
{
cout<<"\n\nEnter the Item Code
: ";
cin>>code;
if(ob.getcode()==code)
{
result=ob.bdisplay();
bill+=result;
}
else
{
cout<<"\nItem Not Available!";
}
fin.read((char *)&ob,sizeof(ob));
cout<<"\n\tDo You Want to Continue Billing (Y/N) : ";
cin>>ch;
}
if(bill>0.0)
{
cout<<"\n\n\t\t***Total BILL AMOUNT : R.O. "<<bill;
cout<<"\n\t\t***Received Amount : R.O. ";
cin>>r_amt;
cout<<"\n\t\t***Balance Amount : R.O. "<<r_amt-bill;
}
}
void main()
{
clrscr();
int choice;
char ch='y';
gotoxy(0,8);
cout<<"````````````````````````````````````````";
cout<<"````````````````````````````````````````";
gotoxy(0,10);
cout<<"\n\t\t\t\t
WELCOME";
cout<<"\n\t\t\t\t
cout<<"\n\t\t\t
to
";
gotoxy(0,17);
cout<<"````````````````````````````````````````";
cout<<"````````````````````````````````````````";
gotoxy(0,20);
cout<<"\n\tPress any key to continue ... ";
while(kbhit()==0); // to wait till for a keystroke
do
{
clrscr();
cout<<"\n\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n\t\t\t
MENU
";
cout<<"\n\t\t\t``````````````````````````";
cout<<"\n\t\t\t:
:";
:";
:";
:";
:";
:";
:";
:";
cout<<"\n\t\t\t: 8.Exit
:";
cout<<"\n\t\t\t:........................:";
cout<<"\n\nEnter Your Choice : ";
cin>>choice;
switch(choice)
{
case 1: create();
break;
case 2: modify();
break;
case 3: del();
break;
case 4: add();
break;
case 5: display();
break;
case 6: sp_offer();
break;
case 7: biller();
break;
case 8: clrscr();
gotoxy(29,11);
cout<<"DESIGNED BY : JERRIN THOMAS ";
gotoxy(34,12);
cout<<"Copyright 2013";
gotoxy(32,13);
cout<<"All Rights Reserved";
exit(0);
break;
default:MessageBox(0,"Invalid Choice Selected!","ERROR!",0);
}
cout<<"\n\n\tDo You Want To Go Back To Menu..? (Y/N) : ";
cin>>ch;
}while(ch=='y'||ch=='Y');
clrscr();
gotoxy(29,11);
cout<<"DESIGNED BY : JERRIN THOMAS ";
gotoxy(34,12);
cout<<"Copyright 2013";
gotoxy(32,13);
cout<<"All Rights Reserved";
exit(0);
}
MAIN MENU
CREATING RECORDS
MODIFYING RECORDS
DELETING RECORDS
CUSTOMER BILLING