Source Code : STORE-TOLL an Billing Project

STORE-TOLL an Billing Project

Code :

#include

#include

#include

#include

#include

#include

#define NO 0

#define YES 1

#define NONE -1

//in a menu there can be three items

#define MAX_MENU 6

int x,y;

int selection;

int button,x,y;

void *p;

size_t area;

int validate(int);

FILE *date;

FILE *f2;

FILE *fop;

FILE *today;

  char todaydate[15];

FILE *day;

  char salebydate[10];

FILE *itemtoday;

FILE *itembydate;

  char str[10];

int customer;

struct MENU

{

int x;

int y;

int x1;

int y1;

unsigned char Active[MAX_MENU];

char *head;

};

int mouseon(struct MENU *t);

void process();

void xorbar(int sx,int sy,int ex,int ey,int c);

void show();

void hide();

void status();

  //position of the billprocess menu

  struct MENU Billprocess = {0,0,80,20};

  //position of the print menu

  struct MENU Print = {90,0,165,20};

  struct MENU Management = {175,0,260,20};

void main()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,"f:\tcpp");

selection=NONE;

for(gd=0;gd

{

  //gd=3

Billprocess.Active[gd]=YES;

  //gd=1

Print.Active[gd]=YES;

Management.Active[gd]=YES;

}

  //head that is printed on msg

Billprocess.head="processbill";

Print.head="Print";

Management.head="management";

  //allocation for image memory

area=imagesize(0,0,150,150);

p=malloc(area);

if(p==NULL)

{

closegraph();

restorecrtmode();

printf("not enough memory");

exit(1);

}

//style of the menu

setfillstyle(1,7);

//full window

bar(0,0,660,650);

welcomescreen();

x=2;

y=2;

process();

//end();

closegraph();

getch();

}

void process()

{

  //menu items in billprocess menu

char *bp[]={"Processbill","Openbill","Exit"};

  //menu item in print menu

char *pr[]={"Printbill"};

char

*mgt[]={"SalesToday","SalesBydate","Itemsoldtoday","Itemsoldbydate"};

char KEY;

  //menu bar position

win(0,0,660,20);

  //drawing button for menu items

drawbtn(&Billprocess,"Billprocess");

drawbtn(&Print,"Print");

drawbtn(&Management,"Management");

settextstyle(0,0,0);

//outtextxy(close(x+y),close(y+7),"x");

show();

  //instantly menus are idle

Billprocess.Active[3]=NO;

Print.Active[1]=NO;

Management.Active[4]=NO;

while(1)

{

if(kbhit())

{

KEY=getch();

//way to exit press esc or -

if(KEY==27 || KEY==45)

break;

}

status();

if(button==1)

{

//if(mouseon(&close))

//break;

if(mouseon(&Billprocess))

{

pullmenudown(bp,3,&Billprocess);

if(selection==NONE)

msg("no selection");

if(selection==0)

{

char str[3];

struct dosdate_t d;

  char todaydate[15];

  char month[5],year[5];

  // initalization of customerid

  int customerid;

  // macro to generate customerid in random

  randomize();

  customerid= rand() % 1000;

  customer=customerid;

  itoa(customerid,str,10);

    _dos_getdate(&d);

    itoa(d.day,todaydate,10);

    itoa(d.month,month,10);

    itoa(d.year,year,10);

    strcat(todaydate,month);

    strcat(todaydate,year);

    date=fopen(todaydate,"a+");

  f2=fopen(str,"w");

    //user defined function for page design

  pagedesign();

  gotoxy(6,4);

  printf("CUSTOMERID : %d",customerid);

  fprintf(f2,"%d",customerid);

    //user defined method call for time zone to which customer

arrives

to bill

  entertime();

    //user defined function for database acess

  getdatabaseacess();

  }

  if(selection==1)

  {

  char str[3];

  setfillstyle(1,0);

  bar(5,25,635,448);

gotoxy(10,8);

printf("ENTER THE CUSTOMERID TO OPEN  ");

scanf("%s",str);

fop=fopen(str,"r");

if(!fop)

{

gotoxy(10,12);

printf("no customer is  available");

}

else

{

  pagedesign();

  openbill();

  }

  }

  if(selection==2)

  {

  exit(0);

  }

  }

if(mouseon(&Print))

{

pullmenudown(pr,1,&Print);

if(selection==NONE)

msg("noselection");

  if(selection==0)

  {

  char str[3];

  setfillstyle(1,0);

  bar(5,25,635,448);

    itoa(customer,str,10);

fop=fopen(str,"r");

if(!fop)

{

gotoxy(10,12);

printf("no customer is  available");

}

else

{

  printbill();

  }

  }

}

if(mouseon(&Management))

{

pullmenudown(mgt,4,&Management);

if(selection==NONE)

msg("noselection");

if(selection==0)

{

struct dosdate_t d;

  char month[5],year[5];

_dos_getdate(&d);

    itoa(d.day,todaydate,10);

    itoa(d.month,month,10);

    itoa(d.year,year,10);

    strcat(todaydate,month);

    strcat(todaydate,year);

    today=fopen(todaydate,"r");

  setfillstyle(1,0);

  bar(5,25,635,448);

if(!today)

{

gotoxy(15,12);

printf("NO DATABASE IS AVAILABLE");

}

else

{

  todaysales();

  }

  }

  if(selection==1)

  {

  setfillstyle(1,0);

  bar(5,25,635,448);

gotoxy(10,8);

printf("ENTER THE DATE TO OPEN  ");

scanf("%s",salebydate);

day=fopen(salebydate,"r");

if(!day)

{

gotoxy(10,10);

printf("NO DATABASE AVAILABLE");

}

else

{

  totalsalebydate();

  }

  }

  if(selection==2)

  {

struct dosdate_t d;

  char month[5],year[5];

_dos_getdate(&d);

    itoa(d.day,todaydate,10);

    itoa(d.month,month,10);

    itoa(d.year,year,10);

    strcat(todaydate,month);

    strcat(todaydate,year);

    itemtoday=fopen(todaydate,"r");

  setfillstyle(1,0);

  bar(5,25,635,448);

if(!itemtoday)

{

gotoxy(25,12);

printf("NO DATABASE IS AVAILABLE");

}

else

{

  itemtodayretrive();

  }

  }

  if(selection==3)

  {

  setfillstyle(1,0);

  bar(5,25,635,448);

gotoxy(10,8);

printf("ENTER THE DATE TO OPEN  ");

scanf("%s",str);

itembydate=fopen(str,"r");

if(!itembydate)

{

gotoxy(10,10);

printf("no database is  available");

}

else

{

  retriveitembydate();

  }

  }

}

}

else

{

if(mouseon(&Billprocess))

Hlight(&Billprocess);

if(mouseon(&Print))

Hlight(&Print);

if(mouseon(&Management))

Hlight(&Management);

}

}

}

drawbtn(struct MENU *tm,char *txt)

{

setcolor(0);

settextstyle(2,0,4);

  //position that name of the menu is written

outtextxy(tm->x+15,tm->y+4,txt);

}

Hlight(struct MENU *t)

{

winp(t,0);

msg(t->head);

while(mouseon(t))

{

status();

if(button!=0)

break;

if(kbhit())

break;

}

setcolor(7);

hide();

//MESSAGE WINDOW

rectangle(t->x,t->y,t->x1,t->y1);

msg("WELCOME TO STORE-TOLL");

show();

}

  //mouse placement

int mouseon(struct MENU *t)

{

int flag;

flag=0;

if(x>=t->x && x<=t->x1 && y>=t->y && y<=t->y1)

flag=1;

return flag;

}

//MENU ITEM DISPAY

void xorbar(int sx,int sy,int ex, int ey, int c)

{

int i;

setwritemode(1);

setcolor(4);

hide();

for(i=sy;i<=ey;i++)

line(sx,i,ex,i);

show();

setwritemode(0);

}

push(struct MENU *tm)

{

winp(tm,1);

while(button==1)

{

status();

if(kbhit())

break;

}

}

up(struct MENU *tm)

{

setcolor(7);

hide();

rectangle(tm->x,tm->y,tm->x1,tm->y1);

show();

while(button==1)

{

status();

if(kbhit())

break;

}

}

pullmenudown(char *h[],int n,struct MENU *tm)

{

int i;

i=n*20;

push(tm);

hide();

getimage(tm->x+1, tm->y1+2,tm->x+100,tm->y1+i+5,p);

win(tm->x+1,tm->y1+2,tm->x+100,tm->y1+i+5);

setcolor(5);

settextstyle(2,0,4);

for(i=0;i

{

if(!tm->Active[i])

{

setcolor(15);

outtextxy(tm->x+15,tm->y1+9+i*20,h[i]);

setcolor(0);

outtextxy(tm->x+14,tm->y1+8+i*20,h[i]);

}

else

{

//position to write menu items

outtextxy(tm->x+14,tm->y1+8+i*20,h[i]);

}

}

show();

while(button==1)

status();

handlemenu(n,tm);

}

pullmenuup(struct MENU *tm)

{

int i;

hide();

putimage(tm->x+1,tm->y1+2,p,COPY_PUT);

show();

up(tm);

}

handlemenu(int n,struct MENU *tm)

{

int i;

char key;

setcolor(0);

selection=NONE;

i=0;

while(1)

{

status();

if(button==1)

break;

for(i=0;i

{

status();

if(mouseon1(tm->x+4, tm->y1+6+i*20, tm->x+99, tm->y1+22+i*20))

{

xorbar(tm->x+3,tm->y1+6+i*20,tm->x+97,tm->y1+22+i*20,14);

while(mouseon1(tm->x+4,tm->y1+8+i*20,tm->x+97,tm->y1+22+i*20))

{

status();

if(button==1)

{

if(tm->Active[i]==YES)

{

selection=i;

break;

}

else

{

selection=NONE;

}

}

if(kbhit())

break;

}

xorbar(tm->x+3,tm->y1+6+i*20,tm->x+97,tm->y1+22+i*20,14);

}

}

}

pullmenuup(tm);

}

mouseon1(int cx, int cy, int cx1, int cy1)

{

int flag;

flag=0;

if(x>=cx && y>=cy && x<=cx1 && y<=cy1)

flag=1;

return flag;

}

union REGS i,o;

struct SREGS ss;

void show()

{

i.x.ax=1;

int86(0x33,&i,&o);

}

void hide()

{

i.x.ax=2;

int86(0x33,&i,&o);

}

void status()

{

i.x.ax=3;

int86(0x33,&i,&o);

button=o.x.bx;

x=o.x.cx;

y=o.x.dx;

}

    //state of the menu

winp(struct MENU *t ,int state)

{

hide();

if(state==1)

{

setcolor(0);

line(t->x,t->y,t->x,t->y1);

line(t->x,t->y,t->x1,t->y);

setcolor(15);

line(t->x1,t->y,t->x1,t->y1);

line(t->x,t->y1,t->x1,t->y1);

}

else

{

setcolor(5);

line(t->x,t->y,t->x,t->y1);

line(t->x,t->y,t->x1,t->y);

setcolor(5);

line(t->x1,t->y,t->x1,t->y1);

line(t->x,t->y1,t->x1,t->y1);

}

show();

}

  //pull down menu design

win(int sx, int sy, int ex,int ey)

{

hide();

setfillstyle(1,7);

bar(sx,sy,ex,ey);

setcolor(15);

line(sx,sy,sx,ey);

line(sx,sy,ex,sy);

setcolor(0);

line(ex,sy,ex,ey);

line(sx,ey,ex,ey);

show();

}

msg(char *m)

{

int l;

setcolor(14);

rectangle(5,25,635,477);

setfillstyle(1,0);

bar(20,455,620,475);

settextstyle(2,0,6);

setcolor(3);

l=textwidth(m)/2;

outtextxy(320-l,455,m);

outtextxy(321-l,456,m);

}

welcomescreen()

{

setfillstyle(1,0);

bar(5,25,635,425);

settextstyle(4,0,3);

setcolor(2);

outtextxy(210,120,"STORE TOLL");

settextstyle(4,0,3);

setcolor(3);

outtextxy(220,160,"WELCOMES");

settextstyle(4,0,3);

setcolor(5);

outtextxy(265,200,"YOU");

}

pagedesign()

{

  //setting text color

  setcolor(2);

  //full outline

  setfillstyle(1,0);

  bar(5,25,635,448);

  //text style

  settextstyle(4,0,3);

  //name of SHOP

  outtextxy(200,25,"STORE-TOLL");

  //first horizontal line

  line(0,65,650,65);

  //second horizontal line

  line(0,78,650,78);

    //first vertical line

  line(120,65,120,450);

    //second vertical line

  line(275,65,275,450);

    //third vertical line

  line(350,65,350,450);

    //fourth vertical line

  line(450,65,450,450);

  //fifth vertical line

  line(530,65,530,450);

  //text style

  settextstyle(2,0,5);

  outtextxy(10,65,"ITEM CODE");

  outtextxy(140,65,"ITEM NAME");

  outtextxy(280,65,"kg/gm");

  outtextxy(375,65,"PRICE");

  outtextxy(465,65,"NUMBER");

  outtextxy(555,65,"AMOUNT");

  //line for total at bottom

  line(450,430,650,430);

  outtextxy(470,430,"TOTAL");

  return(0);

}

entertime(void)

{

  time_t timer;

  struct tm *tblock;

  /* gets time of day */

  timer = time(NULL);

  /* converts date/time to a structure */

  tblock = localtime(&timer);

  //position for time display

  gotoxy(55,4);

  printf("%s", asctime(tblock));

  fprintf(f2,"  %s", asctime(tblock));

  return(0);

}

getdatabaseacess()

{

FILE *file;

  int code,itemcode,num,yax,quantity,i=0,curY;

  char itemname[30];

  char buf[6],ip;

  int counter=0;

  float rate,sum,total=0.0;

  //first y axis position

  yax=5;

  file=fopen("mhn.txt","r");

  while(i<20)

  {

    msg("BILL ON PROCESS");

//x,y position to get code

  gotoxy(6,++yax);

  //get code input

  msg("GET ITEM CODE");

  curY= wherey();

  printf("|");

  ip=getch();

  while(ip!='

')

    {

    if(isdigit(ip))

    {

  printf("%c",ip);

  buf[counter++]=ip;

    }

    ip=getch();

    if(counter>=5)

    break;

    }

  buf[counter]='

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Code :

//8 QUEEN PROBLEM USING BACKTRACKING

#include

#include

#include

int col[9],o,f=0,C1=DETECT,C2;

gra();

place(int x);

void main()

{

int row,q;

clrscr();

col[1]=0;

row=1;

printf("

  TOTAL NO OF ATTEMPT  92 ");

printf("

  NO OF ATTEMPT 'U' WANT  : ");

scanf("%d",&o);

while(row>0)

  {

  col[row]=col[row]+1;

  while(col[row]<=8&&place(row)==1)

  col[row]=col[row]+1;

  if(col[row]<=8)

  {

  if(row==8)

  {

  f++;

  gra();

  if(f==o)

  break;

  }

  else

  {

  row=row+1;

  col[row]=0;

  }

  }

  else

  row=row-1;

  }

getch();

}

/*  PLACING THE QUEEN  */

place(int x)

{

int i,p,q,r;

for(i=1;i

  {

  p=abs(col[i]-col[x]);

  q=abs(i-x);

  if(col[i]==col[x]||p==q)

  return(1);

  }

  return(2);

}

gra()

{

  int s,x,i,c,d,y,j,b,t1,t2,t3,t4;

  initgraph(&C1,&C2,"f:");

  x=getmaxx();

  y=getmaxy();

  cleardevice();

  x=(x-20)/8;

  y=(y-20)/8;

  line(10,10,10,(y*8)+10);

  line((x*8)+10,10,(x*8)+10,(y*8)+10);

  line(10,10,(x*8)+10,10);

  line(10,(y*8)+10,(x*8)+10,(y*8)+10);

  for(i=1;i

  {

  line(x+10,10+i,(x*2)+10,10+i);

  line((x*5)+10,10+i,(x*6)+10,10+i);

  line((x*3)+10,10+i,(x*4)+10,10+i);

  line((x*7)+10,10+i,(x*8)+10,10+i);

  line(10,y+i+10,x+10,y+i+10);

  line((x*2)+10,y+i+10,(x*3)+10,y+i+10);

  line((x*4)+10,y+i+10,(x*5)+10,y+i+10);

  line((x*6)+10,y+i+10,(x*7)+10,y+i+10);

  line(x+10,(y*2)+10+i,(x*2)+10,(y*2)+10+i);

line((x*3)+10,y*2+i+10,(x*4)+10,y*2+i+10);

line((x*5)+10,y*2+i+10,(x*6)+10,y*2+i+10);

line((x*7)+10,y*2+i+10,(x*8)+10,y*2+i+10);

line(10,(y*3)+10+i,x+10,(y*3)+10+i);

line((x*2)+10,y*3+i+10,(x*3)+10,y*3+i+10);

line((x*4)+10,y*3+i+10,(x*5)+10,y*3+i+10);

line((x*6)+10,y*3+i+10,(x*7)+10,y*3+i+10);

line(x+10,(y*4)+10+i,(x*2)+10,(y*4)+10+i);

line((x*3)+10,y*4+i+10,(x*4)+10,y*4+i+10);

line((x*5)+10,y*4+i+10,(x*6)+10,y*4+i+10);

line((x*7)+10,y*4+i+10,(x*8)+10,y*4+i+10);

line(10,(y*5)+10+i,x+10,(y*5)+10+i);

line((x*2)+10,y*5+i+10,(x*3)+10,y*5+i+10);

line((x*4)+10,y*5+i+10,(x*5)+10,y*5+i+10);

line((x*6)+10,y*5+i+10,(x*7)+10,y*5+i+10);

line(x+10,(y*6)+10+i,(x*2)+10,(y*6)+10+i);

line((x*3)+10,y*6+i+10,(x*4)+10,y*6+i+10);

line((x*5)+10,y*6+i+10,(x*6)+10,y*6+i+10);

line((x*7)+10,y*6+i+10,(x*8)+10,y*6+i+10);

line(10,(y*7)+10+i,x+10,(y*7)+10+i);

line((x*2)+10,y*7+i+10,(x*3)+10,y*7+i+10);

line((x*4)+10,y*7+i+10,(x*5)+10,y*7+i+10);

line((x*6)+10,y*7+i+10,(x*7)+10,y*7+i+10);

delay(30);

}

setcolor(2);

c=(x/2)+10;

d=(y/2)+10;

for(i=1,j=0;i<9;i++)

{

  s=col[i];

  for(b=1;b<11;b++)

  circle((c+x*s)-x,d+j,b);

  j+=y;

  delay(600);

  }

delay(3000);

x=getmaxx();

y=getmaxy();

setcolor(16);

for(i=x/2,j=10;i>=0;i--)

{

  line(i,10,i,y);

  line(x-i,10,x-i,y);

  delay(20);

  }

t1=10;

t2=8;

t4=1;

i=1;

if(f==o)

  {

  for(t3=0;t3<=40;t3++)

  {

  if(t4==10)

  {

  i++;

  t4=1;

  }

  t4++;

  if(t3>=0&&t3<=30)

  {

  setcolor(i);

  outtextxy(t1*t3+8,t2*t3,"H");

  outtextxy(620-(t3*9),t2*t3,"Y");

  outtextxy(324,t2*t3,"N");

  outtextxy(t1*t3+16,480-(t3*8),"A");

  outtextxy(615-(t3*8+16),480-(t3*8),"O");

  outtextxy(332,480-(t3*8),"K");

  outtextxy(t1*t3,240,"T");

  outtextxy(608-(t3*8),240,"U");

  }

  if(t3>=10&&t3<=39)

  {

  setcolor(16);

  outtextxy(t1*(t3-10)+8,t2*(t3-10),"H");

  outtextxy(620-(t3-10)*9,t2*(t3-10),"Y");

  outtextxy(324,t2*(t3-10),"N");

  outtextxy(t1*(t3-10)+16,480-(t3-10)*8,"A");

  outtextxy(615-((t3-10)*8+16),480-(t3-10)*8,"O");

  outtextxy(332,480-(t3-10)*8,"K");

  outtextxy(t1*(t3-10),240,"T");

  outtextxy(608-(t3-10)*8,240,"U");

  }

  delay(50);

}

}

return(0);

}