Tuesday, 5 June 2018

C Program for Hospital Management System

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define rw 80
#define cl 50
FILE*fp,*fp1,*f1,*f2;
int s,z;
char fn1[]="opd12.patient";
char fn2[]="oopd12.patient";
struct hospital{
        char name[20],address[20],ch;
        int age,roomno,sn;
        char disease[30],department[20],date[15];
        char recommendation[50],category[30];
        char test[15][20];
        float testfee[15];
        float totalfee;
        float balance;
        }p,q;
char string[20];
typedef struct hospital alka;
void newrecord(int l);
void print();
void displaytest();
void mainscreen();
void newrecord1();
void displaydepartment();
void edit1();
void editrecord();
void switch1();
void main()
{
    int a,i,n,y;
    char c,d;
    char date1[15],date2[15],string1[20];
    unsigned int tsz;

    clrscr();
    mainscreen();
    label3:
    textcolor(3);
    gotoxy(23,15);
    cprintf("Enter today's Date(yyyy/mm/dd)");
    fflush(stdin);gotoxy(28,19);
    scanf("%[^\n]",date2);
    if((date2[4]!='/')||(date2[7]!='/')||(date2[5]>'3')||(date2[8]>'3'))
    {
        clrscr();
        mainscreen();
        gotoxy(23,13);textcolor(4+128);
        cprintf("Wrong Entry");
        goto label3;
    }
    clrscr();
    mainscreen();
    label1:

    textcolor(15);
    lowvideo();gotoxy(22,15);textcolor(14);
    cprintf("Enter the corresponding no");gotoxy(22,19);textcolor(10);
    cprintf("1.Add new patient record");gotoxy(22,21);
    cprintf("2.Search  or edit record");gotoxy(22,23);
    cprintf("3.Know the records of patients");gotoxy(22,25);
    cprintf("4.Delete the records");gotoxy(22,27);
    cprintf("5.Exit from the program");gotoxy(25,30);
    fflush(stdin);
    scanf("%c",&d);
    switch(d)
    {
        case '1':
              {

            {
                if((fp=fopen(fn1,"rb"))==NULL)
                s=1;
                else
                {
                while(fread(&p,sizeof(alka),1,fp))
                s=1+p.sn;
                }
                fclose(fp);
            }
            clrscr();
            mainscreen();
            label:
            gotoxy(22,19);textcolor(7);
            cprintf("Enter `o' for O.P.D. & `e'for Emergency");
            gotoxy(35,21);
            fflush(stdin);
            scanf("%c",&c);
            if(c=='o')
            {
                clrscr();
                mainscreen();
                textcolor(11);gotoxy(23,11);
                cprintf("ADDING NEW O.P.D.PATIENT RECORD");textcolor(15);
                gotoxy(21,12);
                cprintf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                newrecord(s);
                newrecord1();

                if((fp=fopen(fn1,"ab+"))==NULL)
                {
                    printf("Cannot open the file f1");
                    getch();
                    exit(1);
                }
                for(a=0;a<15;a++)
                p.testfee[a]=0;
                strcpy(&p.test[1][0],"0");
                p.totalfee=0;p.balance=0;
                strcpy(&p.test[0][0],"O.P.D. charge");
                p.testfee[0]=200;

                p.totalfee=200;
                strcpy(p.category,"O.P.D.Patient");
                p.balance=200;
                strcpy(p.recommendation,"Admitted to O.P.D.");
                strcpy(p.date,date2);
                fwrite(&p,sizeof(p),1,fp);
                fclose(fp);
                if((fp=fopen(fn2,"ab+"))==NULL)
                {
                        printf("Cannot open the file f1");
                        getch();
                        exit(1);
                }
                fwrite(&p,sizeof(p),1,fp);
                fclose(fp);


            }
            else if(c=='e')
                   {
                 clrscr();
                 mainscreen();
                 textcolor(11);
                 gotoxy(23,11);
                 cprintf("ADDING NEW EMERGENCY PATIENT RECORD");
                 textcolor(15);
                 gotoxy(23,12);
                 cprintf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                 newrecord(s);
                 newrecord1();
                 if((fp=fopen(fn1,"ab+"))==NULL)
                    {
                        printf("Cannot open the file f1");
                        getch();
                        exit(1);
                    }
                    for(a=0;a<15;a++)
                    p.testfee[a]=0;
                    strcpy(&p.test[1][0],"0");
                    p.totalfee=0;p.balance=0;

                   p.totalfee=250;
                   strcpy(p.date,date2);
                   strcpy(&p.test[0][0],"Emergency Charge");
                   strcpy(p.category,"Emergency Patient");
                   strcpy(p.recommendation,"Admitted to Emergency");
                   p.testfee[0]=250;
                   p.balance=250;
                   fwrite(&p,sizeof(p),1,fp);
                   fclose(fp);
                  if((fp=fopen(fn2,"ab+"))==NULL)
                {
                        printf("Cannot open the file f1");
                        getch();
                        exit(1);
                }
                fwrite(&p,sizeof(p),1,fp);
                fclose(fp);

                   }
            else
            {
                clrscr();
                mainscreen();
                gotoxy(22,15);textcolor(128+5);
                cprintf("Wrong choice");
                textcolor(15);
                goto label;
            }
            break;
              }
        case '2':
              {
               clrscr();
               mainscreen();
               editrecord();
               break;
              }
        case '5':
              {
            clrscr();
            mainscreen();
            textcolor(14); gotoxy(30,24);
            cprintf("THANK U");gotoxy(30,26);
               //    cprintf("SAVING UR SETTINGS"); gotoxy(30,28);
            cprintf("BYE...........");
            getch();
            exit(1);
            break;
            }
        case '4':
            {
                if((fp=fopen(fn1,"rb"))==NULL)
                {
                    printf("cannot open the file");
                    getch();
                    exit(1);
                }

                if((f1=fopen("delete","wb"))==NULL)
                {
                    printf("cannot open the file");
                    getch();
                    exit(1);
                }

                clrscr();
                mainscreen();
                gotoxy(30,25);
                cprintf("Enter the patient no");
                gotoxy(40,27);
                   fflush(stdin);
                scanf("%d",&y);
                while(fread(&p,sizeof(alka),1,fp))
                    if(p.sn!=y)
                    fwrite(&p,sizeof(alka),1,f1);
                clrscr();
                mainscreen();
                fseek(fp,(y-1)*sizeof(alka),SEEK_SET);
                fread(&p,sizeof(alka),1,fp);
                print();
                edit1();
                gotoxy(25,46);
                cprintf("Press `ENTER' to delete this record");
                getch();
                fclose(fp);
                fclose(f1);
                remove(fn1);
                rename("delete",fn1);

                if((fp=fopen(fn2,"rb"))==NULL)
                {
                    printf("cannot open the file");
                    getch();
                    exit(1);
                }

                if((f1=fopen("delete","wb"))==NULL)
                {
                    printf("cannot open the file");
                    getch();
                    exit(1);
                }
                while(fread(&p,sizeof(alka),1,fp))
                    if(p.sn!=y)
                    fwrite(&p,sizeof(alka),1,f1);



                fclose(fp);
                fclose(f1);
                remove(fn2);
                rename("delete",fn2);
                clrscr();
                mainscreen();
                gotoxy(25,25);textcolor(3);
                cprintf("Record succesfully Deleted");
                getch();
                gotoxy(37,30);
                break;
            }


        case '3':
            {       label6:
                clrscr();
                mainscreen();
                gotoxy(22,15);textcolor(12);
                cprintf("Enter the corresponding no");gotoxy(22,19);textcolor(3);
                cprintf("1.Records of patients in alphabatecal order");gotoxy(22,21);
                cprintf("2.Records of Emergency patients");gotoxy(22,23);
                cprintf("3.Records of O.P.D. patients");gotoxy(22,25);
                cprintf("4.Recordsin paricular date");gotoxy(22,27);
                cprintf("5.Return to main menu");gotoxy(25,30);
                fflush(stdin);
                scanf("%c",&d);
                switch(d)
                {
                case '1':
                    {
                     if((fp=fopen(fn2,"rb+"))==NULL)
                          {
                        printf("Cannot open the file");
                        getch();
                        exit(1);
                          }
                     fseek(fp,0,SEEK_END);
                     tsz=ftell(fp);
                     n=(int)(tsz/sizeof(alka));
                     for(i=0;i<(n-1);i++)
                     {
                        for(a=i+1;a<n;a++)
                        {
                        fseek(fp,i*sizeof(alka),SEEK_SET);
                        fread(&p,sizeof(alka),1,fp);
                        fseek(fp,a*sizeof(alka),SEEK_SET);
                        fread(&q,sizeof(alka),1,fp);
                        if(strcmp(p.name,q.name)>0)
                            {
                            fseek(fp,i*sizeof(alka),SEEK_SET);
                            fwrite(&q,sizeof(alka),1,fp);
                            fseek(fp,a*sizeof(alka),SEEK_SET); fflush(stdin);
                            fwrite(&p,sizeof(alka),1,fp);
                            }
                        }
                    }
                    rewind(fp);
                    clrscr();
                    mainscreen();
                    gotoxy(3,20);
                    textcolor(11);
                    cprintf("Ready to Display the patient records according to alphabatecal order of names");
                    gotoxy(27,25);textcolor(3);
                    cprintf("Press");textcolor(15+128);
                    cprintf(" `Enter' ");    textcolor(3);
                    cprintf("to continue");
                    getch();
                    while(fread(&p,sizeof(alka),1,fp))
                    {
                    clrscr();
                    mainscreen();
                    print();
                    gotoxy(17,10);  textcolor(7);
                    cprintf("DISPLAYING-RECORD-ACCORDING-TO-PATIENTS-NAMES");
                    gotoxy(16,11);textcolor(15);
                    cprintf("---------------------------------------------");
                    edit1();

                    textcolor(11);
                    gotoxy(20,46);
                    cprintf("Press");textcolor(15+128);
                    cprintf(" `Enter'"); textcolor(11);
                    cprintf(" for next and `r' to quit: ");
                    scanf("%c",&c);

                    if(c=='r')
                    {
                    goto label6;

                    }
                    gotoxy(60,46);
                    getch();

                }
                clrscr();
                mainscreen();
                textcolor(11);
                gotoxy(30,25);
                cprintf("::No Further Records::");   gotoxy(40,30);
                getch();
                fclose(fp);
                break;
                }
            case '5':
                {
                clrscr();
                mainscreen();
                 goto label1;
                 }
            case '2':
                {
                clrscr();
                mainscreen();
                if((fp=fopen(fn1,"rb"))==NULL)
                          {
                        printf("Cannot open the file");
                        getch();
                        exit(1);
                          }
                gotoxy(15,20);
                textcolor(2);
                cprintf("Ready to Display records of Emergency Patients");
                gotoxy(27,25);textcolor(3);
                cprintf("Press");textcolor(15+128);
                cprintf(" `Enter' ");    textcolor(3);
                cprintf("to continue");
                getch();
                while(fread(&p,sizeof(alka),1,fp))
                {
                    if(strcmp(p.category,"Emergency Patient")==NULL)
                    {
                    clrscr();
                    mainscreen();
                    print();
                    gotoxy(17,10);  textcolor(7);
                    cprintf("::DISPLAYING-RECORDS-OF-EMERGENCY-PATIENTS::");
                    gotoxy(16,11);textcolor(15);
                    cprintf("---------------------------------------------");
                    edit1();

                    textcolor(11);
                    gotoxy(20,45);
                    cprintf("Press");textcolor(15+128);
                    cprintf(" `Enter'"); textcolor(11);
                    cprintf(" for next and `r' to quit: ");
                    scanf("%c",&c);

                    if(c=='r')
                    {
                    goto label6;
                    }
                    gotoxy(60,46);
                    getch();
                    }
                }
                clrscr();
                mainscreen();
                textcolor(11);
                gotoxy(30,25);
                cprintf("::No Further Records::");   gotoxy(40,30);
                getch();
                fclose(fp);
                break;
                }
            case '3':
                {
                clrscr();
                mainscreen();
                if((fp=fopen(fn1,"rb"))==NULL)
                          {
                        printf("Cannot open the file");
                        getch();
                        exit(1);
                          }
                gotoxy(15,20);
                textcolor(2);
                cprintf("Ready to Display records of O.P.D Patients");
                gotoxy(27,25);textcolor(3);
                cprintf("Press");textcolor(15+128);
                cprintf(" `Enter' ");    textcolor(3);
                cprintf("to continue");
                getch();
                while(fread(&p,sizeof(alka),1,fp))
                {
                    if(strcmp(p.category,"O.P.D.Patient")==NULL)
                    {
                    clrscr();
                    mainscreen();
                    print();
                    gotoxy(17,10);  textcolor(7);
                    cprintf("::DISPLAYING-RECORDS-OF-OPD-PATIENTS::");
                    gotoxy(16,11);textcolor(15);
                    cprintf("---------------------------------------------");
                    edit1();
                        textcolor(11);
                    gotoxy(20,46);
                    cprintf("Press");textcolor(15+128);
                    cprintf(" `Enter'"); textcolor(11);
                    cprintf(" for next and `r' to quit: ");
                    scanf("%c",&c);

                    if(c=='r')
                    {
                    goto label6;
                    }
                    gotoxy(60,46);
                    getch();
                    }
                }
                clrscr();
                mainscreen();
                textcolor(11);
                gotoxy(30,25);
                cprintf("::No Further Records::");   gotoxy(40,30);
                getch();
                fclose(fp);
                break;
                }
        case '4':
                {
                clrscr();
                mainscreen();
                if((fp=fopen(fn1,"rb"))==NULL)
                          {
                        printf("Cannot open the file");
                        getch();
                        exit(1);
                          }
                label8:
                gotoxy(27,20);
                textcolor(3);
                cprintf("Enter the `Date' of a paricular day(yyyy/mm/dd)");
                gotoxy(35,25);fflush(stdin);
                scanf("%s",string);
                if((string[4]!='/')||(string[7]!='/')||(string[5]>'3')||(string[8]>'3'))
                {
                clrscr();
                mainscreen();
                gotoxy(23,13);textcolor(4+128);
                cprintf("Wrong Entry");
                goto label8;
                }
                   //    getch();
                while(fread(&p,sizeof(alka),1,fp))
                {
                    if(strcmp(string,p.date)==NULL)
                    {
                    clrscr();
                    mainscreen();
                    print();
                    gotoxy(17,10);  textcolor(7);
                    cprintf("::DISPLAYING-RECORDS-OF-");
                    cprintf("DATE >%s",p.date);
                    gotoxy(16,11);textcolor(15);
                    cprintf("---------------------------------------------");
                    edit1();

                    textcolor(11);
                    gotoxy(20,46);
                    cprintf("Press");textcolor(15+128);
                    cprintf(" `Enter'"); textcolor(11);
                    cprintf(" for next and `r' to quit: ");
                    scanf("%c",&c);

                    if(c=='r')
                    {
                    goto label6;
                    }
                    gotoxy(60,46);
                    getch();
                    }
                }
                clrscr();
                mainscreen();
                textcolor(11);
                gotoxy(30,25);
                cprintf("::No Further Records::");   gotoxy(40,30);
                getch();
                fclose(fp);
                break;
                }

            default:
                {
                clrscr();
                mainscreen();
                textcolor(12+128);gotoxy(22,11);
                cprintf("Wrong choice");gotoxy(22,13);textcolor(15);
                 cprintf("Retype choice");
                goto label6;
                }
            }
        }break;





        default:
               {
            clrscr();
            mainscreen();
            textcolor(12+128);gotoxy(22,11);
            cprintf("Wrong choice");gotoxy(22,13);textcolor(15);
             cprintf("Retype choice");
            goto label1;
            }

    }
    clrscr();
    mainscreen();
    goto label1;
}
void newrecord(int l)
{
    char q;
    p.sn=l;
    displaydepartment();
    gotoxy(5,14);textcolor(10);
    cprintf("Record of patient no:");
    printf(" %d",l);
    gotoxy(5,17);
    cprintf("Name:");

    gotoxy(5,20);
    cprintf("Address:");

    gotoxy(5,23);
    cprintf("Age: ");

    gotoxy(5,26);
    cprintf("Sex(m/f): ");

    gotoxy(5,29);
    cprintf("Disease Descrp:");
    gotoxy(9,30);
    cprintf("(In Short)");

    gotoxy(5,33);
    cprintf("Reff. Specialist no:");
    fflush(stdin);gotoxy(10,17);
    scanf("%[^\n]",p.name);
    p.name[0]=toupper(p.name[0]);
    gotoxy(14,20);
    fflush(stdin);
    scanf("%[^\n]",p.address);
    gotoxy(10,23);
    fflush(stdin);
    scanf("%d",&p.age);
    gotoxy(15,26);
    fflush(stdin);
    scanf("%c",&p.ch);
    fflush(stdin);gotoxy(22,29);
    scanf("%[^\n]",p.disease);
}
void newrecord1()
{
      char q;
     fflush(stdin);
     gotoxy(25,33);
    scanf("%c",&q);
    switch(q)
    {
        case '1':
            {          gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("Generalphysician");
                   strcpy(p.department,"General Physician");
                   gotoxy(5,39);
                cprintf("Room no:");
                fflush(stdin);
                scanf("%d",&p.roomno);
                   //    getch();

                break;

            }
        case '2':
            {      gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("E.N.T.");
                   gotoxy(5,39);
                   cprintf("Room no:");
                   printf("302");
                   strcpy(p.department,"E.N.T");
                p.roomno=302; getch();
                break;
            }
            case '3':
            {      gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("Cardiologist");
                   gotoxy(5,39);
                   cprintf("Room no:");
                   printf("509");
                   strcpy(p.department,"cardiologist");
                p.roomno=509; getch();
                break;
            }
            case '4':
            {      gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("Dermatologist");
                   gotoxy(5,39);
                   cprintf("Room no:");
                   printf("406");
                   strcpy(p.department,"Dermatologist");
                p.roomno=406; getch();
                break;
            }

            case '5':
            {      gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("Gastroenteroiogist");
                   gotoxy(5,39);
                   cprintf("Room no:");
                   printf("308");
                   strcpy(p.department,"Gastroentrologist");
                p.roomno=308; getch();
                break;
            }
            case '6':
            {      gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("Pediatrician");
                   gotoxy(5,39);
                   cprintf("Room no:");
                   printf("207");
                   strcpy(p.department,"Padiatrician");
                p.roomno=207; getch();
                break;
            }
            case '7':
            {      gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("EYE Specialist");
                   gotoxy(5,39);
                   cprintf("Room no:");
                   printf("102");
                   strcpy(p.department,"EYE Specialist");
                p.roomno=102; getch();
                break;
            }
            case '8':
            {      gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("Nephrologist");
                   gotoxy(5,39);
                   cprintf("Room no:");
                   printf("109");
                   strcpy(p.department,"Nephrologist");
                p.roomno=109; getch();
                break;
            }
            case '9':
            {      gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("General Surgeon");
                   strcpy(p.department,"General Surgeon");
                   gotoxy(5,39);
                cprintf("Room no:");
                fflush(stdin);
                scanf("%d",&p.roomno);
                   //    getch();
                break;
            }
            case '10':
            {      gotoxy(5,36);
                   cprintf("Reff.Specialist:");
                   printf("Accumpunturist");
                   strcpy(p.department,"Accumpunturist");
                   gotoxy(5,39);
                cprintf("Room no:");
                fflush(stdin);
                scanf("%d",&p.roomno);

                //  getch();
                break;
            }
        default:
            {
            gotoxy(5,36);
            cprintf("Reff.Specialist:");
            fflush(stdin);
            scanf("%[^\n]",p.department);
            gotoxy(5,39);
            cprintf("Room no:");
            fflush(stdin);
            scanf("%d",&p.roomno);

            return;
            }
    }
}

void displaydepartment()
{
    int i;
    gotoxy(48,14);textcolor(6);
    cprintf(":Specialists:");
    gotoxy(47,15);textcolor(15);
    cprintf("---------------");
    gotoxy(70,14);textcolor(6);
    cprintf("Room No.");
    gotoxy(67,15);textcolor(15);
    cprintf("----------");
    gotoxy(48,17);textcolor(5);
    cprintf("1.General Physician");
    gotoxy(70,17);textcolor(7);
    cprintf("201,202");
    gotoxy(48,19);textcolor(5);
    cprintf("2.E.N.T");
    gotoxy(70,19);textcolor(7);
    cprintf("302");
    gotoxy(48,21);textcolor(5);
    cprintf("3.Cardiologist");
    gotoxy(70,21);textcolor(7);
    cprintf("509");
    gotoxy(48,23);textcolor(5);
    cprintf("4.Dermatologist");
    gotoxy(70,23);textcolor(7);
    cprintf("406");
    gotoxy(48,25);textcolor(5);
    cprintf("5.Gastroenterologist");
    gotoxy(70,25);textcolor(7);
    cprintf("308");
    gotoxy(48,27);textcolor(5);
    cprintf("6.Pediatrician");
    gotoxy(70,27);textcolor(7);
    cprintf("207");
    gotoxy(48,29);textcolor(5);
    cprintf("7.EYE Specialist");
    gotoxy(70,29);textcolor(7);
    cprintf("102");
    gotoxy(48,31);textcolor(5);
    cprintf("8.Nephrologist");
    gotoxy(70,31);textcolor(7);
    cprintf("109");
    gotoxy(48,33);textcolor(5);
    cprintf("9.General Surgeon");
    gotoxy(70,33);textcolor(7);
    cprintf("407,408");
    gotoxy(70,35);textcolor(7);
    cprintf("412,413");
    gotoxy(48,37);textcolor(5);
    cprintf("10.Accupuncturist");
    gotoxy(70,37);textcolor(7);
    cprintf("123,119");
    textcolor(15);
    for(i=14;i<=45;i++)
    {
        gotoxy(46,i);
        cprintf("|");
    }
}
void print()
{
    gotoxy(29,10);  textcolor(7);
    cprintf("DISPLAYING RECORDS");
    gotoxy(28,11);textcolor(15);
    cprintf("--------------------");
    gotoxy(10,14);textcolor(2);
    cprintf("Patient no:");gotoxy(21,14);textcolor(11);
    cprintf("%d",p.sn);gotoxy(10,17);textcolor(2);
    cprintf("Name:");gotoxy(15,17);textcolor(11);
    cprintf(" %s",p.name);gotoxy(10,20);textcolor(2);
    cprintf("Address:");gotoxy(18,20);textcolor(11);
    cprintf(" %s",p.address);gotoxy(10,23);textcolor(2);
    cprintf("Age:");gotoxy(15,23);textcolor(11);
    cprintf("%d",p.age);gotoxy(10,26);textcolor(2);
    cprintf("Sex:");gotoxy(14,26);textcolor(11);
    cprintf(" %c",p.ch);gotoxy(10,29);textcolor(2);
    cprintf("Date of Reg.:");gotoxy(24,29);textcolor(11);
    cprintf("%s",p.date);gotoxy(10,32);textcolor(2);
    cprintf("Room no:");gotoxy(18,32);textcolor(11);
    cprintf(" %d",p.roomno);gotoxy(10,35);textcolor(2);
    cprintf("Department:");gotoxy(21,35);textcolor(11);
    cprintf(" %s",p.department);gotoxy(10,38);textcolor(2);
    cprintf("Category:");gotoxy(19,38);textcolor(11);
    cprintf(" %s",p.category);

}
void edit1()
{
    int i,k;
    gotoxy(10,41);textcolor(2);
    cprintf("Details:");gotoxy(18,41);textcolor(11);
    cprintf(" %s",p.recommendation);gotoxy(10,45);textcolor(4);
    cprintf("Press");textcolor(15+128);
    cprintf(" `Enter'");textcolor(4);
    cprintf(" for financial records");
    getch();
    clrscr();
    mainscreen();
    textcolor(14);     gotoxy(20,8);
    cprintf("The list of expenditure of patient no:");
    printf("%d",p.sn);
    for(z=0,i=0,k=11;p.testfee[z]!=NULL;i++,z++)
    {
        textcolor(15);gotoxy(20,k);
        cprintf("%d)",i+1);      textcolor(11);
        cprintf(" %s",&p.test[z][0]);textcolor(15);gotoxy(40,k);
        cprintf("Rs.%0.2f",p.testfee[z]);
        k=k+2;
    }
    gotoxy(20,k+2); textcolor(11);
    cprintf("Total charge=");textcolor(15);
    cprintf("Rs.%0.2f",p.totalfee);
    gotoxy(20,k+4);textcolor(11);
    cprintf("Total Deposited:");textcolor(15);
    cprintf("Rs.%0.2f",p.balance);
    if(p.totalfee>p.balance)
    {
        textcolor(11); gotoxy(20,k+6);
        cprintf("Total money to pay=");
        textcolor(15);
        cprintf("%0.2f",p.totalfee-p.balance);
    }
    else
    {
        textcolor(11); gotoxy(20,k+6);
        cprintf("Total money to return=");
        textcolor(15);
        cprintf("%0.2f",p.balance-p.totalfee);
    }
}
void switch1()
{
    int x,i;
    float d,lk;
    char v;
    label2:
    gotoxy(30,15);textcolor(11);
    cprintf("Enter");gotoxy(30,18);
    cprintf("1.Add Details");
    gotoxy(30,20);
    cprintf("2.Change Specialist");
    gotoxy(30,22);
    cprintf("3.Deposit balance");gotoxy(30,24);
    cprintf("4.Add test");
    gotoxy(30,26);
    cprintf("5.Return to main menu");
    gotoxy(35,39);
    fflush(stdin);
    scanf("%d",&x);
    switch(x)
    {
        case 1:
              {
            clrscr();
            mainscreen();
            gotoxy(31,10);  textcolor(7);
            cprintf("ADDING DETAILS");
            gotoxy(30,11);textcolor(15);
            cprintf("----------------");
            gotoxy(15,25);
            textcolor(2);
            cprintf("Previous Details:");
            gotoxy(32,25);textcolor(11);
            cprintf(" %s ",p.recommendation);
            gotoxy(15,28);textcolor(2);
            strcat(p.recommendation,"-> ");
            printf("New Details:");
            fflush(stdin);
            scanf("%[^\n]",string);
            strcat(p.recommendation,string);
            break;
              }
        case 2:
              {
            clrscr();
            mainscreen();
            displaydepartment();
            gotoxy(28,10);  textcolor(7);
            cprintf("CHANGING SPECIALIST");
            gotoxy(27,11);textcolor(15);
            cprintf("---------------------");
            gotoxy(5,20);
            textcolor(2);
            cprintf("Previous Specialist:");
            gotoxy(26,20);textcolor(11);
            cprintf(" %s ",p.department);
            textcolor(15);gotoxy(5,27);
            cprintf(":Enter the new changed Specialist;");
            gotoxy(5,33);     textcolor(2);
            cprintf("Reff. Specialist no:");
            newrecord1();
            break;
              }
        case 3:
              {
               clrscr();
               mainscreen();
               gotoxy(28,10);  textcolor(7);
               cprintf("DEPOSITING MONEY");
               gotoxy(27,11);textcolor(15);
               cprintf("---------------------");
               gotoxy(20,20);
               textcolor(2);
               cprintf("Deposited balance: Rs.");
               fflush(stdin);
               scanf("%f",&d);
               p.balance=p.balance+d;
               break;
              }
        case 4:
              {
               clrscr();
               mainscreen();
               displaytest();
               gotoxy(45,13);textcolor(3);
               cprintf("Type `esc' tn content to stop");
               gotoxy(45,15);textcolor(15);
               cprintf("Contents");gotoxy(70,15);
            cprintf("Rs.");lk=0;
               for(i=17;1;i++,z++)
               {
                gotoxy(45,i);
                fflush(stdin);
                cprintf("%c ",16);
                scanf("%s",&p.test[z][0]);
                if(strcmp(&p.test[z][0],"esc")==0)
                {       labelh:
                    gotoxy(48,i+3);textcolor(15);
                    cprintf("Paid/Unpaid (p/u):");
                    scanf("%c",&v);
                    if(v=='p')
                    {
                    p.balance=p.balance+lk;
                    }
                    else if(v!='u')
                    {       gotoxy(48,i+2);
                           //    textcolor(4+128);
                           //    cprintf("Wrong Choice");
                        goto labelh;
                    }
                    break;
                }
                gotoxy(70,i);
                fflush(stdin);
                scanf("%f",&p.testfee[z]);
                lk=lk+p.testfee[z];
                p.totalfee=p.totalfee+p.testfee[z];
                i++;
               }
               break;
              }
        case 5:
              {
                       return;
              }

        default:
               {
               clrscr();
               mainscreen();gotoxy(30,13);textcolor(4+128);
               cprintf("Wromg choice");
               goto label2;
               }

    }
    clrscr();
    mainscreen();
    goto label2;
}
void editrecord()
{
    int y,x;
    gotoxy(20,20);textcolor(11);
    cprintf("Enter the patient `record no' or `Full name': ");gotoxy(25,24);

    fflush(stdin);
    scanf("%[^\n]",string);
    string[0]=toupper(string[0]);
    y=atoi(string);
    clrscr();
    mainscreen();
    if((fp=fopen(fn1,"rb+"))==NULL)
    {
        printf("\n cannot open the record file 1");
        getch();
        exit(1);
    }
      // rewind(fp);
    while(fread(&p,sizeof(p),1,fp))
    {
    if((p.sn==y)||(strcmp(p.name,string)==0))
        {
            print();
            edit1();gotoxy(22,46);textcolor(9);
            printf("Press `1'to edit or add and any key togo to main menu");
            fflush(stdin);
            scanf("%d",&x);
            if(x==1)
            {
              clrscr();
              mainscreen();
              switch1();
            }
            else
            return;
            rewind(fp);
            fseek(fp,(p.sn-1)*sizeof(p),SEEK_SET);
            fwrite(&p,sizeof(p),1,fp);
            fclose(fp);
            break;
        }
    }

    if(p.sn!=y)
    {
        gotoxy(22,25);textcolor(3);
        cprintf("There is no record available"); gotoxy(22,30);
        textcolor(15);
        cprintf("Press Enter to continue:"); getch();
    }


}
void displaytest()
{       int i;
    gotoxy(50,10);textcolor(14);
    cprintf("::ADDING SERVICES::");gotoxy(45,11);textcolor(15);
    cprintf("----------------------------");
    gotoxy(9,10);textcolor(6);
    cprintf(":PRICE LIST:");
    textcolor(15);
    gotoxy(4,11);
    cprintf("---------------------");
    gotoxy(5,14);textcolor(10);
    cprintf("1.X-Ray");
    gotoxy(30,14);textcolor(11);
    cprintf("Rs. 300.00");
    gotoxy(5,16);textcolor(10);
    cprintf("2.Ultra-sound");
    gotoxy(30,16);textcolor(11);
    cprintf("Rs. 500.00");
    gotoxy(5,18);textcolor(10);
    cprintf("3.C.T.Scan");
    gotoxy(30,18);textcolor(11);
    cprintf("Rs.1800.00");
    gotoxy(5,20);textcolor(10);
    cprintf("4.TC,DC,HB");
    gotoxy(30,20);textcolor(11);
    cprintf("Rs.  90.00");
    gotoxy(5,22);textcolor(10);
    cprintf("5.Urine R/E");
    gotoxy(30,22);textcolor(11);
    cprintf("Rs.  80.00");
    gotoxy(5,24);textcolor(10);
    cprintf("6.Blood C/S");
    gotoxy(30,24);textcolor(11);
    cprintf("Rs. 250.00");
    gotoxy(5,26);textcolor(10);
    cprintf("7.Biliribin D/T");
    gotoxy(30,26);textcolor(11);
    cprintf("Rs. 200.00");
    gotoxy(5,28);textcolor(10);
    cprintf("8.Stool Test");
    gotoxy(30,28);textcolor(11);
    cprintf("Rs.  60.00");
    gotoxy(5,30);textcolor(10);
    cprintf("9.Bed Charge");
    gotoxy(30,30);textcolor(11);
    cprintf("Rs. 150.00");
    gotoxy(5,32);textcolor(10);
    cprintf("10.Sugar Test");
    gotoxy(30,32);textcolor(11);
    cprintf("Rs. 400.00");
    textcolor(15);
    for(i=10;i<=46;i++)
    {
        gotoxy(41,i);
        cprintf("|");
    }
}
void mainscreen()
{
    int i,j;
    clrscr();
    for(i=2,j=2;i<rw;j++)
    {
        if(j>15)
        j=2;
        textcolor(j);
        gotoxy(i,2);
        cprintf("%c",15);
        gotoxy(i,cl-1);
        cprintf("%c",15);
        i++;

    }
    for(i=2,j=2;i<cl;i++,j++)
    {
        if(j>15)
        j=2;
        textcolor(j);
        gotoxy(2,i);
        cprintf("%c",15);
        gotoxy(rw-1,i);
        cprintf("%c",15);

    }
    gotoxy(30,4);textcolor(3);
    cprintf("GTA HOSPITAL");
    gotoxy(27,6);textcolor(6);
    cprintf("********VSKP*******");
    gotoxy(27,7); textcolor(15);
    cprintf("--------------------");
}

OUTPUT:-

C program for Contact Management System

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdlib.h>
#include<dos.h>
struct contact
{
    long ph;
    char name[20],add[20],email[30];
} list;
char query[20],name[20];
FILE *fp, *ft;
int i,n,ch,l,found;
int main()
{
main:
    system("cls");    /* ************Main menu ***********************  */
    printf("\n\t **** Welcome to Contact Management System ****");
    printf("\n\n\n\t\t\tMAIN MENU\n\t\t=====================\n\t\t[1] Add a new Contact\n\t\t[2] List all Contacts\n

\t\t[3] Search for contact\n\t\t[4] Edit a Contact\n\t\t[5] Delete a Contact\n\t\t[0] Exit\n\t\t=================\n

\t\t");
    printf("Enter the choice:");
    scanf("%d",&ch);
    switch(ch)
    {
    case 0:
        printf("\n\n\t\tAre you sure you want to exit?");
        break;
        /* *********************Add new contacts************  */
    case 1:
        system("cls");
        fp=fopen("contact.dll","a");
        for (;;)
        {
           fflush(stdin);
            printf("To exit enter blank space in the name input\nName (Use identical):");
            scanf("%[^\n]",&list.name);
            if(stricmp(list.name,"")==0 || stricmp(list.name," ")==0)
                break;
            fflush(stdin);
            printf("Phone:");
            scanf("%ld",&list.ph);
            fflush(stdin);
            printf("address:");
            scanf("%[^\n]",&list.add);
            fflush(stdin);
            printf("email address:");
            gets(list.email);
            printf("\n");
            fwrite(&list,sizeof(list),1,fp);
        }
        fclose(fp);
        break;
        /* *********************list of contacts*************************  */
    case 2:
        system("cls");
        printf("\n\t\t================================\n\t\t\tLIST OF CONTACTS\n\t\t================================

\n\nName\t\tPhone No\t    Address\t\tE-mail ad.\n=================================================================\n

\n");
        for(i=97; i<=122; i=i+1)
        {
            fp=fopen("contact.dll","r");
            fflush(stdin);
            found=0;
            while(fread(&list,sizeof(list),1,fp)==1)
            {
                if(list.name[0]==i || list.name[0]==i-32)
                {
                  printf("\nName\t: %s\nPhone\t: %ld\nAddress\t: %s\nEmail\t: %s\n",list.name,
                           list.ph,list.add,list.email);
                    found++;
                }
            }
            if(found!=0)
            {
               printf("=========================================================== [%c]-(%d)\n\n",i-32,found);
                getch();
            }

            fclose(fp);
        }
        break;
        /* *******************search contacts**********************  */
    case 3:
        system("cls");
        do
        {
            found=0;
            printf("\n\n\t..::CONTACT SEARCH\n\t===========================\n\t..::Name of contact to search: ");
            fflush(stdin);
            scanf("%[^\n]",&query);
            l=strlen(query);
            fp=fopen("contact.dll","r");
            system("cls");
            printf("\n\n..::Search result for '%s' \n===================================================\n",query);
            while(fread(&list,sizeof(list),1,fp)==1)
            {
                for(i=0; i<=l; i++)
                    name[i]=list.name[i];
                name[l]='\0';
                if(stricmp(name,query)==0)
                {
                    printf("\n..::Name\t: %s\n..::Phone\t: %ld\n..::Address\t: %s\n..::Email\t: %s

\n",list.name,list.ph,list.add,list.email);
                    found++;
                    if (found%4==0)
                    {
                        printf("..::Press any key to continue...");
                        getch();
                    }
                }
            }
           if(found==0)
                printf("\n..::No match found!");
            else
                printf("\n..::%d match(s) found!",found);
            fclose(fp);
            printf("\n ..::Try again?\n\n\t[1] Yes\t\t[0] No\n\t");
            scanf("%d",&ch);
        }
        while(ch==1);
        break;
        /* *********************edit contacts************************/
    case 4:
        system("cls");
        fp=fopen("contact.dll","r");
        ft=fopen("temp.dat","w");
        fflush(stdin);
        printf("..::Edit contact\n===============================\n\n\t..::Enter the name of contact to edit:");
        scanf("%[^\n]",name);
        while(fread(&list,sizeof(list),1,fp)==1)
        {
            if(stricmp(name,list.name)!=0)
                fwrite(&list,sizeof(list),1,ft);
        }
        fflush(stdin);
        printf("\n\n..::Editing '%s'\n\n",name);
        printf("..::Name(Use identical):");
        scanf("%[^\n]",&list.name);
        fflush(stdin);
        printf("..::Phone:");
        scanf("%ld",&list.ph);
        fflush(stdin);
        printf("..::address:");
        scanf("%[^\n]",&list.add);
        fflush(stdin);
        printf("..::email address:");
        gets(list.email);
        printf("\n");
        fwrite(&list,sizeof(list),1,ft);
        fclose(fp);
        fclose(ft);
        remove("contact.dll");
        rename("temp.dat","contact.dll");
        break;
        /* ********************delete contacts**********************/
    case 5:
        system("cls");
        fflush(stdin);
        printf("\n\n\t..::DELETE A CONTACT\n\t==========================\n\t..::Enter the name of contact to

delete:");
        scanf("%[^\n]",&name);
        fp=fopen("contact.dll","r");
        ft=fopen("temp.dat","w");
        while(fread(&list,sizeof(list),1,fp)!=0)
            if (stricmp(name,list.name)!=0)
                fwrite(&list,sizeof(list),1,ft);
        fclose(fp);
        fclose(ft);
        remove("contact.dll");
        rename("temp.dat","contact.dll");
        break;
    default:
        printf("Invalid choice");
        break;
    }
    printf("\n\n\n..::Enter the Choice:\n\n\t[1] Main Menu\t\t[0] Exit\n");
    scanf("%d",&ch);
    switch (ch)
    {
    case 1:
        goto main;
    case 0:
        break;
    default:
        printf("Invalid choice");
        break;
    }
    return 0;
}


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(GREEN);
            gotoxy(25,25);
            cprintf("\nA PROJECT BY SATEESH");
            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(WHITE);
          return;
       }


OUTPUT:-