Wednesday, 25 April 2018

Meme Maker

<!DOCTYPE html>
<html>
<head>
  <title>Meme's</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  <style>
    #image-contain {
      display: inline-flex;
    }
    button{
    font-size: 14px;
    border-radius: 10px;
    color: red;
    background: #56c7e9;
    }
    input[type=text] {
    width: 6em;
    border-radius: 10px;
    }

  </style>
</head>

<body>
  <h1 align="center">Meme Maker</h1>
  <div>
    <input type="file" id="file" /> 
  </div>
  <div id="image-contain">
    <canvas width="500px" height="500px">
    </canvas>
    <div>
      <STRONG><span>Top-Line:</span></STRONG><br/>
      <input id="topLineText" type="text"><br/>
      <STRONG><span>Bottom-Line:</span></STRONG><br/>
      <input id="bottomLineText" type="text"><br/>
      <button id="saveButton">Save</button>
    </div>
  </div>
  <script>
    function Textchangelistener (e) {
      var id = e.target.id;
      var text = e.target.value;
     
      if (id == "topLineText") {
        window.topLineText = text;
      } else {
        window.bottomLineText = text;
      }
     
      redrawmeme(window.imageSrc, window.topLineText, window.bottomLineText);
    }
   
    function redrawmeme(image, topLine, bottomLine) {
      // Get Canvas2DContext
      var canvas = document.querySelector('canvas');
      var ctx = canvas.getContext("2d");
      if (image != null)
        ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
     
      // Text attributes
      ctx.font = '30pt Impact';
      ctx.textAlign = 'center';
      ctx.strokeStyle = 'black';
      ctx.lineWidth = 3;
      ctx.fillStyle = 'white';
     
      if (topLine != null) {
        ctx.fillText(topLine, canvas.width / 2, 40);
        ctx.strokeText(topLine, canvas.width / 2, 40);
      }
     
      if (bottomLine != null) {
        ctx.fillText(bottomLine, canvas.width / 2, canvas.height - 20);
        ctx.strokeText(bottomLine, canvas.width / 2, canvas.height - 20);
      }
    }
   
    function savefile() {
      window.open(document.querySelector('canvas').toDataURL());
    }
   
    function file_select(e) {
      var canvasWidth = 500;
      var canvasHeight = 500;
      var file = e.target.files[0];

      var reader = new FileReader();
      reader.onload = function(fileObject) {
      var data = fileObject.target.result;
       
      var image = new Image();
      image.onload = function() {
         
          window.imageSrc = this;
          redrawmeme(window.imageSrc, null, null);
        }

        image.src = data;
        console.log(fileObject.target.result);
      };
      reader.readAsDataURL(file)
    }
   
    window.topLineText = "";
    window.bottomLineText = "";
    var input1 = document.getElementById('topLineText');
    var input2 = document.getElementById('bottomLineText');
    input1.oninput = Textchangelistener;
    input2.oninput = Textchangelistener;
    document.getElementById('file').addEventListener('change', file_select, false);
    document.querySelector('button').addEventListener('click', savefile, false);
  </script>

</body>
</html>

Friday, 1 December 2017

snake game

#include<stdlib.h>
#include<ctype.h>
#include<conio.h>
#include<stdio.h>
#include<time.h>
#include<dos.h>
#define ESC 27
#define UPARR 72
#define LEFTARR 75
#define DOWNARR 80
#define RIGHTARR 77
#define SAVE 60
#define LOAD 61
main()
{
void starting(void);
void make_xy(char **,char **);
void getrand(char *,char *,char *,char *,char *,int,char);
char getkey(char,char);
void savegame(char *,char *,int,char);
int loadgame(char *,char *,char *);
void win_message(void);
char *x,*y,pos_x,pos_y,num,out=0,old_ch=0,ch=0,new_ch,new_x,new_y,old_num=0;
int i,length=6;
starting();
make_xy(&x,&y);
getrand(&pos_x,&pos_y,&num,x,y,length,ch);
while(!out){
if((new_ch=getkey(old_ch,ch))==ESC)
out=2;
if(out)
break;
if(new_ch==SAVE)
savegame(x,y,length,old_ch);
else if(new_ch==LOAD){
length=loadgame(x,y,&ch);
getrand(&pos_x,&pos_y,&num,x,y,length,ch);
}
else
ch=new_ch;
new_x=x[0];
new_y=y[0];
if(ch==UPARR)
new_y=y[0]-1;
else if(ch==LEFTARR)
new_x=x[0]-1;
else if(ch==DOWNARR)
new_y=y[0]+1;
else if(ch==RIGHTARR)
new_x=x[0]+1;
old_ch=ch;
if((new_x<2)|(new_y<2)|(new_x>79)|(new_y>22))
out=1; /* HIGHEST POSSIBLE SCORE ÷ (78*21-6)*5 = 8160 ÷ 10,000 */
for(i=1;i<length-!old_num;i++) /* NOT "length": TAIL-END MAY MOVE AWAY! */
if((new_x==x[i])&(new_y==y[i])){
out=1;
break;
}
}
}
}
}
if((pos_x==new_x)&(pos_y==new_y)){
old_num+=num;
/* x=(char *)realloc(x,(score+6)*sizeof(char));
y=(char *)realloc(y,(score+6)*sizeof(char)); */
/* if((x==0)|(y==0)) */ /* PROBLEM IS NOT HERE */
/* x=x;*//* SOMEHOW realloc ISN'T COPYING PROPERLY */
getrand(&pos_x,&pos_y,&num,x,y,length,ch);
if(!old_num){
gotoxy(x[length-1],y[length-1]);
putchar(' ');
else{
length++;
if(length==1638){
win_message();
return 0;
gotoxy(67,25);
printf("Score = %5d",length-6);
old_num--;
x[i+1]=x[i];
y[i+1]=y[i];
for(i=length-1;i>0;i--){
x[i]=x[i-1];
y[i]=y[i-1];
if(i==1){
gotoxy(x[i],y[i]);
putchar('Û');
} }
}
}
}
/*-------------------------------------------------------------------------*/
void starting()
{
char i;
x[0]=new_x;
y[0]=new_y;
gotoxy(x[0],y[0]);
printf(" \b"); /* USE THE FUNCTION _setcursortype() */
if(out)
break;
delay(99);
if(out==1){
gotoxy(1,24);
printf("The snake collided with the wall or with itself!\n"
"GAME OVER!!\t\t(Press 'q' to terminate...)");
gotoxy(x[0],y[0]);
while(toupper(getch())!='Q');
clrscr();
printf("Hope you enjoyed the game\n\n\t\tBye!\n");
return 0;
clrscr(); /* FIRST TO DRAW A BOUNDARY for THE GAME */
putchar('É');
for(i=0;i<78;i++)
putchar('Í');
putchar('»');
gotoxy(1,23);
putchar('È');
for(i=0;i<78;i++)
putchar('Í');
putchar('1⁄4');
window(1,2,1,23);
for(i=0;i<21;i++)
cprintf("o");
window(80,2,80,23);
for(i=0;i<21;i++)
cprintf("o"); /* THE BOUNDARY IS DRAWN */
window(1,1,80,25);
gotoxy(38,12);
printf("ÛÛÛÛÛ "); /* THE "SNAKE" IS PUT for THE FIRST TIME */
gotoxy(1,24);
printf("Welcome to the game of SNAKE!\n(Press any arrow key to start now,"
" Escape to leave at any time...)"); /* WELCOME MESSAGE */
gotoxy(43,12);
while(!kbhit());
gotoxy(30,24);
delline();delline(); /* REMOVING MESSAGE */
cprintf("\n( EAT THE NUMBER !! ) Score = 0");
gotoxy(43,12); /* GO TO THE HEAD OF THE SNAKE */
}
void make_xy(char **px,char **py)
{
char i;
}
void getrand(char *px,char *py,char *pn,char *x,char *y,int length,char ch)
{
int allowed=0,i; /* i AND length MUST BE int */
*px=(char *)malloc(1638*sizeof(char)); /*EARLIER IT WAS 6, NOT 1638; BUT*/
*py=(char *)malloc(1638*sizeof(char)); /*realloc IS NOT COPYING PROPERLY*/
for(i=0;i<6;i++){
(*px)[i]=43-i;
(*py)[i]=12;
} /* THE TWO ARRAYS for COORDINATES OF THE SNAKE ARE SIMULATED */
while(!allowed){
allowed=1;
srand((unsigned)time(0));
*px=rand()%78+2; /* GENERATING RANDOM POSITIONAL COORDINATES for */
srand((unsigned)time(0));
*py=rand()%21+2; /* PUTTING A RANDOM NUMBER */
if(ch==UPARR){
if((*px==x[0])&(*py==y[0]-1))
allowed=0;
}
else if(ch==DOWNARR){
if((*px==x[0])&(*py==y[0]+1))
allowed=0;
}
}
else if(ch==LEFTARR){
if((*px==x[0]-1)&(*py==y[0]))
allowed=0;
else if((ch==RIGHTARR)&(*px==x[0]+1)&(*py==y[0]))
allowed=0;
for(i=0;(i<length)&&allowed;i++)
if((*px==x[i])&(*py==y[i]))
allowed=0;
} /* THE RANDOM NUMBER GENERATED SHOULD NOT BE PUT ON SNAKE'S BODY */
srand((unsigned)time(0));
*pn=rand()%9+1; /* THE NUMBER */
gotoxy(*px,*py);
putchar(*pn+48);
gotoxy(x[0],y[0]);
}
char getkey(char old_ch,char ch)
{
char i;
if(kbhit())
for(i=0;i<5;i++){ /* if i too low, takes too many keystrokes */
while((ch=getch())==0);
if(ch==27){
/* out=2;
i=5;
break;*/return ch;
}
}
}
void savegame(char *px,char *py,int length,char ch)
{
if((ch!=LOAD)&(ch!=SAVE)&(ch!=UPARR)&(ch!=DOWNARR)&
(ch!=LEFTARR)&(ch!=RIGHTARR))
continue;
if((ch!=old_ch)|(!kbhit()))
break;
else
for(i=0;(i<12)&(!kbhit());i++)
delay(100);
return ch;
FILE *fp;
int i;
rename("snake.sav","snake.bak");
fp=fopen("snake.sav","wb");
fprintf(fp,"%d %c",length,ch);
for(i=0;i<length;i++)
fprintf(fp,"%c%c",px[i],py[i]);
fclose(fp);
}
int loadgame(char *px,char *py,char *pch)
{
FILE *fp;
int length,i;
fp=fopen("snake.sav","rb");
if(!fp){
clrscr();
puts("ERROR: no saved game found in current directory!!!\n\n\t\t"
"Exiting...\n");
sleep(3);
exit(1);
}
window(2,2,79,22);
clrscr();
/* fscanf(fp,"%d %c ",&length,pch);*/
fscanf(fp,"%d %c",&length,pch);
for(i=0;i<length;i++){
/* fscanf(fp,"%d %d ",&px[length],&py[length]);*/
fscanf(fp,"%c%c",&px[i],&py[i]);
gotoxy(px[i]-1,py[i]-1);
putchar('Û');
}
window(1,1,80,25);
gotoxy(30,24);
delline();delline(); /* REMOVING MESSAGE */
cprintf("\n( EAT THE NUMBER !! ) Score = %5d",length-6);
gotoxy(px[0],py[0]);
printf(" \b");
fclose(fp);
return length;
}
void win_message()

{
window(1,1,80,25);
gotoxy(1,24);
delline();delline();
textcolor(14);
cprintf("CONGRATULATION!! YOU HAVE COMPLETED THE GAME!!\r\n"
"(Press any key to terminate...)");
clrscr();
textcolor(7);

Friday, 6 May 2016

A simple Calculator Application

#include"graphics.h"
#include"dos.h"
#include"stdio.h"
#include"math.h"
union REGS i,o;
char text[35][25]={
"7","8","9","*","4","5","6","/","1","2","3","+","0","00",".","-","M","M+",
"M-","+/-","MR","MC","x^2","sr","OFF","AC","CE","="};

int s=0,k=0,pass,op,prop,newnum=1,bt,memo=1,d=0,sq;
long double num=0,accum,m;
void normalbutton(int,int,int,int,char *);
void main()
{
int gd=DETECT,gm,x1,x2,y1,y2,i,j,maxx,maxy,x,y,button;
initgraph(&gd,&gm,"");
if(initmouse()==0)
 {
  closegraph();
  restorecrtmode();
  printf(" Mouse driver not loded");
  exit(1);
}
setcolor(2);
gotoxy(20,10);
printf("WELCOME TO ISTE
");
gotoxy(20,14);
printf("press any key to continue.......
");
getch();
cleardevice();
showmouseptr();
movemouseptr(&x,&y);
setcolor(15);
rectangle(198,140,417,163);
rectangle(199,141,418,164);
rectangle(197,139,416,162);
rectangle(185,130,430,450);
rectangle(184,129,431,451);
rectangle(182,127,433,454);
rectangle(181,126,434,453);
setfillstyle(SOLID_FILL,3);
//bar(200,142,415,161);
outtextxy(50,25,"A Calculator project in C presented by B.NARAYANA 
MOORTHY
AND  R.KARTHIK KEYAN");
outtextxy(200,100,"Press OFF button to exit....");
y1=140;
y2=160;
for(j=0;j<7;j++)
 {
  x1=200;
  x2=235;
  y1+=40;
  y2+=40;
for(i=0;i<4;i++)
{
   normalbutton(x1,x2,y1,y2,text[s]);
   s++;
   x1+=60;
   x2+=60;
   }
}
while(1)
{
getmousepos(&button,&x,&y);
y1=140;
y2=160;
for(j=0;j<7;j++)
 {
  x1=200;
  x2=235;
  y1+=40;
  y2+=40;
  for(i=0;i<4;i++)
  {
 if((x<x2&&x>x1)&&(y<y2&&y>y1))
 {
 if((button&1)==1)
  {
  gotoxy(28,10);
 bt=j*4+i;
 setcolor(11);
 outtextxy(x1+12,y1+7,text[j*4+i]);
 if(num>pow(10.0,18))
 exit();
 delay(10);
 delay(250);
 delay(10);
 switch (bt)
 {
 case  8 :
  addnum(1);
  break;
 case  9 :
  addnum(2);
  break;
 case  10 :
  addnum(3);
  break;
 case  4 :
  addnum(4);
  break;
 case  5 :
  addnum(5);
  break;
 case  6 :
  addnum(6);
  break;
 case  0 :
  addnum(7);
  break;
 case  1 :
  addnum(8);
  break;
 case  2 :
  addnum(9);
  break;
 case  12 :
  addnum(0);
  break;
 case  11 :
  operation(1);   // plus
  break;
 case  15 :
  operation(2);    // minus
  break;
 case  3 :
  operation(3);    // multiplication
  break;
 case  7 :
  operation(4);     // division
  break;
 case 13:
  doublezero();
  break;
 case  14 :
  decimal();
  break;
 case 16:
  m=m;
  printf("%25.5Lf",m); //memory call
  break;
 case 20:
  printf("%25.5Lf",m);
  break;
 case 19:
  plusminus();
  break;
 case 17:
  m=m+num;       //memory plus
  break;
 case 18:
  m=m-num;       //memory minus
  break;
 case 21:
  clearm();
  break;
 case 22 :
  square();
  break;
 case 23:
  sqroot();
  break;
 case 24:
  hidemouseptr();
  setcolor(1);
  cleardevice();
  setcolor(14);
  outtextxy(225,200,"THANK YOU");
  delay(2000);
  exit();
  break;
 case 25:
  allclear();
  break;
 case 26:
  clear();
  break;
 case 27:
  num=operation(5);        //  equalto
  break;
  }
  setcolor(1);
 outtextxy(x1+12,y1+7,text[j*4+i]);
  }
   }
 x1+=60;

 x2+=60;
}
 }
 }
}
void normalbutton(int x1,int x2,int y1,int y2,char *text)
{
setcolor(15);
rectangle(x1-2,y1-2,x2+1,y2+1);
rectangle(x1-1,y1-1,x2+2,y2+2);
setcolor(5);
rectangle(x1,y1,x2+2,y2+2);
rectangle(x1,y1,x2+1,y2+1);
setfillstyle(SOLID_FILL,14);
bar(x1,y1,x2,y2);
setcolor(1);
outtextxy(x1+12,y1+7,text);
k++;
}

initmouse()
{
 i.x.ax=0;
 int86 (0x33,&i,&o);
 return(o.x.ax);
}
hidemouseptr()
{
  i.x.ax=2;
  int86(0x33,&i,&o);
  return 0;
}

showmouseptr()
{
 i.x.ax=1;
 int86(0x33,&i,&o);
 return 0;
}
getmousepos(int *button,int *x,int *y)
{
 i.x.ax=3;
 int86(0x33,&i,&o);
 *button=o.x.bx;
 *x=o.x.cx;
 *y=o.x.dx;
 return 0;
}
/* Move mouse ptr to x,y */
movemouseptr(int *x,int *y)
{
 i.x.ax=4;
 int86(0x33,&i,&o);
 o.x.cx=*x;
 o.x.dx=*y;
 return 0;
}
addnum(int pass)
{   if(sq)
 newnum=1;

 if(newnum)
   {      if(d)
 {
   num=pass/(pow(10.0,d));
   d++;
   newnum=0;
 }
  else
 {  num=pass;
    newnum=0;
 }
   }
 else
 {
 if(d)
 {
    if(num<0)
  num=num-pass/(pow(10.0,d));
    else
  num=num+pass/(pow(10.0,d));
   d++;
 }
 else
 {
 num=num*10+pass;
 }
 }
 printf("%25.5Lf",num);
 return ;
}
operation(int opr)
{  long double pnum;
   pnum=num;

   if(newnum && (prop != 5) && memo)
   {
   }
   else
  {  newnum=1;
  d=0;
  sq=0;
  switch(prop)
 {
  case 1:
  accum=accum+pnum;
  break;
  case 2:
  accum=accum-pnum;
  break;
  case 3:
  accum=accum*pnum;
  break;
  case 4:
  accum=accum/pnum;
  break;
  default:
    accum=pnum;
  }
  }
 prop=opr;
 num=accum;
 printf("%25.5Lf",num);
 return num;
}
allclear()
{
 sq=0;
 accum=0;
 num=0;
 d=0;
 newnum=1;
 printf("%25.5Lf",num);
 return;
}
plusminus()
{ if(num!=0)
  { num*=-1;
 printf("%25.5Lf",num);
  }
  return;
}
clearm()
{
m=0;
//printf("%25.5Lf",m);
return;
}
decimal()
{
 if(!d)
 {
 d=1;
 if(newnum==1)
 {
  num=0;
 }
  printf("%25.5Lf",num);
  }
  return;
}
square()
{
sq=1;
 num*=num;
 printf("%25.5Lf",num);
return;
}
sqroot()
{ sq=1;
 num=pow(num,0.5);
 printf("%25.5Lf",num);
return;
}
doublezero()
{
 if(d)
   {
  d++;
  d++;
   }
 else
  num*=100;
 printf("%25.5Lf",num);
 return;
}
clear()
{
num=0;
printf("%25.5Lf",num);
return;
}

Customer Billing System

 #include<stdio.h>
 #include<conio.h>
 #include<stdlib.h>

 void input();
 void writefile();
 void search();
 void output();

 struct date{
  int month;
  int day;
  int year;
  };

  struct account {
int number;
char name[100];
int acct_no;
float mobile_no;
char street[100];
char city[100];
char acct_type;
float oldbalance;
float newbalance;
float payment;
struct date lastpayment;
  }customer;
  int tl,sl,ts;
 void main()
{
 int i,n;
 char ch;
 clrscr();

 _setcursortype(_NOCURSOR);
 printf("   CUSTOMER BILLING SYSTEM:\n\n");
 printf("===============================\n");
 printf("\n1:    to add account on list\n");
 printf("2:    to search customer account\n");
 printf("3:    exit\n");
 printf("\n================================\n");
 do{
      printf("\nselect what do you want to do?");
      ch=getche();
 }while(ch<='0' || ch>'3');
 switch(ch){
case '1':
clrscr();
printf("\nhow many customer accounts?");
scanf("%d",&n);
for(i=0;i<n;i++){
input();
if(customer.payment>0)
customer.acct_type=(customer.payment<0.1*customer.oldbalance)? 'O': 'D';
else
customer.acct_type=(customer.oldbalance>0)?'D' : 'C';
customer.newbalance=customer.oldbalance - customer.payment;
writefile();
}
main();
case '2':
clrscr();
printf("search by what?\n");
printf("\n1 --- search by customer number\n");
printf("2 --- search by customer name\n");
search();
ch=getche();
main();
case '3':
clrscr();
delay(700);
textcolor(BLUE);
gotoxy(25,25);
cprintf("\nA PROJECT BY VARUN");
delay(1500);
exit(1);
 }
 }


   void input()
{
 FILE *fp=fopen("bidur.dat","rb");
 fseek (fp,0,SEEK_END);
 tl=ftell(fp);
 sl=sizeof(customer);
 ts=tl/sl;
 fseek(fp,(ts-1)*sl,SEEK_SET);
 fread(&customer,sizeof(customer),1,fp);
 printf("\ncustomer no:%d\n",++customer.number);
 fclose(fp);
 printf("         Account number:");
 scanf("%d",&customer.acct_no);
 printf("\n       Name:");
 scanf("%s",customer.name);
 printf("\n       mobile no:");
 scanf("%f",&customer.mobile_no);
 printf("         Street:");
 scanf("%s",customer.street);
 printf("         City:");
 scanf("%s",customer.city);
 printf("         Previous balance:");
 scanf("%f",&customer.oldbalance);
 printf("         Current payment:");
 scanf("%f",&customer.payment);
 printf("         Payment date(mm/dd/yyyy):");
 scanf("%d/%d/%d",&customer.lastpayment.month,&customer.lastpayment.day,&customer.lastpayment.year);
 return;
   }

   void writefile()
   {
 FILE *fp;
 fp=fopen("bidur.dat","ab");
 fwrite(&customer,sizeof(customer),1,fp);
 fclose(fp);
 return;
   }

   void search()
   {
char ch;
char nam[100];
int n,i,m=1;
FILE *fp;
fp=fopen("bidur.dat","rb");
do{
printf("\nenter your choice:");
ch=getche();
}while(ch!='1' && ch!='2');
switch(ch){
     case '1':
   fseek(fp,0,SEEK_END);
   tl=ftell(fp);
   sl=sizeof(customer);
   ts=tl/sl;
   do{
printf("\nchoose customer number:");
scanf("%d",&n);
if(n<=0 || n>ts)
printf("\nenter correct\n");
else{
   fseek(fp,(n-1)*sl,SEEK_SET);
   fread(&customer,sl,1,fp);
   output();
}
printf("\n\nagain?(y/n)");
ch=getche();
   }while(ch=='y');
   fclose(fp);
   break;
     case '2':
   fseek(fp,0,SEEK_END);
   tl=ftell(fp);
   sl=sizeof(customer);
   ts=tl/sl;
   fseek(fp,(ts-1)*sl,SEEK_SET);
   fread(&customer,sizeof(customer),1,fp);
   n=customer.number;

   do{
printf("\nenter the name:");
scanf("%s",nam);
fseek(fp,0,SEEK_SET);
for(i=1;i<=n;i++)
{
    fread(&customer,sizeof(customer),1,fp);
    if(strcmp(customer.name,nam)==0)
    {
output();
m=0;
break;
    }
}
if(m!=0)
printf("\n\ndoesn't exist\n");
printf("\nanother?(y/n)");
ch=getche();
   }while(ch=='y');
   fclose(fp);
     }
     return;
}



   void output()
{
  printf("\n\n    Customer no    :%d\n",customer.number);
  printf("    Name   :%s\n",customer.name);
  printf("    Mobile no      :%.f\n",customer.mobile_no);
  printf("    Account number :%d\n",customer.acct_no);
  printf("    Street         :%s\n",customer.street);
  printf("    City           :%s\n",customer.city);
  printf("    Old balance    :%.2f\n",customer.oldbalance);
  printf("    Current payment:%.2f\n",customer.payment);
  printf("    New balance    :%.2f\n",customer.newbalance);
  printf("    Payment date   :%d/%d/%d\n\n",customer.lastpayment.month,customer.lastpayment.day,customer.lastpayment.year);
  printf("    Account status :");
  textcolor(128+RED);
  switch(customer.acct_type)
     {
     case 'C':
cprintf("CURRENT\n\n");
break;
     case 'O':
cprintf("OVERDUE\n\n");
break;
     case 'D':
cprintf("DELINQUENT\n\n");
break;
     default:
cprintf("ERROR\\n\n");
     }
     textcolor(GREEN);
     return;
  }














Wednesday, 27 April 2016

gym management system

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
struct book
{
 char name[50];
 int age;
 char address[50];
 char phn_no[50];
 char email[20];
 int plan;
 int bill;
}e;
struct yoga
{
 char name[50];
 int age;
 char phn_no[50];
 char day[20];
 int time;
}b;
main()
{
 FILE *fp ,*fd;
 int a;
 char d='y';
 char c='y';
 clrscr();
 printf("**********************WELCOME TO SILVER GYM************************ \n");
 printf("please choose any plan \n ");
 printf("1) join the gym \n ");
 printf("2) know our gym \n ");
 printf("3) create a peronal booking with our specialist yoga trainer \n ");
 printf("4) display the records \n ");
 printf("5) exit \n ");
 printf("******************************************************************* \n");
 scanf("%d",&a);
 if(a==1)
 {
   clrscr();
   fp=fopen("new.dat","w");
   if(fp==NULL)
   {
    printf("sorry cannot open file");
    sleep(3);
   }
   while(d=='y')
   {
    fflush(stdin);
    printf("enter your name \n");
    gets(e.name);
    printf("enter your age \n ");
    scanf("%d",&e.age);
    fflush(stdin);
    printf("enter your address \n");
    gets(e.address);
    fflush(stdin);
    printf("please enter your phone number \n");
    scanf("%s",&e.phn_no);
    printf("please enter your email \n ");
    scanf("%s",&e.email);
    printf("Now please choose any plan \n");
    printf("loading please wait for a moment");
    sleep(3);
    clrscr();
    printf("-------------------OUR PLANS-----------------\n");
    printf("  PLAN                          RATE  \n");
    printf("1) our wieght training plan     1000/permnth \n");
    printf("2) cardio plan                  800/permnth  \n ");
    printf("3) wieght loss plan             1000/permnth \n ");
    printf("4) special yoga plan            700/permnth  \n ");
    printf("5) dual(cardio+ wieghtlifting)  1500/permnth \n ");
    fflush(stdin);
    printf("Please choose any plan \n ");
    scanf("%d",&e.plan);
    if(e.plan==1)
    {
     e.bill=1000;
    }
    else if(e.plan==2)
    {
     e.bill=800;
    }
    else if(e.plan==3)
    {
     e.bill=1000;
    }
    else if(e.plan==4)
    {
     e.bill=700;
    }
    else if(e.plan==5)
    {
     e.bill=1500;
    }
    fwrite(&e,sizeof(e),1,fp);
    printf("do you want to enter more records (y/n)..");
    d=getch();
   }
   fclose(fp);

  }
  else if(a==2)
  {clrscr();
   printf("************************************************************** \n");
   printf(" Silver gym brings you a blend of cardio traing and weightlifting together \n ");
   printf(" we have a total of 20 qualified and certified trainers always wiling to help \n ");
   printf(" \n \n ");
   printf(" we are loacted at \t XY2/block-B paschim vihar \n");
   printf(" contact us at \t 25210510 \t 9898645 \n");
   printf("************************************************************** \n");
   sleep(10);
  }
  else if(a==3)
  {
   clrscr();
   fd=fopen("second.dat","w");
   if(fd==NULL)
   {
    printf("sorry cannot open file");
    sleep(5);
    exit(0);
   }
   while(c=='y')
   {
    fflush(stdin);
    printf("creating a personal booking with our yoga specialist MR Amit Grover \n");
    printf("\n please wait for a second ...... \n ");
    sleep(5);
    printf("enter your name \n");
    gets(b.name);
    printf("enter your age \n");
    scanf("%d",&b.name);
    printf("enter your phone no \n ");
    scanf("%s",&b.phn_no);
    printf("we are avaible from monday to saturday \n timing :10 AM to 8PM \n");
    printf("please choose day and time accordingly \n");
    fflush(stdin);
    printf("enter the day for meeting \n");
    gets(b.day);
    printf("enter the time \n");
    scanf("%d",&b.time);
    fwrite(&b,sizeof(b),1,fd);
    printf("your booking has been fixed ..please be on your selected time \n");
    sleep(1);
    printf("want to create more bookings (y/n).. \n");
    c=getch();
   }
   fclose(fd);
  }
  else if(a==4)
  {
   clrscr();
   printf("showing records for new bookings \n");
   fp=fopen("new.dat","r");
   while(fread(&e,sizeof(e),1,fp)==1)
   {
    printf("   NAME : %s",e.name);
    printf("\n AGE  : %d",e.age);
    printf("\n ADDRESS : %s",e.address);
    printf("\n PHONE NO. : %s",e.phn_no);
    printf("\n EMAIL : %s  ",e.email);
    printf("\n PLAN : %d ",e.plan);
    printf("\n RATE : %d ",e.bill);
   }
   fclose(fp);
   sleep(12);
   clrscr();
   printf("\n showing records for personal bookings with yoga specialist");
   fd=fopen("second.dat","r");
   while(fread(&b,sizeof(b),1,fd)==1)
   {
    printf("\n NAME : %s",b.name);
    printf("\n AGE  : %d",b.age);
    printf("\n PHONE NO : %s",b.phn_no);
    printf("\n DAY : %s ",b.day);
    printf("\n TIME : %d ",b.time);
   }
   fclose(fd);
   sleep(2);
  }
  else if(a==5)
  {
   exit(0);
  }
  else
  {
   printf("WRONG CHOICE");
   sleep(2);
   exit(0);
  }
}

Thursday, 21 April 2016

employment management system

/// List of library functions
#include <stdio.h> ///for input output functions like printf, scanf
#include <stdlib.h>
#include <conio.h>
#include <string.h>  ///string operations
/** Main function started */
int main(){
    FILE *fp, *ft; /// file pointers
    char another, choice;

    /** structure that represent a employee */
    struct emp{
char name[40]; ///name of employee
int age; /// age of employee
float bs; /// basic salary of employee
    };

    struct emp e; /// structure variable creation

    char empname[40]; /// string to store name of the employee

    long int recsize; /// size of each record of employee

    /** open the file in binary read and write mode
    * if the file EMP.DAT already exists then it open that file in read write mode
    * if the file doesn't exit it simply create a new copy
    */
    fp = fopen("EMP.DAT","rb+");
    if(fp == NULL){
fp = fopen("EMP.DAT","wb+");
if(fp == NULL){
   printf("Connot open file");
   exit(1);
}
    }

    /// sizeo of each record i.e. size of structure variable e
    recsize = sizeof(e);

    /// infinite loop continues untile the break statement encounter
    while(1){
system("cls"); ///clear the console window
gotoxy(30,10); /// move the cursor to postion 30, 10 from top-left corner
printf("1. Add Record"); /// option for add record
gotoxy(30,12);
printf("2. List Records"); /// option for showing existing record
gotoxy(30,14);
printf("3. Modify Records"); /// option for editing record
gotoxy(30,16);
printf("4. Delete Records"); /// option for deleting record
gotoxy(30,18);
printf("5. Exit"); /// exit from the program
gotoxy(30,20);
printf("Your Choice: "); /// enter the choice 1, 2, 3, 4, 5
fflush(stdin); /// flush the input buffer
choice  = getche(); /// get the input from keyboard
switch(choice){
   case '1':  /// if user press 1
system("cls");
fseek(fp,0,SEEK_END); /// search the file and move cursor to end of the file
/// here 0 indicates moving 0 distance from the end of the file

another = 'y';
while(another == 'y'){ /// if user want to add another record
   printf("\nEnter name: ");
   scanf("%s",e.name);
   printf("\nEnter age: ");
   scanf("%d", &e.age);
   printf("\nEnter basic salary: ");
   scanf("%f", &e.bs);

   fwrite(&e,recsize,1,fp); /// write the record in the file

   printf("\nAdd another record(y/n) ");
   fflush(stdin);
   another = getche();
}
break;
   case '2':
system("cls");
rewind(fp); ///this moves file cursor to start of the file
while(fread(&e,recsize,1,fp)==1){ /// read the file and fetch the record one record per fetch
   printf("\n%s %d %.2f",e.name,e.age,e.bs); /// print the name, age and basic salary
}
getch();
break;

   case '3':  /// if user press 3 then do editing existing record
system("cls");
another = 'y';
while(another == 'y'){
   printf("Enter the employee name to modify: ");
   scanf("%s", empname);
   rewind(fp);
   while(fread(&e,recsize,1,fp)==1){ /// fetch all record from file
if(strcmp(e.name,empname) == 0){ ///if entered name matches with that in file
   printf("\nEnter new name,age and bs: ");
   scanf("%s%d%f",e.name,&e.age,&e.bs);
   fseek(fp,-recsize,SEEK_CUR); /// move the cursor 1 step back from current position
   fwrite(&e,recsize,1,fp); /// override the record
   break;
}
   }
   printf("\nModify another record(y/n)");
   fflush(stdin);
   another = getche();
}
break;
   case '4':
system("cls");
another = 'y';
while(another == 'y'){
   printf("\nEnter name of employee to delete: ");
   scanf("%s",empname);
   ft = fopen("Temp.dat","wb");  /// create a intermediate file for temporary storage
   rewind(fp); /// move record to starting of file
   while(fread(&e,recsize,1,fp) == 1){ /// read all records from file
if(strcmp(e.name,empname) != 0){ /// if the entered record match
   fwrite(&e,recsize,1,ft); /// move all records except the one that is to be deleted to temp file
}
   }
   fclose(fp);
   fclose(ft);
   remove("EMP.DAT"); /// remove the orginal file
   rename("Temp.dat","EMP.DAT"); /// rename the temp file to original file name
   fp = fopen("EMP.DAT", "rb+");
   printf("Delete another record(y/n)");
   fflush(stdin);
   another = getche();
}
break;
   case '5':
fclose(fp);  /// close the file
exit(0); /// exit from the program
}
    }
    return 0;
}