Вы находитесь на странице: 1из 25

INTRODUCTION

The C++ programming language was developed at AT&T Bell Laboratories in


early 1980s by Bjarne Stroustrup. The name C++ was coined by Rick Mascitti
where ++ is the C increment operator. Ever since its birth, C++ evolved to
cope with problems encountered by users. The major reason behind the success
and popularity of C++ is that it supports the Object Oriented Technology, latest
in the software development and most near to the real world. Object Oriented
Technology is regarded as the ultimate paradigm for the modelling of
information, be that data or logic.
This Electronics Shop Management Software is designed to manage the
necessary information associated with an Electronics Shop. Binary data files are
used to store the information related to the gadgets available in the shop. This
program uses the concepts of Object Oriented Programming like data hiding,
data encapsulation and classes. The output is user-friendly and impressive. This
project makes use of a bunch of in-built functions for formatting output,
comparisons, etc. Descriptions of some of the important areas are also given as
comments in the source code for future modifications, if necessary. Sample
outputs of the program are also given for easy reference.

Downloaded From :: www.electrobigbang.wordpress.com

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.

Downloaded From :: www.electrobigbang.wordpress.com

Downloaded From :: www.electrobigbang.wordpress.com

Downloaded From :: www.electrobigbang.wordpress.com

#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
{

/* the main class for */

private:

/*

getting details of */

char name[25];

/*

different items */

long int icode;


float price;
float disc;
public:
eshop()
{
disc=0.0;
}
void getdata() // for entering details
{
clrscr();
cout<<"\n\t\t\t

~~~~~~~~~~~~~~~~~~~~~~~~~~";

cout<<"\n\t\t\t

ENTER DETAILS

";

Downloaded From :: www.electrobigbang.wordpress.com

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<<"%";
}

Downloaded From :: www.electrobigbang.wordpress.com

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;

Downloaded From :: www.electrobigbang.wordpress.com

}
return(nprice);
}
char *getname()
{
return(name);
}
float getdisc()
{
return(disc);
}
long int getcode()
{
return(icode);
}

}ob;

void create() // creating the file Eshop.dat


{
clrscr();
fstream fout;
char ch='y';
fout.open("Eshop.dat",ios::out|ios::binary);
if(!fout)

Downloaded From :: www.electrobigbang.wordpress.com

{
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);

Downloaded From :: www.electrobigbang.wordpress.com

}
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();
}

Downloaded From :: www.electrobigbang.wordpress.com

void del() // deleting an item


{
clrscr();
fstream fin,fout;
char found='n',ch='y',d_name[25];
while(ch=='y'||ch=='Y')
{
fin.open("Eshop.dat",ios::in|ios::binary);
fout.open("Temp.dat",ios::out|ios::binary);
if(!fin)
{
MessageBox(0,"The File doesn't exist","ERROR!",0);
exit(0);
}
if(!fout)
{
MessageBox(0,"The File cannot be created","ERROR!",0);

exit(0);
}

cout<<"\n\nENTER THE NAME OF THE ITEM TO BE DELETED : ";

gets(d_name);

fin.read((char *)&ob,sizeof(ob));
while(fin)

Downloaded From :: www.electrobigbang.wordpress.com

{
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();

Downloaded From :: www.electrobigbang.wordpress.com

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);

Downloaded From :: www.electrobigbang.wordpress.com

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)

Downloaded From :: www.electrobigbang.wordpress.com

{
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

";

cout<<"Old Price\t\t New Price\n";


cout<<"========================================";
cout<<"========================================";
fin.read((char *)&ob,sizeof(ob));
while(fin)
{
if(ob.getdisc()>0.0)
{
ob.putdata(1);
}
fin.read((char *)&ob,sizeof(ob));
}
fin.close();

Downloaded From :: www.electrobigbang.wordpress.com

}
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)

Downloaded From :: www.electrobigbang.wordpress.com

{
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';

Downloaded From :: www.electrobigbang.wordpress.com

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

";

Eshop Management Software";

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: 1.Enter Item Details

:";

cout<<"\n\t\t\t: 2.Modify Item Details

:";

cout<<"\n\t\t\t: 3.Delete Item Details

:";

cout<<"\n\t\t\t: 4.Add a New Item

:";

cout<<"\n\t\t\t: 5.Display all Items

:";

Downloaded From :: www.electrobigbang.wordpress.com

cout<<"\n\t\t\t: 6.Special Offers

:";

cout<<"\n\t\t\t: 7.Customer Bill

:";

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 ";

Downloaded From :: www.electrobigbang.wordpress.com

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);
}

Downloaded From :: www.electrobigbang.wordpress.com

MAIN MENU

CREATING RECORDS

Downloaded From :: www.electrobigbang.wordpress.com

MODIFYING RECORDS

Downloaded From :: www.electrobigbang.wordpress.com

DELETING RECORDS

ADDING NEW RECORDS

Downloaded From :: www.electrobigbang.wordpress.com

DISPLAYING ALL RECORDS

DISPLAYING ITEMS HAVING DISCOUNT

Downloaded From :: www.electrobigbang.wordpress.com

CUSTOMER BILLING

Downloaded From :: www.electrobigbang.wordpress.com