You are on page 1of 6

#include<iostream>

#include<conio.h>
#include<string>
#include<sstream>
#include<fstream>
#include<limits>
#include<ctime>
using namespace std;
class pass
{
public:
int l,k;
};
class items
{
public:
int a,b,c;

table(int price,int profit, int customer_no, char item_name[])


{
cout.setf(ios::left,ios::adjustfield);
cout.fill(' ');

cout<<" "<<customer_no;
cout<<"\t ";
cout.width(25);
cout<<item_name; //SHOWS ITEM NAME

cout.width(15);
cout<<""<<price<<"\t\t\t"<<profit<<endl;//SHOWS ITEM PRICE AND PROFIT
a=customer_no;
b=price;
c=profit;
}
table2(int no_of_items,int custom_no,char item_na[])
{
cout.setf(ios::left,ios::adjustfield);
cout.fill(' ');
cout<<" "<<custom_no;
cout<<"\t ";
cout.width(25);
cout<<item_na;
cout.width(15);
cout<<""<<no_of_items<<endl;

pass comp(int d)
{
if(a==d)
{
pass o;
o.l=b;
o.k=c;
return o; //RETURNING 2 VALUES
}
else
{
pass q;
q.l=0;
q.k=0;
return q; //RETURNING 2 VALUES 0
}
}
};

string intToString(int t)
{
string ch;
ostringstream outs;
outs << t; // Convert value into a string.
ch = outs.str();

return ch;
}
int main()
{
//DECLARING EACH AND EVERY REQUIRED VARIABLES AND VALUES
time_t now = time(0);
// convert now to string form
string dt = ctime(&now),dtday,dtmon,dtdate,dttime,dtyear;
char apples[25]="Apple Cider", black[25]="Black Tea", cb[25]="Chicken
Burger",cm[25]="Chicken Mo:Mo",cp[25]="Chicken Pizza";
char cs[25]="Chilli Sausage",ff[25]="French Fries",gt[25]="Green Tea",hc[25]="Hot
Chocolate",lem[25]="Lemonade";
char mt[25]="Milk Tea",mp[25]="Mushroom Pizza",sd[25]="Soft
Drinks(coke/fanta)",vb[25]="Veg Burger", vm[25]="Veg Mo:Mo";
int a,w,num ,timi=0, i=1, j=1,h=1, b=1,d=1, sum=0, profit=0,
counting=0,app=140,appp=30, bla=80,blap=25, chb=350,chbp=100;
int chm=250,chmp=30, chp=500,chpp=200, chs=350,chsp=120,frf=230,frfp=100,
grt=90,grtp=25, hot=250,hotp=100;
int le=120,lep=40, mit=80,mitp=25, mup=500,mupp=200,sds=100,sdsp=50,
vbr=250,vbrp=100, vmm=200,vmmp=80;
int pacount=0,
racount=0,oacount=0,vacount=0,bacount=0,xacount=0,sacount=0,macount=0,uacount=0,hac
ount=0,facount=0,dacount=0;
int kacount=0, gacount=0,aacount=0;
float gtotal=0, gprofit=0, overall=0;

cout<<"\n\t WELCOME TO OUR CAFE\n";

while(1)
{
//SHOWING THE OPTIONS
cout<<"\n\n [ENTER 1]\tTo Enter New Customer "<<endl;
cout<<" [ENTER 2]\tTo look at History of Customers"<<endl;
cout<<" [ENTER 0]\tTo terminate the program"<<endl;
cout<<"\n\tYOUR ACTION :";
cin>>a;
//IF THE USER DOESNT ENTER INTEGERS
while (!cin)
{
cout <<"\n\t\tENTER A NUMBER ONLY \n\n";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout<<"\tYOUR ACTION :";
cin >> a;
}
//ACTION 1
if(a==1)
{
//COUNTING NUMBER OF FILES CREATED BY OUR PROGRAM
while(1)
{
string name = "customer" + intToString(d) + ".txt";
ifstream fin(name.c_str());
fin.close();
if(fin.fail())
{
break;
}
d++;
}
i=d;
//SHOWING CUSTOMER ID
{
cout<<"\n\nCustomer ID:";
cout.setf(ios::right,ios::adjustfield);
cout.fill('0');
cout.width(5);
cout<<i<<endl;
}
//SHOWING TIME
cout<< dt << endl;

//SHOWING TABLE
cout<<"\tLIST OF ITEMS"<<endl;
cout<<"The following items are in alphabetical order \n"<<endl;
cout<<"Item No.\t ITEM NAME\t\tITEM PRICE(RS)\t\tITEM PROFIT(RS)\n";
items it1,it2,it3,it4,it5,it6,it7,it8,it9,it10,it11,it12,it13,it14,it15;
it1.table(app,appp,j,apples);j++;counting++;
it2.table(bla,blap,j,black);j++;counting++;
it3.table(chb,chbp,j,cb);j++;counting++;
it4.table(chm,chmp,j,cm);j++;counting++;
it5.table(chp,chpp,j,cp);j++;counting++;
it6.table(chs,chsp,j,cs);j++;counting++;
it7.table(frf,frfp,j,ff);j++;counting++;
it8.table(grt,grtp,j,gt);j++;counting++;
it9.table(hot,hotp,j,hc);j++;counting++;
it10.table(le,lep,j,lem);j++;counting++;
it11.table(mit,mitp,j,mt);j++;counting++;
it12.table(mup,mupp,j,mp);j++;counting++;
it13.table(sds,sdsp,j,sd);j++;counting++;
it14.table(vbr,vbrp,j,vb);j++;counting++;
it15.table(vmm,vmmp,j,vm);j=1;counting++;

cout<<"\n\t\tUser Enter the Item numbers\n\t\t";


cout<<"(enter 0 to finish entry)\n";
cout<<"\t\t(enter 123 to cancel entry)\n\n";

//ENTERING ITEM NUMBERS;


while(1)
{
cout<<"Item number:";
cin>>num;
//IF USER DOESNT ENTER INTEGERS
while (!cin)
{
cout <<"\n \t ENTER A NUMBER ONLY \n\n";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout<<"Item number:";
cin >> num;
}
//ENDING THE ENTRY OF ITEMS FROM USER
if(num==0)
{break;}
else if(num<=counting)
{
pass pa,ra,oa,va,ba,xa,sa,ma,ua,ha,fa,da,ka,ga,aa;
pa=it1.comp(num);
if(pa.l>0)
{pacount++;}
ra=it2.comp(num);if(ra.l>0){racount++;}
oa=it3.comp(num);if(oa.l>0){oacount++;}
va=it4.comp(num);if(va.l>0){vacount++;}
ba=it5.comp(num);if(ba.l>0){bacount++;}
xa=it6.comp(num);if(xa.l>0){xacount++;}
sa=it7.comp(num);if(sa.l>0){sacount++;}
ma=it8.comp(num);if(ma.l>0){macount++;}
ua=it9.comp(num);if(ua.l>0){uacount++;}
ha=it10.comp(num);if(ha.l>0){hacount++;}
fa=it11.comp(num);if(fa.l>0){facount++;}
da=it12.comp(num);if(da.l>0){dacount++;}
ka=it13.comp(num);if(ka.l>0){kacount++;}
ga=it14.comp(num);if(ga.l>0){gacount++;}
aa=it15.comp(num);if(aa.l>0){aacount++;}

sum=sum+pa.l+ra.l+oa.l+va.l+ba.l+xa.l+sa.l+ma.l+ua.l+ha.l+fa.l+da.l+ka.l+ga.l+aa.l;

profit=profit+pa.k+ra.k+oa.k+va.k+ba.k+xa.k+sa.k+ma.k+ua.k+ha.k+fa.k+da.k+ka.k+ga.k
+aa.k;
}
else if(num==123)
{
return 0;
}
else
{
cout<<"\n\t Item number "<<num<<" is not in the list \n"<<endl;
}

}
//SHOWING RESULTS
cout.setf(ios::right,ios::adjustfield);
cout.width(25);
cout<<"Total Amount is Rs"<<sum<<endl;
cout.width(25);
cout<<"Total Profit is Rs"<<profit<<endl;

string name = "customer" + intToString(i) + ".txt";

ofstream fout(name.c_str());
fout<<dt<<endl;
fout<<sum<<endl;
fout<<profit<<endl;
fout<<pacount<<endl;
fout<<racount<<endl;
fout<<oacount<<endl;
fout<<vacount<<endl;
fout<<bacount<<endl;
fout<<xacount<<endl;
fout<<sacount<<endl;
fout<<macount<<endl;
fout<<uacount<<endl;
fout<<hacount<<endl;
fout<<facount<<endl;
fout<<dacount<<endl;
fout<<kacount<<endl;
fout<<gacount<<endl;
fout<<aacount<<endl;
fout.close();

d=1;
timi++;
sum=0;
profit=0;
counting=0;
}

//ACTION 2
else if(a==2)
{
cout<<"\n\nLIST OF CUSTOMERS RECORD\n";
cout<<"\n\nCustomer ID \t\tTIME \t\t\tTOTAL AMOUNT(Rs) \tTOTAL PROFIT(Rs)
"<<endl;

while(1)
{
string name = "customer" + intToString(h) + ".txt";
ifstream fin(name.c_str());
if(fin.fail())
{break;}
fin>>dtday>>dtmon>>dtdate>>dttime>>dtyear;
fin>>sum;

fin>>profit>>pacount>>racount>>oacount>>vacount>>bacount>>xacount>>sacount>>macount
>>uacount>>hacount>>facount>>dacount;
fin>>kacount>>gacount>>aacount;

fin.close();

cout.fill('0');
cout.width(5);
cout<<h;
cout<<"\t\t"<<dtday<<" "<<dtmon<<" "<<dtdate<<" "<<dttime<<" "<<dtyear;
cout<<"\t\t"<<sum;
cout<<"\t\t\t"<<profit<<endl;
gtotal=gtotal+sum;
gprofit=gprofit+profit;

h++;
}
h=1;
cout<<endl<<endl<<"LIST OF ITEMS SOLD TILL NOW"<<endl<<endl;
cout<<"Item No.\t ITEM NAME\t\tNUMBER OF ITEMS SOLD\n";
items it1,it2,it3,it4,it5,it6,it7,it8,it9,it10,it11,it12,it13,it14,it15;
it1.table2(pacount,j,apples);j++;
it2.table2(racount,j,black);j++;
it3.table2(oacount,j,cb);j++;
it4.table2(vacount,j,cm);j++;
it5.table2(bacount,j,cp);j++;
it6.table2(xacount,j,cs);j++;
it7.table2(sacount,j,ff);j++;
it8.table2(macount,j,gt);j++;
it9.table2(uacount,j,hc);j++;
it10.table2(hacount,j,lem);j++;
it11.table2(facount,j,mt);j++;
it12.table2(dacount,j,mp);j++;
it13.table2(kacount,j,sd);j++;
it14.table2(gacount,j,vb);j++;
it15.table2(aacount,j,vm);j=1;

cout<<"\n\n\tThe Total amount is Rs"<<gtotal<<endl;


cout<<"\n\tThe Total profit is Rs"<<gprofit;
cout<<"\n\n\tOur profit percentage is "<<(gprofit/gtotal)*100<<"%";

}
else if(a==0)
{
return 0;
}

else
{
cout<<"\n\t\tACTION NUMBER IS INVALID"<<endl;
}
}

You might also like