Monday, 21 August 2017

Pyramid with stars

#include<stdio.h>

void main()
{
    int row, c, n, temp;

    printf("Enter the number of rows in pyramid of stars you wish to see ");
    scanf("%d", &n);

    temp = n;

    for (row = 1; row <= n; row++)
    {
        for (c = 1; c < temp; c++)
            printf(" ");

        temp--;

        for (c = 1; c <= 2 * row - 1; c++)
            printf("*");

        printf("\n");
    }//loop end

    return 0;
}

Guess the name project

#include<stdio.h>
#include<stdlib.h>
#define size 20
void loading(void);
void extra(void);
int i,ii,j,k,l;//COUNTER VARIABLES
int RN1,RN2,len,index;//RANDOM NUMBERS,LENGTH of NAME & INDEX of LETTER ENTERED
char ch,chr,name[size],correct[size]="-------------------",wrong[2*size]="---------------------------------------";
char crct[size],wrng[2*size],a,b;
char Boy_Name[180][size]= {
            "Abbas","Ali","Abid","Abrar","Adeel","Adil","Afzal","Afzaal","Ahmed","Kamran",
            "Abdullah","Ahmer","Ahsan","Ajmal","Akbar","Akhtar","Akram","Aqeel","Aqib","Aleem",
            "Shahid","Altaf","Amin","Amir","Amjad","Anwar","Arif","Arsalan","Arshad","Asad",
            "Fawad","Asim","Aslam","Ayaaz","Ayub","Azam","Azeem","Azhar","Aziz","Babar",
            "Hashaam","Bashir","Danial","Danish","Dawood","Ehtisham","Fahad","Faisal","Faiz","Farid",
            "Farrukh","Fawad","Fayaz","Fazal","Hasan","Hussain","Habib","Hafeez","Haider","Hamid",
            "Hameed","Haroon","Harris","Humayun","Ibrahim","Idrees","Iftikhar","Ijaz","Ilyas","Imran",
            "Inzamam","Iqbal","Irfan","Ishaq","Ismail","Jabbar","Jafar","Jalal","Jaleel","Jamal",
            "Jameel","Junaid","Javaid","Jawad","Kabir","Kaleem","Karim","Khalid","Latif","",
            "Mohammad","Mahmood","Majid","Mohsin","Mubashar","Mudassar","Munawar","Murtaza","Musharraf","Mustafa",
            "Muzaffar","Nabeel","Nadeem","Naeem","Nasir","Naseer","Noman","Naveed","Nawaz","Khaliq",
            "Qadir","Qaiser","Qasim","Raza","Rahim","Rahman","Rameez","Rashid","Rauf","Razzaq",
            "Riaz","Rizwan","Saad","Sabir","Sadaqat","Saeed","Saif","Sajid","Saqib","Salim",
            "Khawar","Araib","Salman","Shabbir","Sarfraz","Shafiq","Shahid","Shahzad","Shan","Sheharyar",
            "Sheraz","Shoaib","Shuja","Sohaib","Sohail","Adnan","Tahir","Taimoor","Tanvir","Tariq",
            "Umair","Umar","Usman","Uzair","Waheed","Wajid","Waqar","Wasi","Wasim","Yahya",
            "Yasir","Younis","Yousaf","Zafar","Zaheer","Zahid","Zain","Zaman","Zameer","Zeeshan",
            "Zia","Zohaib","Zubair","Badar","Farooq","Rehman","Waqas","Tabassum","Tasawar","Tayyab"
            };
char Girl_Name[180][size]={
            "Abida","Adeela","Afreen","Afsheen","Aisha","Alina","Amina","Ammara","Ambreen","Arfa",
            "Arzoo","Asma","Atiqa","Azra","Batool","Beenish","Benazir","Bina","Bushra","Fakhra",
            "Farah","Fareeha","Farida","Farzana","Fatima","Firdous","Ghazala","Hajira","Iffat","Irum",
            "Javeria","Kausar","Khadija","Kulsoom","Laila","Lubna","Madeeha","Maimoona","Maleeha","Mariam",
            "Mehek","Momina","Nadira","Nadia","Nafeesa","Nargis","Pakeeza","Parveen","Neelofar","Andaleeb",
            "Hania","Hadia","Hafsa","Hira","Hareem","Tehreem","Rabia","Raeesa","Raheela","Rashida",
            "Ruqaya","Saba","Sabiha","Sadia","Sabahat","Sabeen","Sehar","Saima","Sajida","Sakina",
            "Salma","Sameera","Sana","Sanober","Sara","Seema","Shabana","Shabnam","Shagufta","Shaista",
            "Shakeela","Shamim","Sharmeen","Zoha","Shazia","Shumaila","Sobia","Somaiya","Surayya","Shanza",
            "Sheeza","Tabassum","Tahira","Nasira","Taskeen","Tasneem","Tasawar","Ulfat","Umaira","Uzma",
            "Zunaira","Zahida","Shahida","Yasmeen","Zainub","Zarqa","Zuhra","Zulekha","Aneeqa","Shama",
            "Aalia","Hifza","Aiman","Fazeela","Habiba","Kiran","Aafia","Maleeha","Balqees","Abiha",
            "Arifa","Ambar","Atiya","Warda","Naseem","Sidra","Fozia","Muntaha","Zobia","Saudia",
            "Sofia","Huma","Hina","Sumaira","Rehana","Fajar","Noor","Aiza","Tooba","Resham",
            "Mehwish","Juggan","Iman","Hadiqa","Umaima","Sarwat","Fiza","Mehreen","Tania","Anam",
            "Neelum","Maheen","Iraj","Maham","Gia","Saira","Faiza","Haya","Maria","Meera",
            "Sunbal","Minahil","Natasha","Nosheen","Rubab","Sonia","Zeba","Zara","Deeba","Farwa",
            "Faryal","Fareeha","Mahira","Mahnoor","Maya","Naheed","Nimra","Nirma","Rahat","Sanam"
            };
void main()
    {
    clrscr();
    gotoxy(32,1);
    printf("INSTRUCTIONS:\n\nIn this game, computer will choose a name from a list of names of PAKISTANI boys& girls.\nIt will tell you whether the name chosen is of a BOY or a GIRL and it will");
    printf(" also tell you that how many LETTERS are there in the NAME. It will draw two lines as:----\t(TOTAL NUMBER of LETTERS in NAME)\n--------\t(NUMBER of WRONG characters you can enter)\nwhich");
    printf(" shows that the name chosen consists of 4 LETTERS & you have 8 chances to\nguess the CORRECT LETTERS (i.e. TWICE the LENGTH of NAME).\nThen you will have to START guessing LETTERS");
    printf(" by entering LETTERS. FOR EXAMPLE:\tIf the choosen name is \"ABRAR\" and you guessed \"a\", the computer will put it as:a--a-\n----------\nwhich shows that the letter guessed is PRESENT in");
    printf(" the name at FIRST & FOURTH\nPLACE. NEXT, if you guess \"s\", computer will put it as:\na--a-\ns---------\nwhich shows that the letter guessed is NOT PRESENT in the name. AND SO ON.\nIf the UPPER line fills");
    printf(" before the LOWER line,it means that you have\nSUCCESSFULLY guessed the name. \nIf the LOWER line fills BEFORE the UPPER line, it means that you have FAILED to guess the name. \n\nIf you");
    printf(" want to PLAY, press \"Y\". OTHERWISE, press \"N\" to QUIT. ");
    ch=getch();
//if user wants to play the game.
returnc:i=0;
    if(ch=='Y' || ch== 'y')
        {
        loading();
        strcpy(crct,correct);//copies CORRECT string to CRCT string.
        strcpy(wrng,wrong);//copies WRONG string to WRNG string.
        randomize();
        RN1=random(2);//1st random number.
        RN2=random(180);//2nd random number.
//check if the name to be choosen is of a BOY or a GIRL & assign the choosen name to string NAME.
        if(RN1==0)
            {
            printf("You Have to Guess the Name of a BOY");
            for(ii=0;ii<size;ii++)
                {
                name[ii]=Boy_Name[RN2][ii];
                if(Boy_Name[RN2][ii]=='\0')
                    break;
                }
            }
        else if(RN1==1)
            {
            printf("You Have to Guess the Name of a GIRL");
            for(ii=0;ii<size;ii++)
                {
                name[ii]=Girl_Name[RN2][ii];
                if(Girl_Name[RN2][ii]=='\0')
                    break;
                }
            }
//check LENGTH of NAME choosen.
        len=strlen(name);
        printf("\n\nNAME consists of %d CHARACTERS\n\n",len);
        printf("You have %d chances to guess the correct name\n\n",2*len);
//print the strings CRCT and WRNG.
        for(ii=0;ii<len;ii++)
            printf("%c",crct[ii]);
        printf("\n");
        for(ii=0;ii<2*len;ii++)
            printf("%c",wrng[ii]);


       input1:    for(i=i;;)
            {
        input:  if(i<=2*len)
                {
                index=-1;
                a=b='y';
                printf("\n\n%d chances left",2*len-i);
                printf("\n\nEnter Character ");
                }
                chr=getche();
                printf("\n");
//checks whether the entered character exists in the name or not.
                for(j=0;j<len;j++)
                    if(chr==name[j] || chr==name[j]-32 || chr-32==name[j])
                        {
                        index=j;
                        crct[index]=chr;
                        }
                if(index!=-1)
                    {
                    for(j=0;j<len;j++)
                        if(crct[j]=='-')
                            a='n';
                    if(a=='n')
                        {
                        extra();
                        goto input1;
                        }
                    else
                        {
                        extra();
                        gotoxy(28,13);
                            printf("CONGRATULATIONS! YOU WON");
                        gotoxy(17,15);
                            printf("Press 'y' to PLAY AGAIN or press 'n' to QUIT ");
                                ch=getch();
                        goto returnc;
                        }
                    }
                if(index==-1)
                    {
                    if(i==2*len)
                        goto exit;
                    else
                        for(l=0;l<=2*len;l++)
                            if(wrng[l]=='-')
                                {
                                wrng[l]=chr;
                                goto print;
                                }
                    }
//prints the new strings.
              print:clrscr();
                for(k=0;k<len;k++)
                    printf("%c",crct[k]);
                printf("\n\n");
                for(k=0;k<2*len;k++)
                    printf("%c",wrng[k]);
//Check whether the LOWER line is filled or not. If not, put 'b=n' & take input again until last chance.
                    for(j=0;j<=2*len;j++)
                        if(wrng[j]=='-')
                            b='n';
                    if(b=='n')
                        {
                        i++;
                        goto input;
                        }
                    else if(b=='y')
                        {
                        i++;
                        goto input;
                        }
            exit:   clrscr();
                gotoxy(34,11);
                    printf("SORRY! YOU LOST");
                gotoxy(20,13);
                    printf("The Name that was choosen is \"%s\"",name);
                gotoxy(17,15);
                    printf("Press 'y' to PLAY AGAIN or press 'n' to QUIT ");
                        ch=getch();
                goto returnc;
            }
        }
//if user don't want to play the game.
    else if(ch=='N' || ch=='n')
        {
        clrscr();
        gotoxy(31,12);
            printf("GOOD BYE...TAKE CARE");
        }
//if user enters the wrong input i.e. else than 'y' or 'n'.
    else
        {
        clrscr();
        gotoxy(24,12);
            printf("Press \"Y\" to PLAY & \"N\" to QUIT ");
                ch=getch();
        goto returnc;
        }
    getch();
    }



void extra()
    {
    clrscr();
    for(k=0;k<len;k++)
        printf("%c",crct[k]);
    printf("\n\n");
    for(k=0;k<2*len;k++)
        printf("%c",wrng[k]);
    }




void loading(void)
    {
    int z;
    for(z=5;z>=1;z--)
        {
        clrscr();
        gotoxy(36,10);
            printf("LOADING . . .");
        gotoxy(31,12);
            printf("%d Seconds Remaining",z);
        delay(1000);
        }
    clrscr();
    }

System clock poject

#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
void main()
{
int gd=DETECT,gm;
int x=320,y=240,r=200,i,h,m,s,thetamin,thetasec;
struct  time t;
char n[12][3]={"3","2","1","12","11","10","9","8","7","6","5","4"};
initgraph(&gd,&gm,"C:\\TC\\BGI");/*put the directory which contains
egavga.bgi*/
circle(x,y,210);
setcolor(4);
settextstyle(4,0,5);
for(i=0;i<12;i++)
    {
    if(i!=3)
        outtextxy(x+(r-14)*cos(M_PI/6*i)-10,y-(r-14)*sin(M_PI/6*i)-26,n[i]);
    else
        outtextxy(x+(r-14)*cos(M_PI/6*i)-20,y-(r-14)*sin(M_PI/6*i)-26,n[i]);
    }
gettime(&t);
printf("The current time is: %2d:%02d:%02d.%02d",t.ti_hour, t.ti_min,t.ti_sec, t.ti_hund);
while(!kbhit())
    {
    setcolor(5);
    setfillstyle(1,5);
    circle(x,y,10);
    floodfill(x,y,5);
    gettime(&t);
    if(t.ti_min!=m)
        {
        setcolor(0);
        line(x,y,x+(r-60)*cos(thetamin*(M_PI/180)),y-(r-60)*sin(thetamin*(M_PI/180)));
        circle(x+(r-80)*cos(thetamin*(M_PI/180)),y-(r-80)*sin(thetamin*(M_PI/180)),10);
        line(x,y,x+(r-110)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-110)*sin(M_PI/6*h-((m/2)*(M_PI/180))));
        circle(x+(r-130)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-130)*sin(M_PI/6*h-((m/2)*(M_PI/180))),10);
        }
    if(t.ti_hour>12)
        t.ti_hour=t.ti_hour-12;
    if(t.ti_hour<4)
        h=abs(t.ti_hour-3);
    else
        h=15-t.ti_hour;
    m=t.ti_min;
    if(t.ti_min<=15)
        thetamin=(15-t.ti_min)*6;
    else
        thetamin=450-t.ti_min*6;
    if(t.ti_sec<=15)
        thetasec=(15-t.ti_sec)*6;
    else
        thetasec=450-t.ti_sec*6;
    setcolor(4);
    line(x,y,x+(r-110)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-110)*sin(M_PI/6*h-((m/2)*(M_PI/180))));
    circle(x+(r-130)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-130)*sin(M_PI/6*h-((m/2)*(M_PI/180))),10);
    line(x,y,x+(r-60)*cos(thetamin*(M_PI/180)),y-(r-60)*sin(thetamin*(M_PI/180)));
    circle(x+(r-80)*cos(thetamin*(M_PI/180)),y-(r-80)*sin(thetamin*(M_PI/180)),10);
    setcolor(15);
    line(x,y,x+(r-70)*cos(thetasec*(M_PI/180)),y-(r-70)*sin(thetasec*(M_PI/180)));
    delay(1000);
    setcolor(0);
    line(x,y,x+(r-70)*cos(thetasec*(M_PI/180)),y-(r-70)*sin(thetasec*(M_PI/180)));
    }
}

Manual Clock Project

#include<graphics.h>
#include<stdio.h>
void clock(void);
void clock1(void);
void main()
{
int a,x,y,d,m;
d=DETECT;
initgraph(&d,&m,"C:\\TC\\BGI");
cleardevice();
setcolor(4);
outtextxy(100,100,"Press Any Key Repeatedly and See the Trick");
clock();
for(x=303,y=150;x<=353;x=x+5)
    {
    setcolor(4);
    line(303,210,x,y+5);
    getch();
    cleardevice();
    clock();
    }
for(x=353,y=155;x<=403,y<=180;x+=5,y+=3)
    {
    setcolor(4);
    line(303,210,x,y);
    getch();
    cleardevice();
    clock();
    }
for(x=403,y=180;y<=250;y=y+5)
    {
    setcolor(4);
    line(303,210,x,y);
    getch();
    cleardevice();
    clock();
    }
for(x=403,y=250;x>=350,y<=270;x-=5,y+=2)
    {
    setcolor(4);
    line(303,210,x,y);
    getch();
    cleardevice();
    clock();
    }
for(x=350,y=270;x>=250;x-=5)
    {
    setcolor(4);
    line(303,210,x,y);
    getch();
    cleardevice();
    clock();
    }
for(x=250,y=270;x>=200,y>=250;x-=4,y-=2)
    {
    setcolor(4);
    line(303,210,x,y);
    getch();
    cleardevice();
    clock();
    }
for(x=200,y=250;y>=170;y-=4)
    {
    setcolor(4);
    line(303,210,x,y);
    getch();
    cleardevice();
    clock();
    }
for(x=200,y=170;x<=250,y>=150;x+=5,y-=1)
    {
    setcolor(4);
    line(303,210,x,y);
    getch();
    cleardevice();
    clock();
    }
cleardevice();
clock1();
getch();
closegraph();
}

void clock(void)
{
setbkcolor(14);
setcolor(2);
outtextxy(350,150,"1");
outtextxy(250,150,"11");
outtextxy(300,150,"12");

outtextxy(400,170,"2");
outtextxy(400,210,"3");
outtextxy(400,250,"4");

outtextxy(350,270,"5");
outtextxy(300,270,"6");
outtextxy(250,270,"7");

outtextxy(200,250,"8");
outtextxy(200,210,"9");
outtextxy(200,170,"10");

setcolor(1);
line(180,130,420,130);
line(180,290,420,290);
line(180,130,180,290);
line(420,130,420,290);
circle(303,210,7);
setcolor(6);
setlinestyle(0,0,3);
line(303,210,303,250);
setcolor(11);
setlinestyle(0,5,2);
line(303,210,303,155);
}


void clock1(void)
{
setbkcolor(14);
setcolor(2);
outtextxy(350,150,"1");
outtextxy(250,150,"11");
outtextxy(300,150,"12");

outtextxy(400,170,"2");
outtextxy(400,210,"3");
outtextxy(400,250,"4");

outtextxy(350,270,"5");
outtextxy(300,270,"6");
outtextxy(250,270,"7");

outtextxy(200,250,"8");
outtextxy(200,210,"9");
outtextxy(200,170,"10");

setcolor(1);
line(180,130,420,130);
line(180,290,420,290);
line(180,130,180,290);
line(420,130,420,290);
circle(303,210,7);
setcolor(6);
setlinestyle(0,0,3);
line(303,210,303,250);
setcolor(11);
setlinestyle(0,5,2);
line(303,210,313,155);
setcolor(4);
line(303,210,303,155);
getch();
}

Auto clock Project

#include<graphics.h>
#include<stdio.h>
void clock(void);
void clock1(void);
void main()
{
int a,x,y,d,m;
d=DETECT;
initgraph(&d,&m,"C:\\TC\\BGI");
cleardevice();
setcolor(4);
clock();
for(x=303,y=150;x<=353;x=x+10)/*FROM 12 TO 1*/
    {
    setcolor(4);
    line(303,210,x,y+5);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=353,y=155;x<=403,y<=180;x+=10,y+=6)/*FROM 1 TO 2*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=403,y=180;y<=250;y+=10)/*FROM 2 TO 4*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=403,y=250;x>=350,y<=270;x-=10,y+=4)/*FROM 4 TO 5*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=350,y=270;x>=250;x-=10)/*FROM 5 TO 7*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=250,y=270;x>=200,y>=250;x-=8,y-=4)/*FROM 7 TO 8*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=200,y=250;y>=170;y-=8)/*FROM 8 TO 10*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
for(x=200,y=170;x<=250,y>=150;x+=10,y-=2)/*FROM 10 TO 11*/
    {
    setcolor(4);
    line(303,210,x,y);
    delay(1000);
    cleardevice();
    clock();
    }
cleardevice();
clock1();
getch();
closegraph();
}

void clock(void)
{
setbkcolor(14);
setcolor(2);
outtextxy(350,150,"1");
outtextxy(250,150,"11");
outtextxy(300,150,"12");

outtextxy(400,170,"2");
outtextxy(400,210,"3");
outtextxy(400,250,"4");

outtextxy(350,270,"5");
outtextxy(300,270,"6");
outtextxy(250,270,"7");

outtextxy(200,250,"8");
outtextxy(200,210,"9");
outtextxy(200,170,"10");

setcolor(1);
line(180,130,420,130);
line(180,290,420,290);
line(180,130,180,290);
line(420,130,420,290);
circle(303,210,7);
setcolor(6);
setlinestyle(0,0,3);
line(303,210,303,250);
setcolor(11);
setlinestyle(0,5,2);
line(303,210,303,155);
}


void clock1(void)
{
setbkcolor(14);
setcolor(2);
outtextxy(350,150,"1");
outtextxy(250,150,"11");
outtextxy(300,150,"12");

outtextxy(400,170,"2");
outtextxy(400,210,"3");
outtextxy(400,250,"4");

outtextxy(350,270,"5");
outtextxy(300,270,"6");
outtextxy(250,270,"7");

outtextxy(200,250,"8");
outtextxy(200,210,"9");
outtextxy(200,170,"10");

setcolor(1);
line(180,130,420,130);
line(180,290,420,290);
line(180,130,180,290);
line(420,130,420,290);
circle(303,210,7);
setcolor(6);
setlinestyle(0,0,3);
line(303,210,303,250);
setcolor(11);
setlinestyle(0,5,2);
line(303,210,313,155);
setcolor(4);
line(303,210,303,155);
getch();
}

DataBase project of class file 3

DataBase project of class file 3
void inputs(int c[],int so[],int ss[],int sss[],int k)
    {
    int i;
    printf("Enter Roll No.=");
        scanf("%d",&c[k]);
    for(i=0;i<k;i++)
        if(c[k]==c[i])
            {
            printf("Roll No. of Two Students cannot be Same.\n");
            printf("Enter Roll No. Again=");
                scanf("%d",&c[k]);
            }   
    printf("Enter MARKS of SUBJECT 1=");
        scanf("%d",&so[k]);
    printf("Enter MARKS of SUBJECT 2=");
        scanf("%d",&ss[k]);
    printf("Enter MARKS of SUBJECT 3=");
        scanf("%d",&sss[k]);
    }


void mao(int m[],int so[],int ss[],int sss[],int k)
    {
    m[k]=so[k]+ss[k]+sss[k];
    }


void age(float p[],int m[],int k)
    {
    p[k]=m[k]/3.0;
    }

   
void gra(int gd[],float p[],int k)
    {
    if(p[k]>=80)
        gd[k]=1;
    else if(p[k]>=70 && p[k]<80)
        gd[k]=2;
    else if(p[k]>=60 && p[k]<70)
        gd[k]=3;
    else if(p[k]>=50 && p[k]<60)
        gd[k]=4;
    else
        gd[k]=5;
    }


double cavg(int m[],int l)
    {
    int i,sum=0;
    double ca;
    for(i=0;i<l;i++)
        sum=sum+m[i];
    ca=sum/l;
    return ca;
    }


void first_last(int m[],int c[],int l)
    {
    int i,max=m[0],max_index=0,min=m[0],min_index=0;
    clrscr();
    for(i=1;i<l;i++)
        {
        if(max<m[i])
            {
            max=m[i];
            max_index=i;
            }
        else if(min>m[i])
            {
            min=m[i];
            min_index=i;
            }
        }
    printf("Roll Number of TOPPER Student is %d",c[max_index]);
    printf("\nRoll Number of NULL Student is %d",c[min_index]);
    }


void sortA_mao(int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int e[],int l)
    {
    int i,j,large,l_index;
    for(i=0;i<l-1;i++)
        {
        large=m[i];
        l_index=i;
        for(j=i+1;j<l;j++)
            {
            if(large<m[j])
                {
                large=m[j];
                l_index=j;
                }
            }
        m[l_index]=m[i];
        m[i]=large;
       
       
        e[i]=c[i];
        c[i]=c[l_index];
        c[l_index]=e[i];           
            e[i]=so[i];
            so[i]=so[l_index];
            so[l_index]=e[i];
        e[i]=ss[i];
        ss[i]=ss[l_index];
        ss[l_index]=e[i];
            e[i]=sss[i];
            sss[i]=sss[l_index];
            sss[l_index]=e[i];
        e[i]=p[i];
        p[i]=p[l_index];
        p[l_index]=e[i];
            e[i]=gd[i];
            gd[i]=gd[l_index];
            gd[l_index]=e[i];
        }
    }


void sortD_mao(int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int e[],int l)
    {
    int i,j,small,s_index;
    for(i=0;i<l-1;i++)
        {
        small=m[i];
        s_index=i;
        for(j=i+1;j<l;j++)
            {
            if(small>m[j])
                {
                small=m[j];
                s_index=j;
                }
            }
        m[s_index]=m[i];
        m[i]=small;
       
       
        e[i]=c[i];
        c[i]=c[s_index];
        c[s_index]=e[i];           
            e[i]=so[i];
            so[i]=so[s_index];
            so[s_index]=e[i];
        e[i]=ss[i];
        ss[i]=ss[s_index];
        ss[s_index]=e[i];
            e[i]=sss[i];
            sss[i]=sss[s_index];
            sss[s_index]=e[i];
        e[i]=p[i];
        p[i]=p[s_index];
        p[s_index]=e[i];
            e[i]=gd[i];
            gd[i]=gd[s_index];
            gd[s_index]=e[i];
        }
    }


void fetch(int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int el,int l)
    {
    int i,a,loc=-1;
    char g;
    clrscr();
    printf("R.No.\tSUB 1\tSUB 2\tSUB 3\tT.MARKS\t%AGE\tGRADE");
    for(i=0;i<l;i++)
        {
        switch(gd[i])
            {
            case 1:
                g='A';
                break;
            case 2:
                g='B';
                break;
            case 3:
                g='C';
                break;
            case 4:
                g='D';
                break;
            case 5:
                g='F';
                break;
            }
        if(el==c[i])
            {
            loc=i;
            break;
            }
        }   
        if(loc==-1)
            printf("\nSORRY! \x1 RECORD OF \"%d\" DOES NOT EXIST.",el);
        else
            {
            printf("\n%d\t%d\t%d\t%d\t%d\t%0.2f\t%c",c[loc],so[loc],ss[loc],sss[loc],m[loc],p[loc],g);
            }
    }


void display(int s[],int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int l,double ca)
    {
    int i;
    char g;
    clrscr();
    printf("S.No.\tR.No.\tSUB 1\tSUB 2\tSUB 3\tT.MARKS\t%AGE\tGRADE\n");
    for(i=0;i<l;i++)
        {
        s[i]=i+1;
        switch(gd[i])
            {
            case 1:
                g='A';
                break;
            case 2:
                g='B';
                break;
            case 3:
                g='C';
                break;
            case 4:
                g='D';
                break;
            case 5:
                g='F';
                break;
            }
        printf("%d\t%d\t%d\t%d\t%d\t%d\t%0.2f\t%c\n",s[i],c[i],so[i],ss[i],sss[i],m[i],p[i],g);
        }
    printf("\nCLASS AVERAGE is=%0.2f",ca);
    }


void S_display(int c[],int so[],int ss[],int sss[],int m[],float p[],int gd[],int l,double ca)
    {
    int i;
    char g;
    clrscr();
    printf("R.No.\tSUB 1\tSUB 2\tSUB 3\tT.MARKS\t%AGE\tGRADE\n");
    for(i=0;i<l;i++)
        {
        switch(gd[i])
            {
            case 1:
                g='A';
                break;
            case 2:
                g='B';
                break;
            case 3:
                g='C';
                break;
            case 4:
                g='D';
                break;
            case 5:
                g='F';
                break;
            }
        printf("%d\t%d\t%d\t%d\t%d\t%0.2f\t%c\n",c[i],so[i],ss[i],sss[i],m[i],p[i],g);
        }
    printf("\nCLASS AVERAGE is=%0.2f",ca);
    }

DataBase project of class .H file

#include<stdio.h>
#include<database.h>
#include<graphics.h>
#define s 60
int sn[s],cn[s],s1[s],s2[s],s3[s],mo[s],gr[s],ex[s];
float page[s];
double cav;
void main()
{
int m,d,m1,j,t,e;
char ch;
d=DETECT;
initgraph(&d,&m,"C:\\TC\\BGI");
cleardevice();
setcolor(10);
setbkcolor(8);
printf("Enter NUMBER of Students in the CLASS:");
    scanf("%d",&m1);
for(j=0;j<m1;j++)
    {
    inputs(cn,s1,s2,s3,j);
        mao(mo,s1,s2,s3,j);
    age(page,mo,j);
        gra(gr,page,j);
    }
cav=cavg(mo,m1);
display(sn,cn,s1,s2,s3,mo,page,gr,m1,cav);
printf("\n\nDo You Want to See who is TOPPER & who is NULL ?(Y/N)");
    ch=getch();
if(ch=='y' || ch=='Y')
    first_last(mo,cn,m1);
else
    printf("\nOK");
printf("\n\nDo You Want to Sort the Table w.r.t T.MARKS ?(Y/N)");
    ch=getch();
if(ch=='y' || ch=='Y')
    {
    printf("\nPress 'a' for ASCENDING ORDER & 'd' for DESCENDING ORDER");
        ch=getch();
    if(ch=='a' || ch=='A')
        {
        sortA_mao(cn,s1,s2,s3,mo,page,gr,ex,m1);
        S_display(cn,s1,s2,s3,mo,page,gr,m1,cav);
        }
    else
        {
        sortD_mao(cn,s1,s2,s3,mo,page,gr,ex,m1);
        S_display(cn,s1,s2,s3,mo,page,gr,m1,cav);
        }
    }
else
    printf("\nOK");
printf("\nDo You Want to See the Records of Particular Students ?(Y/N)");
    ch=getch();
if(ch=='y' || ch=='Y')
    {
    clrscr();
    printf("How Many RECORDS You want to See ?");
        scanf("%d",&t);
    for(j=1;j<=t;j++)
        {
        printf("\nEnter Class No. of the Student Whose Record You Want to Fetch:");
        scanf("%d",&e);
        fetch(cn,s1,s2,s3,mo,page,gr,e,m1);
        }
    }
else
    printf("\nOK");
getch();
closegraph();
}

Sunday, 20 August 2017

pateint.java java examples

package ACP.Patient;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.io.*;

class Patient implements Serializable
{
    private String patientName;
    private String fatherName;
    private String diseaseCategory;
    private String patientCNIC;
    private String doctorName;
    private String prescription;
    private String diseaseHistory;
    private Date   dateOfBirth;
    private int    patientID;
   
    private static int nextID = 0;
//////////-----------------------------Constructor-----------------------------//////////
    Patient()
    {
        this.setPatientInfo();
    }
//////////-----------------------Method setPatientInfo------------------------//////////
    void setPatientInfo()
    {
        String[] diseaseCategories = {"", "Heart", "ENT", "Diabetic", "Brain", "Orthopedic", "General"};
        String[] doctors       = {"", "Dr. Faridullah Khan(Cardiologist)", "Dr. Muhammad Tariq(ENT Specialist)", "Dr. Muhammad Faisal(Diabetes Specialist)", "Dr. Ejaz Ahmed(Neurologist)", "Dr. Ali Akhtar(Orthopedic Surgeon)", "Dr. Rauf Niazi(General Surgeon)"};
        Date currentDate        = new Date();
        DateFormat df           = new SimpleDateFormat("dd/MM/yyyy");
        String tempPrescription       = null;
              //////////////////////////////////////////////////////////////////////////
        this.patientName = JOptionPane.showInputDialog("Enter Patient's Name:");
        while(this.patientName.length()== 0)
            this.patientName = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's Name:");
              //////////////////////////////////////////////////////////////////////////
        this.fatherName = JOptionPane.showInputDialog("Enter Father's Name:");
        while(this.fatherName.length() == 0)
            this.fatherName = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Father's Name:");
              //////////////////////////////////////////////////////////////////////////
        String dOB = JOptionPane.showInputDialog(null, "Enter Patient's Date of Birth:", "dd/MM/yyyy");
        while(true)
        {
            try
            {
                this.dateOfBirth = df.parse(dOB);
                break;
            }
            catch (ParseException e)
            {
                dOB = JOptionPane.showInputDialog(null, "Invalid Input. Enter Again\n\nEnter Patient's Date of Birth:", "dd/MM/yyyy");
            }
        }
              //////////////////////////////////////////////////////////////////////////
        this.patientCNIC = JOptionPane.showInputDialog(null, "Enter Patient's CNIC:", "xxxxx-xxxxxxx-x");
        while(this.patientCNIC.length() == 0 || this.patientCNIC.equals("xxxxx-xxxxxxx-x"))
            this.patientCNIC = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's CNIC:", "xxxxx-xxxxxxx-x");
              //////////////////////////////////////////////////////////////////////////
        this.diseaseCategory = (String) JOptionPane.showInputDialog(null, "Select Patient's Disease Category:", null, JOptionPane.QUESTION_MESSAGE, null, diseaseCategories, diseaseCategories[0]);
        while(this.diseaseCategory.equals(diseaseCategories[0]))
            this.diseaseCategory = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Patient's Disease Category:", null, JOptionPane.ERROR_MESSAGE, null, diseaseCategories, diseaseCategories[0]);
              //////////////////////////////////////////////////////////////////////////
        this.doctorName = (String) JOptionPane.showInputDialog(null, "Select Doctor's Name:", null, JOptionPane.QUESTION_MESSAGE, null, doctors, doctors[0]);
        while(this.doctorName.equals(doctors[0]))
            this.doctorName    = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Doctor's Name:", null, JOptionPane.ERROR_MESSAGE, null, doctors, doctors[0]);
          //////////////////////////////////////////////////////////////////////////
        tempPrescription = JOptionPane.showInputDialog("Enter Prescription:");
        while(tempPrescription.length() == 0)
            tempPrescription = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Prescription:");
        this.prescription   = df.format(currentDate) + "\t" + tempPrescription;
              //////////////////////////////////////////////////////////////////////////
        this.diseaseHistory = df.format(currentDate) + "\t" + this.doctorName + "\t" + tempPrescription;
              //////////////////////////////////////////////////////////////////////////
        if(nextID != 0)
            this.patientID = nextID++;
        else
        {
            nextID         = 9001;
            this.patientID = nextID++;
        }
              //////////////////////////////////////////////////////////////////////////
        JOptionPane.showMessageDialog(null, new JTextArea("Patient ID:\t" + this.patientID + "\nName:\t" + this.patientName + "\nFather Name:\t" + this.fatherName + "\nDate of Birth:\t" + df.format(this.dateOfBirth) + "\nPatient CNIC:\t" + this.patientCNIC + "\nCategory:\t" + this.diseaseCategory + "\nDoctor Name:\t" + this.doctorName + "\nPrescription:\t" + this.prescription + "\nHistory:\t" + this.diseaseHistory), "Patient Added", JOptionPane.INFORMATION_MESSAGE);
    }
//////////----------------------Method updatePatientInfo----------------------//////////
    void updatePatientInfo(Patient[] p, int arraySearchSize)
    {
        String[] doctors = {"", "Dr. Faridullah Khan(Cardiologist)", "Dr. Muhammad Tariq(ENT Specialist)", "Dr. Muhammad Faisal(Diabetes Specialist)", "Dr. Ejaz Ahmed(Neurologist)", "Dr. Ali Akhtar(Orthopedic Surgeon)", "Dr. Rauf Niazi(General Surgeon)"};
        String input     = JOptionPane.showInputDialog("Enter Patient's ID(a number) Whose Information You Want to Update:");
        while(input.length() == 0)
            input    = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's ID(a number) Whose Information You Want to Update:");
       
        int iDtoSearch;
        while(true)
        {
            try
            {
                iDtoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's ID(a number) Whose Information You Want to Update:");
            }
        }
       
        int foundAtIndex = searchIDs_Index(p, arraySearchSize, iDtoSearch);
        if(foundAtIndex == -1)
            JOptionPane.showMessageDialog(null, "No Patient Found with ID '" + iDtoSearch + "'", "Invalid ID", JOptionPane.ERROR_MESSAGE);
        else
        {
            input = (String) JOptionPane.showInputDialog(null, "Select Doctor's Name:", null, JOptionPane.QUESTION_MESSAGE, null, doctors, doctors[0]);
            while(input.length() == 0)
                input = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Doctor's Name:", null, JOptionPane.QUESTION_MESSAGE, null, doctors, doctors[0]);
            p[foundAtIndex].doctorName = input;
            showPatientInfo(p, foundAtIndex);
        }
    }
//////////--------------Method updatePrescriptionDiseaseHistory--------------//////////
    void updatePrescriptionDiseaseHistory(Patient[] p, int arraySearchSize)
    {
        Date currentDate = new Date();
        DateFormat df    = new SimpleDateFormat("dd/MM/yyyy");
        String input     = JOptionPane.showInputDialog("Enter Patient's ID(a number) Whose Prescription You Want to Update:");
        while(input.length() == 0)
            input    = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's ID(a number) Whose Prescription You Want to Update:");
       
        int iDtoSearch;
        while(true)
        {
            try
            {
                iDtoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's ID(a number) Whose Prescription You Want to Update:");
            }
        }
        int foundAtIndex = searchIDs_Index(p, arraySearchSize, iDtoSearch);
        String newPrescription;
        if(foundAtIndex == -1)
            JOptionPane.showMessageDialog(null, "No Patient Found with ID '" + iDtoSearch + "'", "Invalid ID", JOptionPane.ERROR_MESSAGE);
        else
        {
            newPrescription = JOptionPane.showInputDialog("Enter New Prescription:");
            while(newPrescription.length() == 0)
                newPrescription = (String) JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter New Prescription:");
            p[foundAtIndex].prescription   = p[foundAtIndex].prescription + "\n\t" + df.format(currentDate) + "\t" + newPrescription;
            p[foundAtIndex].diseaseHistory = p[foundAtIndex].diseaseHistory + "\n\t" + df.format(currentDate) + "\t" + p[foundAtIndex].doctorName + "\t" + newPrescription;
             showPatientInfo(p, foundAtIndex);
        }
    }
//////////---------------------Method deletePatientInfo----------------------//////////
    int deletePatientInfo(Patient[] p, int arraySearchSize)
    {
        String input  = JOptionPane.showInputDialog("Enter Patient's ID(a number) Whose Record You Want to Delete:");
        while(input.length() == 0)
            input = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's ID(a number) Whose Record You Want to Delete:");
       
        int iDtoSearch;
        while(true)
        {
            try
            {
                iDtoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's ID(a number) Whose Record You Want to Delete:");
            }
        }
        int foundAtIndex = searchIDs_Index(p, arraySearchSize, iDtoSearch);
        if(foundAtIndex == -1)
            JOptionPane.showMessageDialog(null, "No Patient Found with ID '" + iDtoSearch + "'", "Invalid ID", JOptionPane.ERROR_MESSAGE);
        else
            for(int j = foundAtIndex; j < arraySearchSize; j++)
            {
                if(j == arraySearchSize - 1)
                {
                    JOptionPane.showMessageDialog(null, "Record of Patient ID " + iDtoSearch + " is Deleted", "Record Deleted", JOptionPane.INFORMATION_MESSAGE);
                    p[j] = null;
                    return (--arraySearchSize);
                }
                else
                    p[j] = p[j+1];
            }
        return arraySearchSize;
    }
//////////---------------------Method searchView_patientID--------------------//////////
    void searchView_patientID(Patient[] p, int arraySearchSize)
    {
        String input  = JOptionPane.showInputDialog("Enter Patient's ID(a number) Whose Record You Want to Search:");
        while(input.length() == 0)
            input = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's ID(a number) Whose Record You Want to Search:");
       
        int iDtoSearch;
        while(true)
        {
            try
            {
                iDtoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's ID(a number) Whose Record You Want to Search:");
            }
        }
        int foundAtIndex = searchIDs_Index(p, arraySearchSize, iDtoSearch);
        if(foundAtIndex == -1)
            JOptionPane.showMessageDialog(null, "No Patient Found with ID '" + iDtoSearch + "'", "Invalid ID", JOptionPane.ERROR_MESSAGE);
        else
            showPatientInfo(p, foundAtIndex);
    }
//////////--------------------Method searchView_patientName------------------//////////
    void searchView_patientName(Patient[] p, int arraySearchSize)
    {
        DateFormat df  = new SimpleDateFormat("dd/MM/yyyy");
        int totalFound = 0;
        String name    = JOptionPane.showInputDialog("Enter Patient's Name Whose Record You Want to Search:");
        while(name.length() == 0)
            name   = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's Name Whose Record You Want to Search:");
        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize && totalFound == 0)
                JOptionPane.showMessageDialog(null, "No Patient Found with Name '" + name + "'", "Record Not Found", JOptionPane.ERROR_MESSAGE);
            else if(i == arraySearchSize)
                break;
            else if(p[i].patientName.equals(name))
            {
                showPatientInfo(p, i);
                totalFound++;
            }
        }
    }
//////////-------------------Method searchView_patientAge--------------------//////////
    void searchView_patientAge(Patient[] p, int arraySearchSize)
    {
        Date currentDate = new Date();
        int totalFound   = 0;
        String input     = JOptionPane.showInputDialog("Enter Patient's Age(a number) Whose Record You Want to Search:");
        while(input.length() == 0)
            input    = JOptionPane.showInputDialog("Field Cannot Be Empty\nEnter Patient's Age(a number) Whose Record You Want to Search:");
       
        int AgetoSearch;
        while(true)
        {
            try
            {
                AgetoSearch = Integer.parseInt(input);
                break;
            }
            catch (NumberFormatException nFE)
            {
                input = JOptionPane.showInputDialog("Please Enter a Number\nEnter Patient's Age(a number) Whose Record You Want to Search:");
            }
        }

        int age;
        int curMonth;
        int birthMonth;
        int curDate;
        int birthDate;

        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize && totalFound == 0)
                JOptionPane.showMessageDialog(null, "No Patient Found with Age '" + AgetoSearch + "'", "Record Not Found", JOptionPane.ERROR_MESSAGE);
            else if(i == arraySearchSize)
                break;
            else
            {
                age       = currentDate.getYear() - p[i].dateOfBirth.getYear();
               
                curMonth   = currentDate.getMonth();
                birthMonth = p[i].dateOfBirth.getMonth();
                curDate       = currentDate.getDate();
                birthDate  = p[i].dateOfBirth.getDate();

                if(curMonth < birthMonth || (curMonth == birthMonth && curDate < birthDate))
                    age--;

                if(AgetoSearch == age)
                {
                    showPatientInfo(p, i);
                    totalFound++;
                }
            }
        }
    }
//////////----------------Method searchView_diseaseCategory------------------//////////
    void searchView_diseaseCategory(Patient[] p, int arraySearchSize)
    {
        String[] diseaseCategories = {"", "Heart", "ENT", "Diabetic", "Brain", "Orthopedic", "General"};
        int totalFound               = 0;
        String categoryToSearch    = (String) JOptionPane.showInputDialog(null, "Select Patient's Disease Category Whose Record You Want to Search:", null, JOptionPane.QUESTION_MESSAGE, null, diseaseCategories, diseaseCategories[0]);
        while(categoryToSearch.equals(diseaseCategories[0]))
            categoryToSearch   = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Patient's Disease Category Whose Record You Want to Search:", null, JOptionPane.ERROR_MESSAGE, null, diseaseCategories, diseaseCategories[0]);
       
        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize && totalFound == 0)
                JOptionPane.showMessageDialog(null, "No Patient Found in '" + categoryToSearch + "' Category", "Record Not Found", JOptionPane.ERROR_MESSAGE);
            else if(i == arraySearchSize)
                break;
            else if(p[i].diseaseCategory.equals(categoryToSearch))
            {
                showPatientInfo(p, i);
                totalFound++;           
            }
        }
    }
//////////-----------------Method searchView_doctorName---------------------//////////
    void searchView_doctorName(Patient[] p, int arraySearchSize)
    {
        String[] doctors = {"", "Dr. Faridullah Khan(Cardiologist)", "Dr. Muhammad Tariq(ENT Specialist)", "Dr. Muhammad Faisal(Diabetes Specialist)", "Dr. Ejaz Ahmed(Neurologist)", "Dr. Ali Akhtar(Orthopedic Surgeon)", "Dr. Rauf Niazi(General Surgeon)"};
        int totalFound   = 0;
        String docName     = (String) JOptionPane.showInputDialog(null, "Select Patient's Doctor Name Whose Record You Want to Search:", null, JOptionPane.QUESTION_MESSAGE, null, doctors, doctors[0]);
        while(docName.equals(doctors[0]))
            docName     = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nSelect Patient's Doctor Name Whose Record You Want to Search:", null, JOptionPane.ERROR_MESSAGE, null, doctors, doctors[0]);
       
        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize && totalFound == 0)
                JOptionPane.showMessageDialog(null, "No Patient is Treated by '" + docName + "'", "Record Not Found", JOptionPane.ERROR_MESSAGE);
            else if(i == arraySearchSize)
                break;
            else if(p[i].doctorName.equals(docName))
            {
                showPatientInfo(p, i);
                totalFound++;           
            }
        }
    }
      //_____________________________________________________________
    private int searchIDs_Index(Patient[] p, int arraySearchSize, int iDtoSearch)
    {
        for(int i = 0; i <= arraySearchSize; i++)
        {
            if(i == arraySearchSize)
                return -1;
            else if(p[i].patientID == iDtoSearch)
                return i;
        }
        return -1;
    }
      //_____________________________________________________________
    private void showPatientInfo(Patient[] p, int indexToShow)
    {
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        JOptionPane.showMessageDialog(null, new JTextArea("Patient ID:\t" + p[indexToShow].patientID + "\nName:\t" + p[indexToShow].patientName + "\nFather Name:\t" + p[indexToShow].fatherName + "\nDate of Birth:\t" + df.format(p[indexToShow].dateOfBirth) + "\nPatient CNIC:\t" + p[indexToShow].patientCNIC + "\nCategory:\t" + p[indexToShow].diseaseCategory + "\nDoctor Name:\t" + p[indexToShow].doctorName + "\nPrescription:\t" + p[indexToShow].prescription + "\nHistory:\t" + p[indexToShow].diseaseHistory), "Patient Information", JOptionPane.INFORMATION_MESSAGE);
    }
      //_____________________________________________________________
    static void readNextID()
    {
        String iDFileName = "ACP\\NextID.txt";
        try
        {
            DataInputStream dIS = new DataInputStream(new FileInputStream(iDFileName));
            Patient.nextID        = (int) dIS.readInt();
            dIS.close();   
        }
        catch(FileNotFoundException fNFE){}
        catch(IOException iOE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Reading NextId", JOptionPane.ERROR_MESSAGE);
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Reading NextId", JOptionPane.ERROR_MESSAGE);
        }
    }
      //_____________________________________________________________
    static void writeNextID()
    {
        String iDFileName = "ACP\\NextID.txt";
        try
        {
            DataOutputStream dOS = new DataOutputStream(new FileOutputStream(iDFileName));
            dOS.writeInt(Patient.nextID);
            dOS.close();
        }
        catch(IOException iOE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Writing NextId", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Writing NextID", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }   
    }
}

client.java examples of java

package ACP.Patient;

import javax.swing.JOptionPane;
import java.io.*;
//////////////////////////////////////////////////////
class Client
{
    public static void main(String[] fileName)
    {
        final int ARRAY_SIZE    = 50;
        Patient []patient    = new Patient[ARRAY_SIZE];
        int numPatients        = 0;
        String[] choices    = {"", "Add New Patient Record", "Update Patient Information", "Update Prescription & Disease History", "Delete Patient Record", "Search & View Patient Record By Patient ID", "Search & View Patient Record By Patient Name", "Search & View Patient Record By Patient Age", "Search & View Patient Record By Disease category", "Search & View Patient Record By Doctor Name", "Exit"};
        String[] Continue    = {"", "Yes", "No"};
        ObjectOutputStream oOS    = null;
        ObjectInputStream  oIS    = null;
    //////////////////////////////////////////////////////
        String choice        = null;
        String cont        = null;
        int i            = 0;                   
    /////////////////////////////////////////////////////
        if(fileName.length == 0)
        {
            JOptionPane.showMessageDialog(null, "File Name Not Sent From Command Line\nExecute Again With File Name", "Error", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
    ////////////////////////////////////////////////////
        try
        {
            Patient temp = null;
            oIS         = new ObjectInputStream(new FileInputStream(fileName[0]));
            for(i = 0; i < ARRAY_SIZE; i++)
            {
                temp = (Patient) oIS.readObject();
                if(temp != null)
                {
                    patient[i] = temp;
                    numPatients++;
                }
            }
            oIS.close();
        }
        catch(ClassNotFoundException cNFE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + cNFE, "Class Not Found Exception in Reading Objects", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        catch(FileNotFoundException fNFE){}
        catch(EOFException eOFE){}
        catch(IOException iOE)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Reading Objects", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Reading Objects", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }

        Patient.readNextID();
    ///////////////////////////////////////////////////
        do
        {
            choice = (String) JOptionPane.showInputDialog(null, "What You Want To Do ?", "Main Menu", JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]);
            while(choice.equals(choices[0]))
                choice = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nWhat You Want To Do ?", "Main Menu", JOptionPane.ERROR_MESSAGE, null, choices, choices[0]);
       
            if(choice.equals(choices[1]))
            {
                if(numPatients < 0 || numPatients >= ARRAY_SIZE)
                    JOptionPane.showMessageDialog(null, "No Space for New patients :(", "Database Full", JOptionPane.WARNING_MESSAGE);
                else
                {
                    patient[numPatients] = new Patient();
                    numPatients++;
                }               
            }
            else if(choice.equals(choices[2]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].updatePatientInfo(patient, numPatients);
            }   
            else if(choice.equals(choices[3]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].updatePrescriptionDiseaseHistory(patient, numPatients);
            }
            else if(choice.equals(choices[4]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    numPatients = patient[0].deletePatientInfo(patient, numPatients);
            }
            else if(choice.equals(choices[5]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_patientID(patient, numPatients);
            }
            else if(choice.equals(choices[6]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_patientName(patient, numPatients);
            }
            else if(choice.equals(choices[7]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_patientAge(patient, numPatients);
            }
            else if(choice.equals(choices[8]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_diseaseCategory(patient, numPatients);
            }
            else if(choice.equals(choices[9]))
            {
                if(numPatients <= 0)
                    JOptionPane.showMessageDialog(null, "No Records Available", "Database Empty", JOptionPane.WARNING_MESSAGE);
                else
                    patient[0].searchView_doctorName(patient, numPatients);
            }
            else if(choice.equals(choices[10]))
            {
                JOptionPane.showMessageDialog(null, "Good Bye", "Exiting", JOptionPane.PLAIN_MESSAGE);
                               
                if(numPatients > 0)
                {
                    try                       
                    {
                        oOS = new ObjectOutputStream(new FileOutputStream(fileName[0]));
                        for(i = 0; i < ARRAY_SIZE; i++)
                            oOS.writeObject(patient[i]);
                        oOS.close();
                    }
                    catch(IOException iOE)
                    {
                        JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
                    }
                    catch(Exception e)
                    {
                        JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
                    }

                    Patient.writeNextID();
                }
                System.exit(0);
            }
            cont = (String) JOptionPane.showInputDialog(null, "Want to go back to Main Menu ?", "Continue or Exit", JOptionPane.QUESTION_MESSAGE, null, Continue, Continue[0]);
            while(cont.equals(Continue[0]))
                cont = (String) JOptionPane.showInputDialog(null, "Field Cannot Be Empty\nWant to go back to Main Menu ?", "Continue or Exit", JOptionPane.ERROR_MESSAGE, null, Continue, Continue[0]);
        }
        while(cont.equals(Continue[1]));
    ///////////////////////////////////////////////////
        JOptionPane.showMessageDialog(null, "Good Bye", "Exiting", JOptionPane.PLAIN_MESSAGE);
       
        if(numPatients > 0)
        {
            try                       
            {
                oOS = new ObjectOutputStream(new FileOutputStream(fileName[0]));
                for(i = 0; i < ARRAY_SIZE; i++)
                    oOS.writeObject(patient[i]);
                oOS.close();
            }
            catch(IOException iOE)
            {
                JOptionPane.showMessageDialog(null, "Error\n" + iOE, "I/O Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
            }
            catch(Exception e)
            {
                JOptionPane.showMessageDialog(null, "Error\n" + e, "Exception in Writing Objects", JOptionPane.ERROR_MESSAGE);
            }
        }

        Patient.writeNextID();
    ///////////////////////////////////////////////////
    }
}