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;
}