C++ DFH Item ordering and storing in file project with admin and guest Panels(with Search Modify , delete, restore, total business and much more...)100%working(in DevC++)

//first you have to add a few products in admin panel and password for admin is :admin and place a few orders from guest end to explore all the functions , ENJOY:)



#include<iostream>

#include<fstream>

#include<iomanip>

#include<stdio.h>

#include<string.h>

#include<conio.h>

using namespace std;

class items;

class bill;

class billdetails;

////////////////////////////////////////////

//PROTYPING THE FUNCTIONS

void allorders();

void searchbillno();

void restore();

void modifyrecord();

void addrecord();

void pattern();

void displayallitems();

void adminpage();

void startpage();

void guestpage();

void searchitem();

void removeproduct();

void searchitem();

void outofstock();

int generatebillno();

void placeorder();

char *getnamefromfile(int i);

void headingoforderdetails();

void headingforproductsales();

void getorderfromfile(int );

class bill

{

protected:

int billno;

public:

bill()

{

billno=0;

}

int getbillno()                     

{

return billno;

}

void setbillno(int b)

{

billno=b;

}

};

bill bil;


class items

{

protected:

int id;

char name[20];

int price;

public:

int getid()

{

return id;

}

int getPrice()

{

return price;

}

char *getname()

{

return name;

}

public:

void getdata();

void showdata();

void listdata();

void smallpattern();

};

items i;


class billdetails:public bill,public items

{

int qty;

int amt;

public:

int getqty()

{

return qty;

}

int getamount()

{

return amt;

}

void patternofbill();

void setorder(int,int,char[],int,int);

void patternofproduct();

};


billdetails b;


void billdetails::patternofbill()

{

cout<<setw(15)<<id;

cout<<setw(20)<<name;

cout<<setw(10)<<price;

cout<<setw(10)<<qty;

cout<<setw(10)<<amt;

cout<<endl;

}

void billdetails::patternofproduct()

{

cout<<setw(15)<<billno;

cout<<setw(20)<<name;

cout<<setw(10)<<price;

cout<<setw(10)<<qty;

cout<<setw(10)<<amt;

cout<<endl;

}


void items::getdata()

{

cout<<"Enter ID   : ";

cin>>id;

cout<<"Enter Name : ";

cin>>name;

cout<<"Enter Price: ";

cin>>price;

cout<<"Data Saved\n";

}


int generatebillno()

{


int n=0;

ifstream fin("bill.po",ios::in|ios::binary);

while(fin.read((char*)&b,sizeof(b)))

{

n=b.getbillno();

}

fin.close();


if(n==0)

n=1;

else

n+=1;

b.setbillno(n);

ofstream fout("bill.po",ios::out|ios::app|ios::binary);

fout.write((char*)&b,sizeof(b));

fout.close();

return n;

}


char *getnamefromfile(int j)

{

int id=j;

char nm[20]="none";

ifstream fin("products.po",ios::in);

while(fin.read((char*)&i,sizeof(i)))

{

if(id==i.getid())

{

strcpy(nm,i.getname());

}

}

return nm;

}


void items::showdata()

{

cout<<"Item Details\n";

cout<<"Id   : "<<id<<endl;

cout<<"Name : "<<name<<endl;

cout<<"Price: "<<price<<endl;

cout<<endl;

}

void searchbillno()

{

int bn;

cout<<"Enter Bill NO to search your bill : ";

cin>>bn;

cout<<endl;

cout<<"Bill No : "<<bn<<"\n\n";

headingoforderdetails();

int total=0;

ifstream fin;

fin.open("orders.po");

while(fin.read((char*)&b,sizeof(b)))

{

if(bn==b.getbillno())

{

cout.setf(ios::left);

b.patternofbill();

total+=b.getamount();

}

}

cout.setf(ios::left);

cout<<setw(45)<<" ";

cout.setf(ios::left);

cout<<"Total: "<<total<<endl;

}

void items::listdata()

{

cout.setf(ios::left);

cout<<setw(8)<<id;

cout<<setw(17)<<name;

cout<<setw(12)<<price;

cout<<endl;

}


void billdetails::setorder(int b,int i,char nm[],int p,int q)

{

billno=b;

id=i;

strcpy(name,nm);

price=p;

qty=q;

amt=p*q;

}


void items::smallpattern()

{

cout.setf(ios::left);

cout<<setw(8)<<"Id"<<setw(17)<<"Name";

cout<<setw(12)<<"Price";

cout<<endl;

}


void displayallitems()

{

ifstream fin;

fin.open("products.po",ios::in);

i.smallpattern();

while(fin.read((char*)&i,sizeof(i)))

{

i.listdata();

}

fin.close();

}


void additem()

{

ofstream fout;

fout.open("products.po",ios::app);

i.getdata();

fout.write((char*)&i,sizeof(i));

fout.close();

}


void searchitem()

{

int id,flag=0;

ifstream fin;

fin.open("products.po",ios::in);

while(fin.read((char*)&i,sizeof(i)))

{

if(id==i.getid())

{

flag++;

i.showdata();

}

}

if(flag==0)

{

cout<<"No such Id found;\n";

}

}


void guestpage()

{

system("color 60");

int ch;

do{

cout<<"0.Back\n";

cout<<"1.View Menu\n";

cout<<"2.Place Order\n";

cout<<"Enter Choice : ";

cin>>ch;

switch(ch)

{

case 1:

system("cls");

cout<<"This is our menu Dear Customer:\n";

displayallitems();

system("pause");

break;

case 2:

system("cls");

placeorder();

    break;

}

system("cls");

}while(ch!=0);

}


void adminpage()

{

int ch;

do{

cout<<"0.Logout\n";

cout<<"1.Add New Product\n";

cout<<"2.Show All Products\n";

cout<<"3.Modify Product\n";

cout<<"4.Remove Product from Serving\n";

cout<<"5.Search Product\n";

cout<<"6.View out of stock products\n";

cout<<"7.Restart the product service\n";

cout<<"8.View order details\n";

cout<<"9.View Product wise details\n";

cout<<"Enter your choice : ";

cin>>ch;

switch(ch)

{

case 0:

system("cls");

startpage();

break;

case 1:

system("cls");

additem();

system("pause");

system("cls");

break;

case 2:

system("cls");

displayallitems();

system("pause");

system("cls");

break;

case 3:

system("cls");

modifyrecord();

system("pause");

system("cls");

break;

case 4:

system("cls");

removeproduct();

system("pause");

system("cls");

    break;

    case 5:

    system("cls");

    searchitem();

    system("pause");

    system("cls");

break;

case 6:

system("cls");

outofstock();

system("pause");

system("cls");

break;

case 7:

system("cls");

restore();

system("pause");

system("cls");

    break;

    case 8:

    system("cls");

searchbillno();

system("pause");

system("cls");

break;

case 9:

system("cls");

allorders();

system("pause");

system("cls");

    break;

}

}while(ch!=0);

}


void outofstock()

{

ifstream fin;

fin.open("trash.po",ios::binary);

while(fin.read((char*)&i,sizeof(i)))

{

i.showdata();

}

fin.close();

}


int getpricefromfile(int j)

{

int id=j;

float r=0;

ifstream fin;

fin.open("products.po",ios::in);

while(fin.read((char*)&i,sizeof(i)))

{

if(id==i.getid())

{

r=i.getPrice();

}

}

fin.close();

return r;

}


void placeorder()

{

int bn=0,j,qt;

char name[20];

bn=generatebillno();

ofstream fout("orders.po",ios::app);

do

{

system("cls");

cout<<"0. To order and Exit \n";

displayallitems();

cout<<"Enter Id to Order Or press 0 : \n";

cin>>j;

if(j==0)

{

goto start;

}

cout<<getnamefromfile(j)<<" @ "<<getpricefromfile(j)<<endl;

cout<<"Enter Quantity : ";

cin>>qt;

b.setorder(bn,j,getnamefromfile(j),getpricefromfile(j),qt);

fout.write((char*)&b,sizeof(b));

}while(j!=0);

start:

fout.close();

cout<<"End:\n";

getorderfromfile(bn);

system("pause");

}


void getorderfromfile(int bn)

{

cout<<"Bill No : "<<bn<<"\n\n";

headingoforderdetails();

int total=0;

ifstream fin;

fin.open("orders.po");

while(fin.read((char*)&b,sizeof(b)))

{

if(bn==b.getbillno())

{

cout.setf(ios::left);

b.patternofbill();

total+=b.getamount();

}

}

cout.setf(ios::left);

cout<<setw(45)<<" ";

cout.setf(ios::left);

cout<<"Total: "<<total<<endl;

}


void headingoforderdetails()

{

cout.setf(ios::left);

cout<<setw(10)<<"Id"

<<setw(20)<<"Product Name"

<<setw(10)<<"Price"

<<setw(10)<<"Qty."

<<setw(10)<<"Amount"<<endl;

}

void headingforproductsales()

{

cout.setf(ios::left);

cout<<setw(15)<<"Bill No"

<<setw(20)<<"Product Name"

<<setw(10)<<"Price"

<<setw(10)<<"Qty."

<<setw(10)<<"Amount"<<endl;

}



void restore()

{

int chh,id;

ofstream fout1,fout2;

fout1.open("tmp.po");

fout2.open("products.po",ios::app);

ifstream fin;

fin.open("trash.po",ios::binary);

cout<<"Enter the Id to Restore:";

cin>>id;

while(fin.read((char*)&i,sizeof(i)))

{

if(id==i.getid())

{

i.showdata();

cout<<"Following Item Will Be Restored...\n";

fout2.write((char*)&i,sizeof(i));

}

else

{

fout1.write((char*)&i,sizeof(i));

}

}

fout1.close();

fout2.close();

fin.close();

remove("trash.po");

rename("tmp.po","");

}


void removeproduct()

{

int chh,id;

ofstream fout1,fout2;

fout1.open("tmp.po");

fout2.open("trash.po",ios::app);

ifstream fin;

fin.open("products.po",ios::binary);

cout<<"Enter the Id to Delete:";

cin>>id;

while(fin.read((char*)&i,sizeof(i)))

{

if(id==i.getid())

{

i.showdata();

cout<<"Following Item Will Be Removed...\n";

fout2.write((char*)&i,sizeof(i));

}

else

{

fout1.write((char*)&i,sizeof(i));

}

}

fout1.close();

fout2.close();

fin.close();

remove("products.po");

rename("tmp.po","products.po");

}

void allorders()

{

int id;

cout<<"Enter id to search product sales : ";

cin>>id;

cout<<endl;

cout<<"Searching for Id no : "<<id<<"\n\n";

headingforproductsales();

int total=0,totalqty=0;

ifstream fin;

fin.open("orders.po");

while(fin.read((char*)&b,sizeof(b)))

{

if(id==b.getid())

{

cout.setf(ios::left);

b.patternofproduct();

total+=b.getamount();

totalqty+=b.getqty();

}

}

cout.setf(ios::left);

cout<<setw(40)<<" ";

cout.setf(ios::left);

cout<<"Total Sales : "<<total<<endl;

cout<<setw(40)<<" ";

cout<<"Total Quantity Sales : "<<totalqty<<endl;

}

void adminlogin()

{

int flag=0;

START:

    system("cls");

cout<<"\t\tSECURED LOGIN!\n";

    cout<<"\nEnter Password  : ";

    char pass[32],pwd[32]={"admin"};

    int i=0;

    char a;

    for(i=0;;)

{

        a=getch();

if((a>='a'&&a<='z')||(a>='A'&&a<='Z')||(a>='0'&&a<='9'))

{

            pass[i]=a;

            ++i;

            cout<<"*";

        }

        if(a=='\b'&&i>=1)

        {

            cout<<"\b \b";


            --i;

        }

        if(a==13)

        {

            pass[i]='\0';

            break;

        }

    }

    if(strcmp(pass,pwd)==0)

    {

    system("cls");

    system("color 10");

    adminpage();

}

else

{

startpage();

cout<<"\nPassword Does Not Matches...\n";

}

}


void modifyrecord()

{

fstream fio;

fio.open("products.po",ios::in|ios::binary|ios::out);

int id,flag=0,pos;

cout<<"Enter Id To be Modified :";

cin>>id;

while(fio.read((char*)&i,sizeof(i)))

{

if(id==i.getid())

{

pos=fio.tellg();

cout<<"Following Record Will Be Modified...\n";

i.showdata();

cout<<"Enter New Details :";

fio.tellg();

}

else

{

cout<<"Not Found";

}

}

}


void startpage()

{

int ch;

system("color 40");

do{

cout<<"0.Exit\n";

cout<<"1.Admin\n";

cout<<"2.Guest\n";

cout<<"Enter Id : ";

cin>>ch;

switch(ch)

{

case 1:

adminlogin();

break;

case 2:

system("cls");

guestpage();

    break;

}

}while(ch!=0);

}


int main()

{

startpage();

}

Comments