Monday, 13 November 2017

Department store source code

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<windows.h>

#define ANS 15
#define ACS 4
 COORD coord={0,0}; // this is global variable
                                    //center of axis is set to the top left cornor of the screen
void gotoxy(int x,int y)
{
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
/*declaration of checking functions*/
void c_code(char[]);
int check(char[]);

/*structure declaration*/
typedef struct{
char name[ANS],code[ACS];
float rate;
int quantity;
}rec;
rec item;

/*declaration of display functions*/
void curser(int);
void dbill();
void d_mainmenu();
void display(rec *,int,int);
void window(int,int,int,int);
void dis_con();
void d_search();
void highlight(int,int);

/*declaration of main menu functions*/
void bill() ;
void edit();
void add();
void del();
void exit();

/*declaration of display submenu functions*/
void d_code();
void d_rate();
void d_quan();
void d_all();

/*start of main*/
int main()
{
 d_mainmenu();
 return 0;
}



void d_mainmenu()
{
 int i;
 char ch;
 const char *menu[]={"   Calculate Bill","   Add Goods","   Edit Goods","   Display All ","   Search", "   Delete Goods","   Exit"};
 system("cls");
 //textbackground(11);
 //textcolor(0);
 //_setcursortype(_NOCURSOR);
 window(25,50,20,32);
 gotoxy(33,18);printf("MAIN MENU");
 for (i=0;i<=6;i++){
  gotoxy(30,22+i+1);printf("%s\n\n\n",menu[i]);}
  curser(7);
 }

void d_search()
{
 char ch;
 int i;
    const char *menu[]={"   By Code","   By Rate","   By Quantity","   Back to main menu"};
 system("cls");
 //textbackground(11);
 //textcolor(0);
 window(25,50,20,32);
 gotoxy(33,18);printf("SEARCH MENU");
 for (i=0;i<=3;i++){
 gotoxy(30,22+i+1);printf("%s\n\n\n",menu[i]);}
 curser(4);
}

/*function for cursor movement*/
void curser(int no)
{
    int count=1;
    char ch='0';
    gotoxy(30,23);
 while(1){
  switch(ch){
   case 80:
    count++;
    if (count==no+1) count=1;
    break;
   case 72:
    count--;
    if(count==0) count=no;
    break;
  }
  highlight(no,count);
  ch=getch();
  if(ch=='\r'){
   if(no==7){
    if (count==1) bill() ;
    else if(count==2) add();
    else if(count==3) edit();
    else if (count==4) d_all();
    else if (count==5) d_search();
    else if (count==6) del();
    else   exit(0);
   }
   if(no==4){
    if (count==1) d_code();
    else if (count==2)d_rate();
    else if (count==3) d_quan();
    else d_mainmenu();
   }
  }
 }
}

void highlight(int no,int count)
{
 if (no==4){
  //textbackground(11);
  //textcolor(0);
  gotoxy(30,23);printf("   By Code          ");
  gotoxy(30,24);printf("   By Rate          ");
  gotoxy(30,25);printf("   By Quantity      ");
  gotoxy(30,26);printf("   Back to main menu");
  //textcolor(0);
  //textbackground(2);
  switch (count)
  {
   case 1:
    gotoxy(30,23);
    printf(" - By Code          ");
    break;
   case 2:
    gotoxy(30,24);
    printf(" - By Rate          ");
    break;
   case 3:
    gotoxy(30,25);
    printf(" - By Quantity      ");
    break;
   case 4:
    gotoxy(30,26);
    printf(" - Back to main menu");
    break;
  }
 }

 if(no==7){
  //textbackground(11);
  //textcolor(0);
  gotoxy (30,23);printf("   Calculate Bill ");
  gotoxy (30,24);printf("   Add Goods      ");
  gotoxy (30,25);printf("   Edit Goods     ");
  gotoxy (30,26);printf("   Display All    ");
  gotoxy (30,27);printf("   Search         ");
  gotoxy (30,28);printf("   Delete Goods   ");
  gotoxy (30,29);printf("   Exit           ");
  //textcolor(0);
  //textbackground(2);
  switch(count){
   case 1:
    gotoxy (30,23);
    printf(" - Calculate Bill ");
    break;
   case 2:
    gotoxy (30,24);
    printf(" - Add Goods      ");
    break;
   case 3:
    gotoxy (30,25);
    printf(" - Edit Goods     ");
    break;
   case 4:
    gotoxy (30,26);
    printf(" - Display All    ");
    break;
   case 5:
    gotoxy (30,27);
    printf(" - Search         ");
    break;
   case 6:
    gotoxy (30,28);
    printf(" - Delete Goods   ");
    break;
   case 7:
    gotoxy (30,29);
    printf(" - Exit           ");
    break;
  }
 }
}

void bill()
{
  char x[4]={0};
  int j=29,q=0,size=0,i=1;
  float total=0,gtotal=0;
  FILE *file;
  file=fopen("record.txt","r+b");
  rewind(file);
  system("cls");
  dbill();
  gotoxy(26,15);printf("enter  \"end\" to finish input");
  while(1){
  gotoxy(25,18);printf("                    ");
  gotoxy(25,19);printf("                    ");
  gotoxy(25,18);printf("enter item code:");
  scanf("%s",x);
  if(strcmp(x,"end")==0)
   break;
  gotoxy(25,19);printf("enter quantity:");
  scanf("%d",&q);
  rewind(file);
  while(fread(&item,sizeof(item),1,file)){
   if((strcmp(item.code,x)==0)){
    total=item.rate*q;
    gotoxy(11,j);printf("%4d",i);
    printf("%9s",item.name);
    printf("%13d",q);
    printf("%15.2f",item.rate);
    printf("%13.2f",total);
    gtotal=gtotal+total;
    size=sizeof(item);
    item.quantity=item.quantity-q;
    j+=2; i++;
    fseek(file,-size,SEEK_CUR);fwrite(&item,sizeof(item),1,file);
    break;
   }
    }
 }
 if(gtotal!=0){
  gotoxy(30,j+5);
  printf("TOTAL AMOUNT = NRs. %6.2f",gtotal);
 }
 fclose(file);
 getch();
 d_mainmenu();
}
 /*function to display bill window*/
void dbill()
{
 int i;
 gotoxy(20,10);
 //;
 for (i=1;i<=10;i++)
  printf("*");
 printf(" * FASHION WEAR * ");
 for (i=1;i<=10;i++)
        printf("*");
 printf("\n\n");
 gotoxy(30,11);printf("Departmental Store");
 //textcolor(1);
 gotoxy(32,25);printf("CUSTOMER'S BILL") ;
 //textcolor(8);
 gotoxy(13,27);printf("SN.   Item Name     Quantity     Rate          Total");

}
/*function to add records*/
void add ()
{
 FILE *file;
 char y[ACS],x[12];
 system("cls");
 //textbackground(11);
 //textcolor(0);
 gotoxy(25,25);printf("Enter new record(Y/N)?");
 while(toupper(getche())=='Y'){
  system("cls");
  file=fopen("record.txt","ab");
  c_code(y);
  strcpy(item.code,y);
  gotoxy(22,28);printf("Enter rate of the item:");
  scanf("%f",&item.rate);
  gotoxy(22,30);printf("Enter quantity of the item:");
  scanf("%d",&item.quantity);
  gotoxy(22,32);printf("Enter name of the item:");
  scanf("%s",item.name);
  fseek(file,0,SEEK_END);fwrite(&item,sizeof(item),1,file);
  fclose(file);
  gotoxy(22,34);printf("Enter new record(Y/N)?");

   }
   d_mainmenu();
}

 /*function to check availability of code*/
void c_code(char y[])
{
 int flag;
 FILE *file;
 file=fopen("record.txt","rb");
 while(1){
  system("cls");
  window(20,58,23,36);
  gotoxy(32,18);printf(" ADD ARTICLES ")  ;
  flag=1;
  rewind(file);
  gotoxy(22,25);printf("Enter new code of the article:");
  scanf(" %[^\n]",y);
  while(fread(&item,sizeof(item),1,file)==1){
   if (strcmp(y,item.code)==0){
    flag=0;
    gotoxy(26,30);printf("code already exists");
    gotoxy(29,32);printf("enter again");getch();
    break;
   }
  }
  if (flag==1)
  break;
 }
}

/*function for editing*/
void edit()
{
 int flag=0,choice;
 char x[ACS],y[ACS];
 FILE *file;
 int size;
 system("cls");
 //textcolor(0);
 //textbackground(11);
 window(20,63,20,46);
 gotoxy(35,18);printf("EDIT RECORDS");
 ;
 gotoxy(25,23);printf("enter item code: ");
 scanf("%s",x);
 flag=check(x);
 if(flag==0){
  file=fopen("record.txt","r+b");
  rewind(file);
  while (fread(&item,sizeof (item),1,file)){
   if(strcmp(item.code,x)==0){
    //textcolor(0);
    gotoxy(25,27);printf("name       = %s",item.name);
    gotoxy(25,28);printf("code       = %s",item.code);
    gotoxy(25,29);printf("rate       = %g",item.rate);
    gotoxy(25,30);printf("quantity   = %d",item.quantity);
    gotoxy(25,32);; printf("do you want to edit this record(y/n):");
    fflush(file);
    if(toupper(getche())=='Y'){
     //textcolor(0);
     gotoxy(25,34); printf("1- edit name ");
     gotoxy(25,35); printf("2- edit code ");
     gotoxy(25,36); printf("3- edit rate ");
     gotoxy(25,37); printf("4- edit quantity ");
     gotoxy(25,39);  ; printf(" enter your choice(1, 2, 3, 4) ");
     scanf("%d",&choice);
     switch(choice){
      case 1:
       system("cls");
       window(23,48,20,40);
       gotoxy(35,18);printf("EDIT RECORDS");
       gotoxy(25,24); printf(" enter new name: ");
       scanf("%s",item.name);
       size=sizeof(item);
       fseek(file,-size,SEEK_CUR);fwrite(&item,sizeof(item),1,file);
       break;
      case 2:
       system("cls");
       window(23,65,20,40);
       gotoxy(35,18);printf("EDIT RECORDS");
       gotoxy(25,24);
       c_code(y);
       strcpy(item.code,y);
       size=sizeof(item);
       fseek(file,-size,SEEK_CUR);fwrite(&item,sizeof(item),1,file);
       break;
      case 3:
       system("cls");
       window(23,65,20,40);
       gotoxy(35,18);printf("EDIT RECORDS");
       gotoxy(25,24);
       printf(" enter new rate: ");
       scanf("%f",&item.rate);
       size=sizeof(item);
       fseek(file,-size,SEEK_CUR);fwrite(&item,sizeof(item),1,file);
       break;
      case 4:
       system("cls");
       window(23,65,20,40);
       gotoxy(35,18);printf("EDIT RECORDS");
       gotoxy(25,24);
       printf(" enter new quantity: ");
       scanf("%d",&item.quantity);
       size=sizeof(item);
       fseek(file,-size,1);fwrite(&item,sizeof(item),1,file);
       break;
     }
     gotoxy(27,30);printf("--- item edited---");
     break;
    }
   }
  }
 }
 if (flag==1){
  gotoxy(32,30);printf("item does not exist");
  gotoxy(36,32);printf("TRY ABGAIN");
 }
 getch();
 fclose(file);
 d_mainmenu();
}

/*function to display all records*/
void d_all()
{
 int i,j=1;
 FILE *file;
 dis_con();
 file=fopen("record.txt","rb");
 rewind(file);
 i=26;
 fflush(file);
 while(fread(&item,sizeof(item),1,file)){
  display(&item,i,j);
  i++;
  j++;
  if ((j%20)==0){
         gotoxy(27,47);/*textcolor(0)*/;printf("press any key to see more...........");
         getch();
         system("cls");
         dis_con();
         i=26;
         continue;
  }
  }
  getch();
  if (i==26) {
  gotoxy(24,30); printf("-- no articles found --");
 }
 getch();
 fclose(file);
 d_mainmenu();
}

/*function to display by quantity*/
void d_quan()
{
  int i,j=1;
  int a,b;
  FILE *file;
  dis_con();
  file=fopen("record.txt","rb");
  rewind(file);
  i=26;
  gotoxy(16,20);;printf("enter lower range: ");
  scanf("%d",&a);
  gotoxy(16,21);printf("enter upper range:");
  scanf("%d",&b);
  fflush(file);
  while(fread(&item,sizeof(item),1,file)){
  if((item.quantity>=a)&&(item.quantity<=b)){
   display(&item,i,j);
   i++;
   j++;
   if ((j%20)==0){
    gotoxy(27,47);printf("press any key to see more...........");
    getch();
    system("cls");
    dis_con();
    i=26;
    continue;
   }
     }
  }
  getch();
  if (i==26){
  gotoxy(28,30); printf(" no item found ");
 }
 getch();
 d_search();
 fclose(file);
}

/*function to display by rate*/
void d_rate(){
  int i,j=1;
  float a,b;
  FILE *file;
  dis_con();
  file=fopen("record.txt","rb");
  rewind(file);
  i=26;
  gotoxy(16,20);;printf("enter lower range: ");
  scanf("%f",&a);
  gotoxy(16,21);printf("enter upper range: ");
  scanf("%f",&b);
  fflush(file);
  while(fread(&item,sizeof(item),1,file)){
  if((item.rate>=a)&&(item.rate<=b)){
   display(&item,i,j);
   i++;
   j++;
   if ((j%20)==0){
    gotoxy(27,47);printf("press any key to see more...........");
    getch();
    system("cls");
    dis_con();
    i=26;
    continue;
   }
  }
  }
 getch();
 if (i==26){
  gotoxy(28,30); printf(" no item found ");
 }
 getch();
 fclose(file);
 d_search();
}

/*function to display by code*/
void d_code()
{
  int i,j=1;
  char x[4]={0};
  FILE *file;
  dis_con();
  file=fopen("record.txt","rb");
  rewind(file);
  i=26;
  gotoxy(16,20);;printf("enter item code: ");
  scanf("%s",x);
  fflush(file);
  while(fread(&item,sizeof(item),1,file)){
  if((strcmp(item.code,x)==0)){
   display(&item,i,j);
   i++;
   j++;
   break;
  }
  }
  if (i==26){
  gotoxy(28,30); printf("no item found");
  }
  getch();
  fclose(file);
  d_search();
}

/*function to display window for item display*/
void dis_con()
{
 int i;
 system("cls");
 gotoxy(20,10);
 ;
 for (i=1;i<=10;i++)
  printf("*");
 printf(" * FASHION WEAR * ");
 for (i=1;i<=10;i++)
        printf("*");
 printf("\n\n");
 gotoxy(30,11);printf("Departmental Store");
 //textcolor(1);
 gotoxy(32,17);printf("RECORDS") ;
 //textcolor(8);
 gotoxy(18,23);printf ("SN   Item Name   Item Code      Rate     Quantity");
}

/*function to display in screen*/
void display(rec *item,int i,int j)
{
 gotoxy(16,i);//textcolor(13);
 printf("%4d",j);
 printf("%9s",item->name);
 printf("%12s",item->code);
 printf("%14.2f",item->rate);
 printf("%11d",item->quantity);
}

/*function to delete records*/
void del()
{
 int flag;
 char x[ANS];
 FILE *file,*file1;
 system("cls");
 //textbackground(11);
 //textcolor(0);
 window(23,51,25,34);
 gotoxy(29,18);printf("DELETE ARTICLES");
 gotoxy(27,27);printf("enter item code: ");
 scanf("%s",x);
 flag=check(x);
 if(flag==0){
  file1=fopen("record1.txt","ab");
  file=fopen("record.txt","rb");
  rewind(file);
  while (fread(&item,sizeof (item),1,file)){
   if(strcmp(item.code,x)!=0)
    fwrite(&item,sizeof(item),1,file1);
  }
  gotoxy(27,29);printf("---item deleted---");
  remove("record.txt");
  rename("record1.txt","record.txt");
 }
 if (flag==1){
  gotoxy(25,29);printf("---item does not exist---");
  gotoxy(30,31);printf("TRY AGAIN");
 }
 fclose(file1);
 fclose(file);
 getch();
 d_mainmenu();
}

/*function to check validity of code while editing and deleting*/
int check(char x[ANS])
{
 FILE *file;
 int flag=1;
 file=fopen("record.txt","rb");
 rewind(file);
 while (fread(&item,sizeof (item),1,file)){
  if(strcmp(item.code,x)==0){
   flag=0;
   break;
  }
 }
 fclose(file);
 return flag;
 }

/*function to display box*/
void window(int a,int b,int c,int d)
{
 int i;
 system("cls");
 gotoxy(20,10);
 //textcolor(1);
 for (i=1;i<=10;i++)
  printf("*");
 printf(" * FASHION WEAR * ");
 for (i=1;i<=10;i++)
        printf("*");
 printf("\n\n");
 gotoxy(30,11);printf("Departmental Store");
 //textcolor(4);
 for (i=a;i<=b;i++){
        gotoxy(i,17);printf("\xcd");
        gotoxy(i,19);printf("\xcd");
        gotoxy(i,c);printf("\xcd");
        gotoxy(i,d);printf("\xcd");
        }

 gotoxy(a,17);printf("\xc9");
 gotoxy(a,18);printf("\xba");
 gotoxy(a,19);printf("\xc8");
 gotoxy(b,17);printf("\xbb");
 gotoxy(b,18);printf("\xba");
 gotoxy(b,19);printf("\xbc");
 //textcolor(4);
 for(i=c;i<=d;i++){
  gotoxy(a,i);printf("\xba");
  gotoxy(b,i);printf("\xba");
 }
 gotoxy(a,c);printf("\xc9");
 gotoxy(a,d);printf("\xc8");
 gotoxy(b,c);printf("\xbb");
 gotoxy(b,d);printf("\xbc");
 //textbackground(11);
 //textcolor(0);
}









mini project "Quiz" in C

#include<stdio.h>
#include<conio.h>
#include <windows.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>

void displayscore()
 {
 char name[20];
 float s;
 FILE *f;
 system("cls");
 f=fopen("score.txt","r");
 fscanf(f,"%s%f",&name,&s);
 printf("\n\n\t\t ");
 printf("\n\n\t\t %s has secured the Highest Score %.2f",name,s);
 printf("\n\n\t\t ");
 fclose(f);
 getch();
 }



void help()
 {
 system("cls");
 printf("\n\n\n\tThis game is very easy to play. You'll be asked some general");
 printf("\n\n\tknowledge questions and the right answer is to be chosen among");
 printf("\n\n\tthe four options provided. Your score will be calculated at the");
 printf("\n\n\tend. Remember that the more quicker you give answer the more");
 printf("\n\n\tscore you will secure. Your score will be calculated and displayed");
 printf("\n\n\tat the end and displayed. If you secure highest score, your score");
 printf("\n\n\twill be recorded. So BEST OF LUCK.");
 }
void writescore(float score, char plnm[20])
 {
 float sc;
 char nm[20];
 FILE *f;
 system("cls");
 f=fopen("score.txt","r");
 fscanf(f,"%s%f",&nm,&sc);
 if (score>=sc)
   { sc=score;
     fclose(f);
     f=fopen("score.txt","w");
     fprintf(f,"%s\n%.2f",plnm,sc);
     fclose(f);
   }
 }
int main()
     {
     int countq,countr;
     int r,i;
     int pa;int nq[6];int w;
     float score;
     char choice;
     char playername[20];
     time_t initialtime,finaltime;
     system("cls");
     //randomize();
     mainhome:
     system("cls");
     puts("\n\t\t WELCOME TO I.Q. TEST PROGRAM\n\n") ;
     puts("\n\t\t-------------------------------");
     puts("\n\t\t Enter 'S' to start game       ");
     puts("\n\t\t Enter 'V' to view high score  ");
     puts("\n\t\t Enter 'H' for help            ");
     puts("\n\t\t Enter 'Q' to quit             ");
     printf("\n\t\t-------------------------------\n\n\t\t  ");
     choice=toupper(getch());
     if (choice=='V')
 {
 displayscore();
 goto mainhome;
 }
     else if (choice=='Q')
 exit(1);
     else if (choice=='H')
 {
 help();
 getch();
 goto mainhome;
 }
    else if(choice=='S'){
     system("cls");

     printf("\n\n\n\t\t\tEnter your name...");
     printf("\n\t\t\t(only one word)\n\n\t\t\t");
     gets(playername);

     home:
     system("cls");
     initialtime=time(NULL);
     countq=countr=0;
     i=1;
     start:
     srand ( time(NULL) );
     r=rand()%23+1;
     nq[i]=r;
     for (w=0;w<i;w++)
 if (nq[w]==r) goto start;

     switch(r)
  {
  case 1:
  printf("\n\nWhat is the maximum no. of asymptotes of the curve x^4+2x+6=0?");
  printf("\n\nA.4\tB.3\n\nC.none\tD.infinite\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.4");break;}

  case 2:
  printf("\n\n\nHow many points are possible in a compound pendulum about which");
  printf("time period is same?");
  printf("\n\nA.4\tB.2\n\nC.none\tD.infinite\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         printf("\n\nWrong!!! The correct answer is A.4");
  break;

  case 3:
  printf("\n\n\nWho was the first US President?");
  printf("\n\nA.Richard Nikson\tB.Abraham Linkon\n\nC.John F. Kennedy\tD.George Washington\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.George Washington");break;}


  case 4:
  printf("\n\n\nWho was awarded the 'Man of the Tournament' of ICC WORLD CUP 2007?");
  printf("\n\nA.Glen Magrath\tB.Mahela Jawardan\n\nC.Mathew Hayden\tD.Sachin Tendulkar\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Glen Magrath");break;}


  case 5:
  printf("\n\n\nWhich country won the Fifa World Cup 1998?");
  printf("\n\nA.France\tB.Brazil\n\nC.Italy\tD.England\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.France");break;}

  case 6:
  printf("\n\n\nWhich syllabe is stressed in the word 'democracy'?");
  printf("\n\nA.1st\tB.2nd\n\nC.3rd\tD.4th\n\n");
  countq++;
  if (toupper(getch())=='B' )
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is B.2nd");break;}


  case 7:
  printf("\n\n\nWhich country was the winner of Cricket World Cup 1987?");
  printf("\n\nA.West Indies\tB.India\n\nC.Australia\tD.England\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Australia");break;}


  case 8:
  printf("\n\n\nWhat is the height of Mount everest in feet?");
  printf("\n\nA.8648\tB.6648\n\nC.8884\tD.8848\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.8848");break;}


  case 9:
  printf("\n\n\nWhat is the capital of Denmark?");
  printf("\n\nA.Copenhagen\tB.Helsinki\n\nC.Rome\t\tD.Madrid\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Copenhagen");break;}


  case 10:
  printf("\n\n\nWhich syllabe is stressed in the word 'instanteneous'?");
  printf("\n\nA.1st\tB.2nd\n\nC.3rd\tD.4th\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.3rd");break;}


  case 11:
  printf("\n\n\nWho was the only player to score 6 successive sixes in an over?");
  printf("\n\nA.Adam Gilchrist\tB.M.S.Dhoni\n\nC.Herschel Gibbs\tD.Sanath Jayasurya\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Herschel Gibbs");break;}

  case 12:
  printf("\n\n\nWho was the only player to take 4 successive wickets?");
  printf("\n\nA.Malinga Bandara\tB.Lasith Malinga\n\nC.Bret Lee\tD.Murali Daran\n\n");
  countq++;
  if (toupper(getch())=='B')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is B.Lasith Malinga");break;}

  case 13:
  printf("\n\n\nWhich country is hosting the Fifa World Cup 2010?");
  printf("\n\nA.South Africa\tB.Italy\n\nC.Argentina\tD.Spain\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.South Africa");break;}

  case 14:
  printf("\n\n\nWho is the author of 'Pulpasa Cafe'?");
  printf("\n\nA.Narayan Wagle\tB.Lal Gopal Subedi\n\nC.B.P. Koirala\tD.Khagendra Sangraula\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Narayan Wagle");break;}

  case 15:
  printf("\n\n\nWhich country is Maria Sarapova from?");
  printf("\n\nA.Russia\tB.Switzerland\n\nC.Argentina\tD.Spain\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Russia");break;}

  case 16:
  printf("\n\n\nWho was awarded the youngest player award in Fifa World Cup 2006?");
  printf("\n\nA.Wayne Rooney\tB.Lucas Podolski\n\nC.Lionel Messi\tD.Christiano Ronaldo\n\n");
  countq++;
  if (toupper(getch())=='B')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is B.Lucas Podolski");break;}


  case 17:
  printf("\n\n\nWhat is the smallest district of Nepal?");
  printf("\n\nA.Lalitpur\tB.Karnali\n\nC.Bhaktapur\tD.Gulmi\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Bhaktapur");break;}

  case 18:
  printf("\n\n\nWhat is the headquarter of Western Development Region?");
  printf("\n\nA.Dhankuta\tB.Kathmandu\n\nC.Dhangadhi\tD.Pokhara\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.Pokhara");break;}

  case 19:
  printf("\n\n\nWhich place is called 'The Cherrapunji of Nepal'?");
  printf("\n\nA.Dharan\tB.Kathmandu\n\nC.Pokhara\tD.Butwal\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Pokhara");break;}

  case 20:
  printf("\n\n\nWhich city is known at 'The City of Seven Hills'?");
  printf("\n\nA.Rome\tB.Vactican City\n\nC.Madrid\tD.Berlin\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Rome");break;}

  case 21:
  printf("\n\n\nWho was the F1 racing champion of 2006?");
  printf("\n\nA.Louis Hamilton\tB.Felipe Massa\n\nC.Fernando Alonso\tD.Michael Schumaker\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Fernanda Alonso");break;}

  case 22:
  printf("\n\n\nWho won the Women Australian Open 2007?");
  printf("\n\nA.Martina Hingis\tB.Maria Sarapova\n\nC.Kim Clijster\tD.Serena Williams\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.Serena Williams");break;}

  case 23:
  printf("\n\n\nName the country where there no mosquito is found?");
  printf("\n\nA.Germany\tB.Spain\n\nC.Japan\tD.France\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.France");break;}



  }
 i++;
 if (i<=5) goto start;
 finaltime=time(NULL);
 score=(float)countr/countq*100-difftime(finaltime,initialtime)/3;
 if (score<0) score=0;
 printf("\n\n\nYour Score: %.2f",score);
 if (score==100) printf("\n\nEXCELLENT!!! KEEP IT UP");
 else if (score>=80 && score<100) printf("\n\nVERY GOOD!!");
 else if (score>=60 &&score<80) printf("\n\nGOOD! BUT YOU NEED TO KNOW MORE.");
 else if (score>=40 && score<60) printf("\n\nSATISFACTORY RESULT, BUT THIS MUCH IS MUCH SUFFICIENT.");
 else printf("\n\nYOU ARE VERY POOR IN G.K.,WORK HARD");
 puts("\n\nNEXT PLAY?(Y/N)");
 if (toupper(getch())=='Y')
  goto home;
 else
  {
  writescore(score,playername);
  goto mainhome;
  }
 }
     else
 {
 printf("\n\n\t\t  Enter the right key\n\n\t\t  ");
 Sleep(700);
 goto mainhome;
 }
 return 0;
}

Sunday, 12 November 2017

Mini project snake game in c

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include<time.h>
#include<ctype.h>
#include <time.h>
#include <windows.h>
#include <process.h>

#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77

int length;
int bend_no;
int len;
char key;
void record();
void load();
int life;
void Delay(long double);
void Move();
void Food();
int Score();
void Print();
void gotoxy(int x, int y);
void GotoXY(int x,int y);
void Bend();
void Boarder();
void Down();
void Left();
void Up();
void Right();
void ExitGame();
int Scoreonly();

struct coordinate{
    int x;
    int y;
    int direction;
};

typedef struct coordinate coordinate;

coordinate head, bend[500],food,body[30];

int main()
{

    char key;

    Print();

    system("cls");

    load();

    length=5;

    head.x=25;

    head.y=20;

    head.direction=RIGHT;

    Boarder();

    Food(); //to generate food coordinates initially

    life=3; //number of extra lives

    bend[0]=head;

    Move();   //initialing initial bend coordinate

    return 0;

}

void Move()
{
    int a,i;

    do{

        Food();
        fflush(stdin);

        len=0;

        for(i=0;i<30;i++)

        {

            body[i].x=0;

            body[i].y=0;

            if(i==length)

            break;

        }

        Delay(length);

        Boarder();

        if(head.direction==RIGHT)

            Right();

        else if(head.direction==LEFT)

            Left();

        else if(head.direction==DOWN)

            Down();

        else if(head.direction==UP)

            Up();

        ExitGame();

    }while(!kbhit());

    a=getch();

    if(a==27)

    {

        system("cls");

        exit(0);

    }
    key=getch();

    if((key==RIGHT&&head.direction!=LEFT&&head.direction!=RIGHT)||
(key==LEFT&&head.direction!=RIGHT&&head.direction!=LEFT)||
(key==UP&&head.direction!=DOWN&&head.direction!=UP)|
|(key==DOWN&&head.direction!=UP&&head.direction!=DOWN))

    {

        bend_no++;

        bend[bend_no]=head;

        head.direction=key;

        if(key==UP)

            head.y--;

        if(key==DOWN)

            head.y++;

        if(key==RIGHT)

            head.x++;

        if(key==LEFT)

            head.x--;

        Move();

    }

    else if(key==27)

    {

        system("cls");

        exit(0);

    }

    else

    {

        printf("\a");

        Move();

    }
}

void gotoxy(int x, int y)
{

 COORD coord;

 coord.X = x;

 coord.Y = y;

 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}
void GotoXY(int x, int y)
{
    HANDLE a;
    COORD b;
    fflush(stdout);
    b.X = x;
    b.Y = y;
    a = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(a,b);
 }
void load(){
    int row,col,r,c,q;
    gotoxy(36,14);
    printf("loading...");
    gotoxy(30,15);
    for(r=1;r<=20;r++){
    for(q=0;q<=100000000;q++);//to display the character slowly
    printf("%c",177);}
    getch();
}
void Down()
{
    int i;
    for(i=0;i<=(head.y-bend[bend_no].y)&&len<length;i++)
    {
        GotoXY(head.x,head.y-i);
        {
            if(len==0)
                printf("v");
            else
                printf("*");
        }
        body[len].x=head.x;
        body[len].y=head.y-i;
        len++;
    }
    Bend();
    if(!kbhit())
        head.y++;
}
void Delay(long double k)
{
    Score();
    long double i;
    for(i=0;i<=(10000000);i++);
}
void ExitGame()
{
    int i,check=0;
    for(i=4;i<length;i++)   //starts with 4 because it needs minimum 4 element to touch its own body
    {
        if(body[0].x==body[i].x&&body[0].y==body[i].y)
        {
            check++;    //check's value increases as the coordinates of head is equal to any other body coordinate
        }
        if(i==length||check!=0)
            break;
    }
    if(head.x<=10||head.x>=70||head.y<=10||head.y>=30||check!=0)
    {
        life--;
        if(life>=0)
        {
            head.x=25;
            head.y=20;
            bend_no=0;
            head.direction=RIGHT;
            Move();
        }
        else
        {
            system("cls");
            printf("All lives completed\nBetter Luck Next Time!!!\nPress any key to quit the game\n");
            record();
            exit(0);
        }
    }
}
void Food()
{
    if(head.x==food.x&&head.y==food.y)
    {
        length++;
        time_t a;
        a=time(0);
        srand(a);
        food.x=rand()%70;
        if(food.x<=10)
            food.x+=11;
        food.y=rand()%30;
        if(food.y<=10)

            food.y+=11;
    }
    else if(food.x==0)/*to create food for the first time coz global variable are initialized with 0*/
    {
        food.x=rand()%70;
        if(food.x<=10)
            food.x+=11;
        food.y=rand()%30;
        if(food.y<=10)
            food.y+=11;
    }
}
void Left()
{
    int i;
    for(i=0;i<=(bend[bend_no].x-head.x)&&len<length;i++)
    {
        GotoXY((head.x+i),head.y);
       {
                if(len==0)
                    printf("<");
                else
                    printf("*");
        }
        body[len].x=head.x+i;
        body[len].y=head.y;
        len++;
    }
    Bend();
    if(!kbhit())
        head.x--;

}
void Right()
{
    int i;
    for(i=0;i<=(head.x-bend[bend_no].x)&&len<length;i++)
    {
        //GotoXY((head.x-i),head.y);
        body[len].x=head.x-i;
        body[len].y=head.y;
        GotoXY(body[len].x,body[len].y);
        {
            if(len==0)
                printf(">");
            else
                printf("*");
        }
        /*body[len].x=head.x-i;
        body[len].y=head.y;*/
        len++;
    }
    Bend();
    if(!kbhit())
        head.x++;
}
void Bend()
{
    int i,j,diff;
    for(i=bend_no;i>=0&&len<length;i--)
    {
            if(bend[i].x==bend[i-1].x)
            {
                diff=bend[i].y-bend[i-1].y;
                if(diff<0)
                    for(j=1;j<=(-diff);j++)
                    {
                        body[len].x=bend[i].x;
                        body[len].y=bend[i].y+j;
                        GotoXY(body[len].x,body[len].y);
                        printf("*");
                        len++;
                        if(len==length)
                            break;
                    }
                else if(diff>0)
                    for(j=1;j<=diff;j++)
                    {
                        /*GotoXY(bend[i].x,(bend[i].y-j));
                        printf("*");*/
                        body[len].x=bend[i].x;
                        body[len].y=bend[i].y-j;
                        GotoXY(body[len].x,body[len].y);
                        printf("*");
                        len++;
                        if(len==length)
                            break;
                    }
            }
        else if(bend[i].y==bend[i-1].y)
        {
            diff=bend[i].x-bend[i-1].x;
            if(diff<0)
                for(j=1;j<=(-diff)&&len<length;j++)
                {
                    /*GotoXY((bend[i].x+j),bend[i].y);
                    printf("*");*/
                    body[len].x=bend[i].x+j;
                    body[len].y=bend[i].y;
                    GotoXY(body[len].x,body[len].y);
                        printf("*");
                   len++;
                   if(len==length)
                           break;
               }
           else if(diff>0)
               for(j=1;j<=diff&&len<length;j++)
               {
                   /*GotoXY((bend[i].x-j),bend[i].y);
                   printf("*");*/
                   body[len].x=bend[i].x-j;
                   body[len].y=bend[i].y;
                   GotoXY(body[len].x,body[len].y);
                       printf("*");
                   len++;
                   if(len==length)
                       break;
               }
       }
   }
}
void Boarder()
{
   system("cls");
   int i;
   GotoXY(food.x,food.y);   /*displaying food*/
       printf("F");
   for(i=10;i<71;i++)
   {
       GotoXY(i,10);
           printf("!");
       GotoXY(i,30);
           printf("!");
   }
   for(i=10;i<31;i++)
   {
       GotoXY(10,i);
           printf("!");
       GotoXY(70,i);
       printf("!");
   }
}
void Print()
{
   //GotoXY(10,12);
   printf("\tWelcome to the mini Snake game.(press any key to continue)\n");
  getch();
   system("cls");
   printf("\tGame instructions:\n");
   printf("\n-> Use arrow keys to move the snake.\n\n-> You will be provided foods at the several coordinates of the screen which you have to eat. Everytime you eat a food the length of the snake will be increased by 1 element and thus the score.\n\n-> Here you are provided with three lives. Your life will decrease as you hit the wall or snake's body.\n\n-> YOu can pause the game in its middle by pressing any key. To continue the paused game press any other key once again\n\n-> If you want to exit press esc. \n");
   printf("\n\nPress any key to play game...");
   if(getch()==27)
   exit(0);
}
void record(){
   char plname[20],nplname[20],cha,c;
   int i,j,px;
   FILE *info;
   info=fopen("record.txt","a+");
   getch();
   system("cls");
   printf("Enter your name\n");
   scanf("%[^\n]",plname);
   //************************
   for(j=0;plname[j]!='\0';j++){ //to convert the first letter after space to capital
   nplname[0]=toupper(plname[0]);
   if(plname[j-1]==' '){
   nplname[j]=toupper(plname[j]);
   nplname[j-1]=plname[j-1];}
   else nplname[j]=plname[j];
   }
   nplname[j]='\0';
   //*****************************
   //sdfprintf(info,"\t\t\tPlayers List\n");
   fprintf(info,"Player Name :%s\n",nplname);
    //for date and time

   time_t mytime;
  mytime = time(NULL);
  fprintf(info,"Played Date:%s",ctime(&mytime));
     //**************************
     fprintf(info,"Score:%d\n",px=Scoreonly());//call score to display score
     //fprintf(info,"\nLevel:%d\n",10);//call level to display level
   for(i=0;i<=50;i++)
   fprintf(info,"%c",'_');
   fprintf(info,"\n");
   fclose(info);
   printf("wanna see past records press 'y'\n");
   cha=getch();
   system("cls");
   if(cha=='y'){
   info=fopen("record.txt","r");
   do{
       putchar(c=getc(info));
       }while(c!=EOF);}
     fclose(info);
}
int Score()
{
   int score;
   GotoXY(20,8);
   score=length-5;
   printf("SCORE : %d",(length-5));
   score=length-5;
   GotoXY(50,8);
   printf("Life : %d",life);
   return score;
}
int Scoreonly()
{
int score=Score();
system("cls");
return score;
}
void Up()
{
   int i;
   for(i=0;i<=(bend[bend_no].y-head.y)&&len<length;i++)
   {
       GotoXY(head.x,head.y+i);
       {
           if(len==0)
               printf("^");
           else
               printf("*");
       }
       body[len].x=head.x;
       body[len].y=head.y+i;
       len++;
   }
   Bend();
   if(!kbhit())
       head.y--;
}
















Mini project "library management" in C programming

//list of header files
#include <windows.h>
#include<stdio.h>                   //contains printf,scanf etc
#include<conio.h>                   //contains delay(),getch(),gotoxy(),etc.
#include <stdlib.h>
#include<string.h>                  //contains strcmp(),strcpy(),strlen(),etc
#include<ctype.h>                   //contains toupper(), tolower(),etc
#include<dos.h>                     //contains _dos_getdate
#include<time.h>
//#include<bios.h>                   //contains  show_mouse();

#define RETURNTIME 15

//list of function prototype
char catagories[][15]={"Computer","Electronics","Electrical","Civil","Mechnnical","Architecture"};
void returnfunc(void);
void mainmenu(void);
void addbooks(void);
void deletebooks(void);
void editbooks(void);
void searchbooks(void);
void issuebooks(void);
void viewbooks(void);
void closeapplication(void);
int  getdata();
int  checkid(int);
int t(void);
//void show_mouse(void);
void Password();
void issuerecord();
void loaderanim();

COORD coord = {0, 0}; // sets coordinates to 0,0
//COORD max_buffer_size = GetLargestConsoleWindowSize(hOut);
COORD max_res,cursor_size;
void gotoxy (int x, int y)
{
        coord.X = x; coord.Y = y; // X and Y coordinates
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void delay(unsigned int mseconds)
{
    clock_t goal = mseconds + clock();
    while (goal > clock());
}
//list of global files that can be acceed form anywhere in program
FILE *fp,*ft,*fs;

//list of global variable
int s;
char findbook;
char password[10]={"pokhara"};


struct meroDate
{
    int mm,dd,yy;
};
struct books
{
    int id;
    char stname[20];
    char name[20];
    char Author[20];
    int quantity;
    float Price;
    int count;
    int rackno;
    char *cat;
    struct meroDate issued;
    struct meroDate duedate;
};
struct books a;
int main()

{
      Password();
      getch();
   return 0;

}
void mainmenu()
{
//loaderanim();
    system("cls");
       // textbackground(13);
int i;
gotoxy(20,3);
printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2 MAIN MENU \xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
//show_mouse();
gotoxy(20,5);
printf("\xDB\xDB\xDB\xDB\xB2 1. Add Books   ");
gotoxy(20,7);
printf("\xDB\xDB\xDB\xDB\xB2 2. Delete books");
gotoxy(20,9);
printf("\xDB\xDB\xDB\xDB\xB2 3. Search Books");
gotoxy(20,11);
printf("\xDB\xDB\xDB\xDB\xB2 4. Issue Books");
gotoxy(20,13);
printf("\xDB\xDB\xDB\xDB\xB2 5. View Book list");
gotoxy(20,15);
printf("\xDB\xDB\xDB\xDB\xB2 6. Edit Book's Record");
gotoxy(20,17);
printf("\xDB\xDB\xDB\xDB\xB2 7. Close Application");
gotoxy(20,19);
printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
gotoxy(20,20);
t();
gotoxy(20,21);
printf("Enter your choice:");
switch(getch())
{
case '1':
addbooks();
break;
case '2':
deletebooks();
break;
case '3':
searchbooks();
    break;
case '4':
issuebooks();
    break;
    case '5':
viewbooks();
break;
    case '6':
editbooks();
break;
    case '7':
    {
system("cls");
gotoxy(16,3);
printf("Programmers....");
gotoxy(16,4);
printf("1. Bibek Subedi       (066/BCT/506)");
gotoxy(16,5);
printf("   Mobile:9846311430  E-mail:subedi_bibek@yahoo.co.in");
gotoxy(16,7);
printf("2. Dinesh Subedi      (066/BCT/512)");
gotoxy(16,8);
printf("   Mobile:9841569394  E-mail:smokindinesh@gmail.com");
gotoxy(16,10);
printf("3. Sijan Bhandari      (066/BCT/537)");
gotoxy(16,11);
printf("   Mobile:9849516774   E-mail:sijan_nasa@yahoo.com");
gotoxy(16,13);
printf("With  the Unexplainable Help of Mr.Ashok Basnet");
gotoxy(10,17);
printf("Exiting in 3 second...........>");
//flushall();
delay(3000);
exit(0);
    }
    default:
{
gotoxy(10,23);
printf("\aWrong Entry!!Please re-entered correct option");
if(getch())
mainmenu();
}

    }
}
void addbooks(void)    //funtion that add books
{
system("cls");
int i;
gotoxy(20,5);
printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2SELECT CATEGOIES\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
gotoxy(20,7);
printf("\xDB\xDB\xDB\xDB\xB2 1. Computer");
gotoxy(20,9);
printf("\xDB\xDB\xDB\xDB\xB2 2. Electronics");
gotoxy(20,11);
printf("\xDB\xDB\xDB\xDB\xB2 3. Electrical");
gotoxy(20,13);
printf("\xDB\xDB\xDB\xDB\xB2 4. Civil");
gotoxy(20,15);
printf("\xDB\xDB\xDB\xDB\xB2 5. Mechanical");
gotoxy(20,17);
printf("\xDB\xDB\xDB\xDB\xB2 6. Architecture");
gotoxy(20,19);
printf("\xDB\xDB\xDB\xDB\xB2 7. Back to main menu");
gotoxy(20,21);
printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
gotoxy(20,22);
printf("Enter your choice:");
scanf("%d",&s);
if(s==7)

mainmenu() ;
system("cls");
fp=fopen("Bibek.dat","ab+");
if(getdata()==1)
{
a.cat=catagories[s-1];
fseek(fp,0,SEEK_END);
fwrite(&a,sizeof(a),1,fp);
fclose(fp);
gotoxy(21,14);
printf("The record is sucessfully saved");
gotoxy(21,15);
printf("Save any more?(Y / N):");
if(getch()=='n')
    mainmenu();
else
    system("cls");
    addbooks();
}
}
void deletebooks()    //function that delete items from file fp
{
    system("cls");
    int d;
    char another='y';
    while(another=='y')  //infinite loop
    {
system("cls");
gotoxy(10,5);
printf("Enter the Book ID to  delete:");
scanf("%d",&d);
fp=fopen("Bibek.dat","rb+");
rewind(fp);
while(fread(&a,sizeof(a),1,fp)==1)
{
    if(a.id==d)
    {

gotoxy(10,7);
printf("The book record is available");
gotoxy(10,8);
printf("Book name is %s",a.name);
gotoxy(10,9);
printf("Rack No. is %d",a.rackno);
findbook='t';
    }
}
if(findbook!='t')
{
    gotoxy(10,10);
    printf("No record is found modify the search");
    if(getch())
    mainmenu();
}
if(findbook=='t' )
{
    gotoxy(10,9);
    printf("Do you want to delete it?(Y/N):");
    if(getch()=='y')
    {
ft=fopen("test.dat","wb+");  //temporary file for delete
rewind(fp);
while(fread(&a,sizeof(a),1,fp)==1)
{
    if(a.id!=d)
    {
fseek(ft,0,SEEK_CUR);
fwrite(&a,sizeof(a),1,ft); //write all in tempory file except that
    }                              //we want to delete
}
fclose(ft);
fclose(fp);
remove("Bibek.dat");
rename("test.dat","Bibek.dat"); //copy all item from temporary file to fp except that
fp=fopen("Bibek.dat","rb+");    //we want to delete
if(findbook=='t')
{
    gotoxy(10,10);
    printf("The record is sucessfully deleted");
    gotoxy(10,11);
    printf("Delete another record?(Y/N)");
}
    }
else
mainmenu();
fflush(stdin);
another=getch();
}
}
    gotoxy(10,15);
    mainmenu();
}
void searchbooks()
{
    system("cls");
    int d;
    printf("*****************************Search Books*********************************");
    gotoxy(20,10);
    printf("\xDB\xDB\xDB\xB2 1. Search By ID");
    gotoxy(20,14);
    printf("\xDB\xDB\xDB\xB2 2. Search By Name");
    gotoxy( 15,20);
    printf("Enter Your Choice");
    fp=fopen("Bibek.dat","rb+"); //open file for reading propose
    rewind(fp);   //move pointer at the begining of file
    switch(getch())
    {
  case '1':
{
    system("cls");
    gotoxy(25,4);
    printf("****Search Books By Id****");
    gotoxy(20,5);
    printf("Enter the book id:");
    scanf("%d",&d);
    gotoxy(20,7);
    printf("Searching........");
    while(fread(&a,sizeof(a),1,fp)==1)
    {
if(a.id==d)
{
    delay(2);
    gotoxy(20,7);
    printf("The Book is available");
    gotoxy(20,8);
    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
    gotoxy(20,9);
    printf("\xB2 ID:%d",a.id);gotoxy(47,9);printf("\xB2");
    gotoxy(20,10);
    printf("\xB2 Name:%s",a.name);gotoxy(47,10);printf("\xB2");
    gotoxy(20,11);
    printf("\xB2 Author:%s ",a.Author);gotoxy(47,11);printf("\xB2");
    gotoxy(20,12);
    printf("\xB2 Qantity:%d ",a.quantity);gotoxy(47,12);printf("\xB2"); gotoxy(47,11);printf("\xB2");
    gotoxy(20,13);
    printf("\xB2 Price:Rs.%.2f",a.Price);gotoxy(47,13);printf("\xB2");
    gotoxy(20,14);
    printf("\xB2 Rack No:%d ",a.rackno);gotoxy(47,14);printf("\xB2");
    gotoxy(20,15);
    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
    findbook='t';
}

    }
    if(findbook!='t')  //checks whether conditiion enters inside loop or not
    {
    gotoxy(20,8);
    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
    gotoxy(20,9);printf("\xB2");  gotoxy(38,9);printf("\xB2");
    gotoxy(20,10);
    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
    gotoxy(22,9);printf("\aNo Record Found");
    }
    gotoxy(20,17);
    printf("Try another search?(Y/N)");
    if(getch()=='y')
    searchbooks();
    else
    mainmenu();
    break;
}
case '2':
{
    char s[15];
    system("cls");
    gotoxy(25,4);
    printf("****Search Books By Name****");
    gotoxy(20,5);
    printf("Enter Book Name:");
    scanf("%s",s);
    int d=0;
    while(fread(&a,sizeof(a),1,fp)==1)
    {
if(strcmp(a.name,(s))==0) //checks whether a.name is equal to s or not
{
    gotoxy(20,7);
    printf("The Book is available");
    gotoxy(20,8);
    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
    gotoxy(20,9);
    printf("\xB2 ID:%d",a.id);gotoxy(47,9);printf("\xB2");
    gotoxy(20,10);
    printf("\xB2 Name:%s",a.name);gotoxy(47,10);printf("\xB2");
    gotoxy(20,11);
    printf("\xB2 Author:%s",a.Author);gotoxy(47,11);printf("\xB2");
    gotoxy(20,12);
    printf("\xB2 Qantity:%d",a.quantity);gotoxy(47,12);printf("\xB2");
    gotoxy(20,13);
    printf("\xB2 Price:Rs.%.2f",a.Price);gotoxy(47,13);printf("\xB2");
    gotoxy(20,14);
    printf("\xB2 Rack No:%d ",a.rackno);gotoxy(47,14);printf("\xB2");
    gotoxy(20,15);
    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
    d++;
}

    }
    if(d==0)
    {
    gotoxy(20,8);
    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
    gotoxy(20,9);printf("\xB2");  gotoxy(38,9);printf("\xB2");
    gotoxy(20,10);
    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
    gotoxy(22,9);printf("\aNo Record Found");
    }
    gotoxy(20,17);
    printf("Try another search?(Y/N)");
    if(getch()=='y')
    searchbooks();
    else
    mainmenu();
    break;
}
default :
getch();
searchbooks();
    }
    fclose(fp);
}
void issuebooks(void)  //function that issue books from library
{
    int t;

    system("cls");
    printf("********************************ISSUE SECTION**************************");
    gotoxy(10,5);
    printf("\xDB\xDB\xDB\xDb\xB2 1. Issue a Book");
    gotoxy(10,7);
    printf("\xDB\xDB\xDB\xDb\xB2 2. View Issued Book");
    gotoxy(10,9);
    printf("\xDB\xDB\xDB\xDb\xB2 3. Search Issued Book");
    gotoxy(10,11);
    printf("\xDB\xDB\xDB\xDb\xB2 4. Remove Issued Book");
    gotoxy(10,14);
    printf("Enter a Choice:");
    switch(getch())
    {
case '1':  //issue book
{
system("cls");
int c=0;
char another='y';
while(another=='y')
{
system("cls");
gotoxy(15,4);
printf("***Issue Book section***");
gotoxy(10,6);
printf("Enter the Book Id:");
scanf("%d",&t);
fp=fopen("Bibek.dat","rb");
fs=fopen("Issue.dat","ab+");
if(checkid(t)==0) //issues those which are present in library
{
     gotoxy(10,8);
     printf("The book record is available");
     gotoxy(10,9);
     printf("There are %d unissued books in library ",a.quantity);
     gotoxy(10,10);
     printf("The name of book is %s",a.name);
     gotoxy(10,11);
     printf("Enter student name:");
     scanf("%s",a.stname);
    // struct dosdate_t d; //for current date
    // _dos_getdate(&d);
    // a.issued.dd=d.day;
    // a.issued.mm=d.month;
     //a.issued.yy=d.year;
     gotoxy(10,12);
     printf("Issued date=%d-%d-%d",a.issued.dd,a.issued.mm,a.issued.yy);
     gotoxy(10,13);
     printf("The BOOK of ID %d is issued",a.id);
     a.duedate.dd=a.issued.dd+RETURNTIME;   //for return date
     a.duedate.mm=a.issued.mm;
     a.duedate.yy=a.issued.yy;
     if(a.duedate.dd>30)
     {
a.duedate.mm+=a.duedate.dd/30;
a.duedate.dd-=30;

     }
     if(a.duedate.mm>12)
     {
a.duedate.yy+=a.duedate.mm/12;
a.duedate.mm-=12;

     }
     gotoxy(10,14);
     printf("To be return:%d-%d-%d",a.duedate.dd,a.duedate.mm,a.duedate.yy);
     fseek(fs,sizeof(a),SEEK_END);
     fwrite(&a,sizeof(a),1,fs);
     fclose(fs);
     c=1;
}
if(c==0)
{
gotoxy(10,11);
printf("No record found");
}
gotoxy(10,15);
printf("Issue any more(Y/N):");
fflush(stdin);
another=getche();
fclose(fp);
}

break;
}
case '2':  //show issued book list
{
system("cls");
int j=4;
printf("*******************************Issued book list*******************************\n");
gotoxy(2,2);
printf("STUDENT NAME    CATEGORY    ID    BOOK NAME    ISSUED DATE    RETURN DATE");
       fs=fopen("Issue.dat","rb");
while(fread(&a,sizeof(a),1,fs)==1)
{

gotoxy(2,j);
printf("%s",a.stname);
gotoxy(18,j);
printf("%s",a.cat);
gotoxy(30,j);
printf("%d",a.id);
gotoxy(36,j);
printf("%s",a.name);
gotoxy(51,j);
printf("%d-%d-%d",a.issued.dd,a.issued.mm,a.issued.yy );
gotoxy(65,j);
printf("%d-%d-%d",a.duedate.dd,a.duedate.mm,a.duedate.yy);
//struct dosdate_t d;
//_dos_getdate(&d);
gotoxy(50,25);
// printf("Current date=%d-%d-%d",d.day,d.month,d.year);
j++;

}
fclose(fs);
gotoxy(1,25);
returnfunc();
}
break;
case '3':   //search issued books by id
{
system("cls");
gotoxy(10,6);
printf("Enter Book ID:");
int p,c=0;
char another='y';
while(another=='y')
{

scanf("%d",&p);
fs=fopen("Issue.dat","rb");
while(fread(&a,sizeof(a),1,fs)==1)
{
if(a.id==p)
{
issuerecord();
gotoxy(10,12);
printf("Press any key.......");
getch();
issuerecord();
c=1;
}

}
fflush(stdin);
fclose(fs);
if(c==0)
{
gotoxy(10,8);
printf("No Record Found");
}
gotoxy(10,13);
printf("Try Another Search?(Y/N)");
another=getch();
}
}
break;
case '4':  //remove issued books from list
{
system("cls");
int b;
FILE *fg;  //declaration of temporary file for delete
char another='y';
while(another=='y')
{
gotoxy(10,5);
printf("Enter book id to remove:");
scanf("%d",&b);
fs=fopen("Issue.dat","rb+");
while(fread(&a,sizeof(a),1,fs)==1)
{
if(a.id==b)
{
issuerecord();
findbook='t';
}
if(findbook=='t')
{
gotoxy(10,12);
printf("Do You Want to Remove it?(Y/N)");
if(getch()=='y')
{
fg=fopen("record.dat","wb+");
rewind(fs);
while(fread(&a,sizeof(a),1,fs)==1)
{
if(a.id!=b)
{
fseek(fs,0,SEEK_CUR);
fwrite(&a,sizeof(a),1,fg);
}
}
fclose(fs);
fclose(fg);
remove("Issue.dat");
rename("record.dat","Issue.dat");
gotoxy(10,14);
printf("The issued book is removed from list");

       }

}
if(findbook!='t')
{
gotoxy(10,15);
printf("No Record Found");
}
}
gotoxy(10,16);
printf("Delete any more?(Y/N)");
another=getch();
}
}
default:
gotoxy(10,18);
printf("\aWrong Entry!!");
    getch();
issuebooks();
break;
      }
      gotoxy(1,30);
      returnfunc();
}
void viewbooks(void)  //show the list of book persists in library
{
    int i=0,j;
    system("cls");
    gotoxy(1,1);
    printf("*********************************Book List*****************************");
    gotoxy(2,2);
    printf(" CATEGORY     ID    BOOK NAME     AUTHOR       QTY     PRICE     RackNo ");
    j=4;
    fp=fopen("Bibek.dat","rb");
    while(fread(&a,sizeof(a),1,fp)==1)
    {
gotoxy(3,j);
printf("%s",a.cat);
gotoxy(16,j);
printf("%d",a.id);
gotoxy(22,j);
printf("%s",a.name);
gotoxy(36,j);
printf("%s",a.Author);
gotoxy(50,j);
printf("%d",a.quantity);
gotoxy(57,j);
printf("%.2f",a.Price);
gotoxy(69,j);
printf("%d",a.rackno);
printf("\n\n");
j++;
i=i+a.quantity;
      }
      gotoxy(3,25);
      printf("Total Books =%d",i);
      fclose(fp);
      gotoxy(35,25);
      returnfunc();
}
void editbooks(void)  //edit information about book
{
system("cls");
int c=0;
int d,e;
gotoxy(20,4);
printf("****Edit Books Section****");
char another='y';
while(another=='y')
{
system("cls");
gotoxy(15,6);
printf("Enter Book Id to be edited:");
scanf("%d",&d);
fp=fopen("Bibek.dat","rb+");
while(fread(&a,sizeof(a),1,fp)==1)
{
if(checkid(d)==0)
{
gotoxy(15,7);
printf("The book is availble");
gotoxy(15,8);
printf("The Book ID:%d",a.id);
gotoxy(15,9);
printf("Enter new name:");scanf("%s",a.name);
gotoxy(15,10);
printf("Enter new Author:");scanf("%s",a.Author);
gotoxy(15,11);
printf("Enter new quantity:");scanf("%d",&a.quantity);
gotoxy(15,12);
printf("Enter new price:");scanf("%f",&a.Price);
gotoxy(15,13);
printf("Enter new rackno:");scanf("%d",&a.rackno);
gotoxy(15,14);
printf("The record is modified");
fseek(fp,ftell(fp)-sizeof(a),0);
fwrite(&a,sizeof(a),1,fp);
fclose(fp);
c=1;
}
if(c==0)
{
gotoxy(15,9);
printf("No record found");
}
}
gotoxy(15,16);
printf("Modify another Record?(Y/N)");
fflush(stdin);
another=getch() ;
}
returnfunc();
}
void returnfunc(void)
{
    {
printf(" Press ENTER to return to main menu");
    }
    a:
    if(getch()==13) //allow only use of enter
    mainmenu();
    else
    goto a;
}
int getdata()
{
int t;
gotoxy(20,3);printf("Enter the Information Below");
gotoxy(20,4);printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
gotoxy(20,5);
printf("\xB2");gotoxy(46,5);printf("\xB2");
gotoxy(20,6);
printf("\xB2");gotoxy(46,6);printf("\xB2");
gotoxy(20,7);
printf("\xB2");gotoxy(46,7);printf("\xB2");
gotoxy(20,8);
printf("\xB2");gotoxy(46,8);printf("\xB2");
gotoxy(20,9);
printf("\xB2");gotoxy(46,9);printf("\xB2");
gotoxy(20,10);
printf("\xB2");gotoxy(46,10);printf("\xB2");
gotoxy(20,11);
printf("\xB2");gotoxy(46,11);printf("\xB2");
gotoxy(20,12);
printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
gotoxy(21,5);
printf("Category:");
gotoxy(31,5);
printf("%s",catagories[s-1]);
gotoxy(21,6);
printf("Book ID:\t");
gotoxy(30,6);
scanf("%d",&t);
if(checkid(t) == 0)
{
gotoxy(21,13);
printf("\aThe book id already exists\a");
getch();
mainmenu();
return 0;
}
a.id=t;
gotoxy(21,7);
printf("Book Name:");gotoxy(33,7);
scanf("%s",a.name);
gotoxy(21,8);
printf("Author:");gotoxy(30,8);
scanf("%s",a.Author);
gotoxy(21,9);
printf("Quantity:");gotoxy(31,9);
scanf("%d",&a.quantity);
gotoxy(21,10);
printf("Price:");gotoxy(28,10);
scanf("%f",&a.Price);
gotoxy(21,11);
printf("Rack No:");gotoxy(30,11);
scanf("%d",&a.rackno);
return 1;
}
int checkid(int t)  //check whether the book is exist in library or not
{
rewind(fp);
while(fread(&a,sizeof(a),1,fp)==1)
if(a.id==t)
return 0;  //returns 0 if book exits
      return 1; //return 1 if it not
}
int t(void) //for time
{
time_t t;
time(&t);
printf("Date and time:%s\n",ctime(&t));

return 0 ;
}
//void show_mouse(void) //show inactive mouse pointer in programme
//{
//union REGS in,out;
//
//       in.x.ax = 0x1;
//       int86(0x33,&in,&out);
//}
void Password(void) //for password option
{

   system("cls");
   char d[25]="Password Protected";
   char ch,pass[10];
   int i=0,j;
   //textbackground(WHITE);
   //textcolor(RED);
    gotoxy(10,4);
    for(j=0;j<20;j++)
    {
    delay(50);
    printf("*");
    }
    for(j=0;j<20;j++)
   {
   delay(50);
   printf("%c",d[j]);
   }
   for(j=0;j<20;j++)
   {
   delay(50);
   printf("*");
   }
   gotoxy(10,10);
   gotoxy(15,7);
   printf("Enter Password:");

   while(ch!=13)
   {
ch=getch();

if(ch!=13 && ch!=8){
putch('*');
pass[i] = ch;
i++;
}
   }
   pass[i] = '\0';
   if(strcmp(pass,password)==0)
   {

gotoxy(15,9);
//textcolor(BLINK);
printf("Password match");
gotoxy(17,10);
printf("Press any key to countinue.....");
getch();
mainmenu();
   }
   else
   {
gotoxy(15,16);
printf("\aWarning!! Incorrect Password");
getch();
Password();
   }
}
void issuerecord()  //display issued book's information
{
system("cls");
gotoxy(10,8);
printf("The Book has taken by Mr. %s",a.stname);
gotoxy(10,9);
printf("Issued Date:%d-%d-%d",a.issued.dd,a.issued.mm,a.issued.yy);
gotoxy(10,10);
printf("Returning Date:%d-%d-%d",a.duedate.dd,a.duedate.mm,a.duedate.yy);
}
void loaderanim()
{
int loader;
system("cls");
gotoxy(20,10);
printf("LOADING........");
printf("\n\n");
gotoxy(22,11);
for(loader=1;loader<20;loader++)
{
delay(100);printf("%c",219);}
}
//End of program

Banking System Project

//*************************************************************** //                   HEADER FILE USED IN PROJECT //********************...