Académique Documents
Professionnel Documents
Culture Documents
i|Page
CERTIFICATE
This is to certify that this project titled
Mega Store
has been successfully completed by Abhinav Rao,
Abhishek Yadav and Aastha Sood of DPS RK Puram
class XII L during the academic session 2014-2015. It
is the original work of its creators.
ii | P a g e
INDEX
Content
Pages
1. Introduction
1-3
2. Source Code
4-15
3. Outputs
16-38
4. Limitations
39
5. Resources
40
iii | P a g e
INTRODUCTION
This program is useful for a store where it helps in
preparing electronic database for all the items available
for sale. The user of this program is an authorised
employee of the store designated to do this work.
The main menu consists of 3 options, namely, Item
Menu, Purchase Menu and an option to exit the
program.
I. In the Item Menu there are 7 options. This menu
allows the user to do the following:
1.
Add an item:
User is required to add item code, item name,
price and quantity. Any number of items can be
added.
2.
Search an item:
The program searches an item by its name or code
(to be entered by user) and displays the details if
the code or name matches. It helps the user to
plan the items to be ordered if they are sold.
1|Page
3.
4.
5.
Delete an item:
Deletion of item is performed on need basis.
6.
7.
2|Page
2.
Create a bill:
This option prompts the user to enter an Item
code corresponding to the item which the
customer wishes to purchase. Based on the code it
displays the item name and price. The number
purchased can be inputted by the user and
accordingly the cost of the item is displayed. Total
amount for all the items selected for purchase is
displayed at the screen. If the number ordered
exceeds the quantity in the store it displays the
maximum permissible limit and bills it.
3.
MEGA STORE
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<dos.h>
#include<graphics.h>
class prod
{
private:
char name[30];
float price,code,qty;
public:
char* retname()
{ return(name);}
float retcode()
{ return(code);}
float retprice()
{ return(price);}
void cprice(float np)
{ price=np;}
float retqty()
{ return(qty);}
void cqty(int n)
{ qty+=n; }
void input()
{
cout<<"\nItem code: "; cin>>code;
cout<<"Item name: "; gets(name);
cout<<"Price: "; cin>>price;
cout<<"Quantity: "; cin>>qty;
}
};
void show()
{
cout<<endl<<"Item code: " <<code<<endl
<<"Item name: "<<name<<endl
<<"Price: "<<price<<endl
<<"Quantity: "<<qty<<endl;
}
4|Page
void bill();
void wel();
int strt();
void nw();
void change();
void show_all();
void Item();
void Purchase();
void scode();
void sname();
void csort();
void nsort();
void del();
void Purchase();
void main()
{
clrscr();
wel();
clrscr();
textmode(C40);
cout<<"Created by: Abhinav Rao, Abhishek Yadav, Aastha Sood";
delay(2500);
clrscr();
int ch;
do
{
ch=strt();
switch(ch)
{
case 1: Item(); ch=0; break;
case 2: Purchase(); ch=0; break;
}
}while(ch<1||ch>3);
getch();
5|Page
void bill()
{
fstream fil; prod s;
int i=1, n=0,p;
float cod,tot=0;
gotoxy(1,1);
cout<<"Code[101-123]" ;
gotoxy(17,1);
cout<<"Name";
gotoxy(35,1);
cout<<"Price";
gotoxy(55,1);
cout<<"Number";
gotoxy(76,1);
cout<<"Cost";
gotoxy(1,25);
cout<<"To exit enter 0";
do
{
fil.open("List.dat",ios::binary|ios::in|ios::out);
i++;
p=0;
gotoxy(2,i);
cin>>cod;
fil.seekg(0);
while(fil.read((char*)&s,sizeof(s)) && !p)
{
if(s.retcode()==cod)
{
int pos=fil.tellg();
gotoxy(17,i);
cout<<s.retname();
gotoxy(36,i);
cout<<s.retprice();
gotoxy(57,i);
cin>>n;
if((s.retqty()-n)>=0)
{
s.cqty(-n);
fil.seekp(pos-sizeof(s));
fil.write((char*)&s,sizeof(s));
gotoxy(77,i);
cout<<n*s.retprice();
tot+=n*s.retprice();
gotoxy(68,25);
cout<<"Total: "<<tot;
p++;
}
6|Page
else
gotoxy(20,i+2);
cout<<"Required amount not available!";
gotoxy(20,i+3);
cout<<"Maximum "<<s.retqty()<<" available.";
delay(4000);
gotoxy(20,i+2);
cout<<"
";
gotoxy(20,i+3);
cout<<"
";
gotoxy(55,i);
cout<<" ";
gotoxy(57,i);
n=s.retqty();
cout<<n;
s.cqty(-n);
fil.seekp(pos-sizeof(s));
fil.write((char*)&s,sizeof(s));
gotoxy(74,i);
cout<<n*s.retprice();
tot+=n*s.retprice();
gotoxy(68,25);
cout<<"Total: "<<tot;
p++;
}
if(p==0 && cod!=0)
{
gotoxy(1,i);
cout<<"Not Found!"<<endl;
delay(3000);
gotoxy(1,i);
cout<<"
";
gotoxy(1,i);
i--;
}
fil.close();
} while(cod!=0);
clrscr();
gotoxy(29,11);
cout<<"Your total is: Rs. "<<tot;
getch();
7|Page
void wel()
{
textmode(C40);
gotoxy(7,10);
char wel[]={"Welcome to the 'Mega Store'!"} ;
for(int i=0;i<strlen(wel);i++)
{delay(115) ;
cout<<wel[i];
}
delay(1500);
clrscr();
textmode(C80);
}
int strt()
{
textmode(C80); delay(500);
do
{
clrscr();
gotoxy(20,3);
cout<<"Please choose one of the following \n";
gotoxy(20,5);
cout<<"1. Item Menu: Product Management Module\n";
gotoxy(20,6);
cout<<"2. Purchase Menu: Sale Management Module\n";
gotoxy(30,7);
cout<<"3. Exit\n\n";
gotoxy(32,9);
cout<<" Choice: ";
int ch; cin>>ch;
clrscr();
}while(ch<1||ch>3);
return(ch);
}
void nw()
{
fstream fil;
prod s;
fil.open("List.dat",ios::binary|ios::app);
do
{
s.input();
fil.write((char*)&s,sizeof(s));
cout<<"\n\nMore products[y/n]? ";
char ch; cin>>ch;
}while(ch=='y'||ch=='Y');
fil.close();
}
8|Page
void change()
{
fstream fil; char ans; int chng=0;
do
{
fil.open("List.dat",ios::binary|ios::in|ios::out);
prod s;
float cod;
int qty,ch;
float price;
cout<<"Item code: ";
cin>>cod;
while(fil.read((char*)&s,sizeof(s)))
{
if(s.retcode()==cod)
{
cout<<"1. Change Quantity\n"
<<"2. Change Price\n"
<<"3. Back Item Menu\n"
<<"\nChoice: ";
cin>>ch; chng++;
switch(ch)
{
case 1:
}
}
case 2:
{
cout<<"New price: ";
cin>>price;
int pos=fil.tellg();
s.cprice(price);
fil.seekp(pos-sizeof(s));
fil.write((char*)&s,sizeof(s));
cout<<"New price of "<<s.retname()<<" is: "<<s.retprice();
}break;
if(chng==0)
9|Page
void show_all()
{
fstream fil;
prod s; int i=1;
fil.open("List.dat",ios::binary|ios::in);
gotoxy(8,1);
cout<<"Code" ;
gotoxy(29,1);
cout<<"Name";
gotoxy(50,1);
cout<<"Price";
gotoxy(71,1);
cout<<"Quantity";
while(fil.read((char*)&s,sizeof(s)))
{
i++;
gotoxy(9,i);
cout<<s.retcode();
gotoxy(28,i);
cout<<s.retname();
gotoxy(52,i);
cout<<s.retprice();
gotoxy(72,i);
cout<<s.retqty();
}
fil.close(); getch();
}
void scode()
{
fstream fil;
prod s; int c=0; int cod;
fil.open("List.dat",ios::binary|ios::in);
cout<<"Code: "; cin>>cod;
while(fil.read((char*)&s,sizeof(s)))
if(s.retcode()==cod)
{ s.show(); c++; }
if(c==0)
cout<<"Item not found!";
getch(); fil.close();
}
10 | P a g e
void sname()
{
fstream fil;
prod s;
int c=0;
fil.open("List.dat",ios::binary|ios::in);
char name[30];
cout<<"Name: ";
gets(name);
while(fil.read((char*)&s,sizeof(s)))
if(strcmpi(s.retname(),name)==0)
{ s.show(); c++; }
if(c==0)
cout<<"Item not found!";
getch();
fil.close();
void csort()
{
fstream fil;
fil.open("List.dat",ios::binary|ios::in|ios::out);
prod sj,sj1;
//s jth,s (j+1)th record
cout<<"Sorting by code.....";
fil.seekg(0,ios::end);
int nor=fil.tellg()/sizeof(sj);
for(int i=0;i<nor;i++)
for(int j=0;j<nor-i-1;j++)
{
fil.seekg(j*sizeof(sj));
fil.read((char*)&sj,sizeof(sj));
fil.read((char*)&sj1,sizeof(sj1));
if(sj.retcode()>sj1.retcode())
{
fil.seekp(j*sizeof(sj));
fil.write((char*)&sj1,sizeof(sj1));
fil.write((char*)&sj,sizeof(sj));
}
}
delay(750);
cout<<"\nThe list has been sorted in ascending order of item code.";
fil.close();
getch();
11 | P a g e
void nsort()
{
fstream fil;
fil.open("List.dat",ios::binary|ios::in|ios::out);
prod sj,sj1;
//s jth,s (j+1)th record
cout<<"Sorting by name.....";
fil.seekg(0,ios::end);
int nor=fil.tellg()/sizeof(sj);
for(int i=0;i<nor;i++)
for(int j=0;j<nor-i-1;j++)
{
fil.seekg(j*sizeof(sj));
fil.read((char*)&sj,sizeof(sj));
fil.read((char*)&sj1,sizeof(sj1));
if(strcmpi(sj.retname(),sj1.retname())>0)
{
fil.seekp(j*sizeof(sj));
fil.write((char*)&sj1,sizeof(sj1));
fil.write((char*)&sj,sizeof(sj));
}
}
delay(750);
cout<<"\nThe list has been sorted in ascending order of item name.";
fil.close();
getch();
}
void del()
{
fstream f1,f2;
f1.open("List.dat",ios::binary|ios::in);
f2.open("Temp.dat",ios::binary|ios::out);
prod s;
float cod, del=0;
cout<<"Please enter item code: ";
cin>>cod;
cout<<"Deleting..."<<endl;
delay(700);
while(f1.read((char*)&s,sizeof(s)))
{
if(cod!=s.retcode())
f2.write((char*)&s,sizeof(s));
else
{
del++; s.show();
cout<<"\nDeleted...";
getch();
}
}
f1.close(); f2.close();
12 | P a g e
if(del==0)
cout<<"No item found to be deleted!";
else
{
f1.open("List.dat",ios::binary|ios::out);
f2.open("Temp.dat",ios::binary|ios::in);
while(f2.read((char*)&s,sizeof(s)))
f1.write((char*)&s,sizeof(s));
f2.close(); f1.close();
}
getch();
void Item()
{
fstream fil;
fil.open("List.dat",ios::binary|ios::in);
int ch; prod s;
do
{
clrscr();
cout<<"1. Add New Items\n"
<<"2. Search an Item\n"
<<"3. Display All Items\n"
<<"4. Sort Item List\n"
<<"5. Delete an Item\n"
<<"6. Update Item details\n"
<<"7. Back Main Menu\n"
<<"\n Choice: ";
cin>>ch;
switch(ch)
{
case 1: { clrscr(); nw(); ch=0;} break;
case 2:
{
int a;
do
{
clrscr();
cout<<"1. Search by code of item\n"
<<"2. Search by name of item\n"
<<"3. Back to Item Menu\n"
<<"\nChoice: ";
cin>>a;
switch(a)
{
case 1: { scode(); a=0;} break;
case 2: { sname(); a=0;} break;
}
}while(a<1||a>3);
13 | P a g e
ch=0;
}break;
case 3:
{
clrscr();
cout<<"Displaying all....";
delay(600); clrscr();
show_all(); ch=0;
} break;
case 4:
{
int b;
do
{
clrscr();
cout<<"1. Sort by name\n"
<<"2. Sort by code\n"
<<"3. Back to Item Menu \n"
<<"\nChoice: ";
cin>>b;
switch(b)
{
case 1: { nsort(); b=0;} break;
case 2: { csort(); b=0;} break;
}
}while(b<1||b>3); ch=0;
} break;
case 5:
{ clrscr(); del(); ch=0; }break;
case 6:
{ clrscr(); change(); ch=0;}
break;
}while(ch<1||ch>7);
fil.close();
14 | P a g e
void Purchase()
{
fstream fil;
fil.open("List.dat",ios::binary|ios::in);
prod s;
int ch;
do
{
clrscr();
cout<<"Please choose one from the following:\n"
<<"1. Display all items\n"
<<"2. Billing\n"
<<"3. Back to Main Menu \n"
<<"\n Choice: ";
cin>>ch;
switch(ch)
{
case 1:
{
clrscr();
cout<<"Displaying all...";
delay(600);
clrscr();
show_all(); ch=0;
} break;
case 2:
{
clrscr();
bill(); ch=0;
} break;
}
}while(ch<1||ch>3);
fil.close();
15 | P a g e
OUTPUT
16 | P a g e
17 | P a g e
18 | P a g e
19 | P a g e
20 | P a g e
21 | P a g e
22 | P a g e
23 | P a g e
24 | P a g e
25 | P a g e
26 | P a g e
27 | P a g e
28 | P a g e
29 | P a g e
30 | P a g e
31 | P a g e
32 | P a g e
33 | P a g e
34 | P a g e
35 | P a g e
36 | P a g e
37 | P a g e
38 | P a g e
39 | P a g e
RESOURCES
Class Notes
C++ Help Menu
40 | P a g e