📄 hospmgmt.c
字号:
/***************************************************************************
* File : HOSPITAL.C
* Description : Hospital management system to maintain patient details as well
as staff details..
* Author : I.Mohamed Bari,05CA032,II Year MCA,Karunya University.
* Version : 1.0
* Date : 1/feb/2007
****************************************************************************/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
/****************************************************************************
* Function : main
* Description :The main function is used for whole hospital management process.
* Parameters : void
* Returns : Void
*****************************************************************************/
void main()
{
int iCh1,iInc;
e:
clrscr();
/* To Display Main menu */
gotoxy(26,40);
textcolor(9);
cprintf("INFOSYS CAMPUS CONNECT PROGRAM");
gotoxy(32,44);
textcolor(19);
cprintf("KARUNYA UNIVERSITY");
gotoxy(16,42);
cprintf("HOSPITAL MANAGEMENT SYSTEM DONE BY MOHAMED BARI.I");
gotoxy(8,45);
textcolor(9);
/* To Dispaly date and time */
cprintf("DATE : %s ",__DATE__);
gotoxy(55,45);
cprintf("TIME : %s ",__TIME__);
for(iInc=0;iInc<=30;iInc++)
{
gotoxy(20,iInc);
textcolor(7);
cprintf("-");
}
for(iInc=0;iInc<80;iInc++)
{
gotoxy(iInc,30);
textcolor(7);
cprintf("|");
}
gotoxy(30,8);
textcolor(9);
/* Main menu */
cprintf("HOSPITAL MANAGEMENT SYSTEM");
gotoxy(30,10);
textcolor(19);
cprintf("1.OUT PATIENT");
gotoxy(30,12);
cprintf("2.IN PATIENT");
gotoxy(30,14);
cprintf("3.STAFF");
gotoxy(30,16);
cprintf("0.EXIT");
gotoxy(30,18);
textcolor(9);
cprintf("ENTER YOUR CHOICE:");
scanf("%d",&iCh1);
if(iCh1==0)
{
/* To exit from the system */
gotoxy(30,28);
textcolor(4);
cprintf("SYSTEM SHUTTING DOWN");
sleep(3);
gotoxy(26,40);
printf("INFOSYS CAMPUS CONNECT PROGRAM");
gotoxy(8,42);
printf("HOSPITAL MANAGEMENT SYSTEM DONE BY MOHAMED BARI.I");
gotoxy(8,45);
printf("DATE : %s ",__DATE__);
gotoxy(55,45);
printf("TIME : %s ",__TIME__);
exit(0);
}
else{
/* Declarations of Variables */
FILE *fp,*ft;
char cAns,cChoice;
struct hospital
{
char acPhistory[50],acName[30],acDesiq[20],acStreet[30],acCity[24],acPhno[11],acDoj[11],acRoom[4],acP_id[4],acSex[2];
int iAge,iSal;
};
struct hospital e;
char icPid[4];
int iF=0,iC=0,iF1=0;
long int lRecsize;
fp=fopen("hp.dat","rb+");
if(fp==NULL)
{
fp=fopen("\hp.dat","wb+");
if(fp==NULL)
{
puts("\n\t\tCannot Open file");
exit();
}
}
lRecsize=sizeof(e);
while(1)
{
clrscr();
textcolor(4);
if(iCh1==1) {
gotoxy(30,8);
textcolor(4);
/* Sub menu for manipulation of patient and staff details */
cprintf("OUT-PATIENT MENU"); }
else if(iCh1==2) {
gotoxy(30,8);
textcolor(4);
cprintf("IN-PATIENT MENU"); }
else if(iCh1==3) {
gotoxy(30,8);
textcolor(4);
cprintf("STAFF MENU"); }
gotoxy(26,40);
textcolor(4);
cprintf("INFOSYS CAMPUS CONNECT PROGRAM");
gotoxy(32,44);
textcolor(19);
cprintf("KARUNYA UNIVERSITY");
gotoxy(16,42);
textcolor(19);
cprintf("HOSPITAL MANAGEMENT SYSTEM DONE BY MOHAMED BARI.I");
gotoxy(8,45);
textcolor(4);
cprintf("DATE : %s ",__DATE__);
gotoxy(55,45);
cprintf("TIME : %s ",__TIME__);
for(iInc=0;iInc<=30;iInc++)
{
gotoxy(20,iInc);
textcolor(7);
cprintf("-");
}
for(iInc=0;iInc<=80;iInc++)
{
gotoxy(iInc,30);
textcolor(7);
cprintf("|");
}
gotoxy(30,10);
textcolor(19);
cprintf("1.ADD ");
gotoxy(30,12);
cprintf("2.DISPLAY");
gotoxy(30,14);
cprintf("3.MODIFY");
gotoxy(30,16);
cprintf("4.DELETE");
gotoxy(30,18);
cprintf("0.EXIT");
gotoxy(30,20);
textcolor(4);
cprintf("SELECT YOUR OPTION: ");
fflush(stdin);
cChoice=getche();
clrscr();
gotoxy(25,8);
textcolor(5);
switch(cChoice)
{
case '1':
//To add a record
w:
printf("\n\n\n\t\tENTER ID: ");
scanf("%s",icPid);
rewind(fp);
//Checking for unique id
while(fread(&e,lRecsize,1,fp)==1)
{
if(strcmp(e.acP_id,icPid)==0)
{
iF=1;
printf("\n\t\tALREADY EXISTS");
goto w;
}}
if(iF==0||fread(&e,lRecsize,1,fp)==0)
{
fseek (fp,0,SEEK_END);
strcpy(e.acP_id,icPid);
a3:
printf("\n\t\tENTER NAME: ");
scanf("%s",e.acName);
if(strlen(e.acName)>30||strlen(e.acName)<3)
goto a3;
if(iCh1==3){
a4:
printf("\n\t\tENTER DESIGNATION: ");
scanf("%s",e.acDesiq);
if(strlen(e.acDesiq)>20||strlen(e.acDesiq)<3)
goto a4;
}
if(iCh1!=3){
printf("\n \t\tENTER CONSULTANT NAME: ");
scanf("%s",e.acDesiq); }
p:
printf("\n \t\tENTER SEX [M/F]: ");
scanf("%s",e.acSex);
if(strlen(e.acSex)>1)
goto p;
f:
printf("\n \t\tENTER AGE : ");
scanf("%d",&e.iAge);
if(iCh1==3){
if(e.iAge<20||e.iAge>65)
goto f; }
else
{ if(e.iAge<0||e.iAge>100)
goto f; }
a5:
printf("\n \t\tENTER STREET: ");
scanf("%s",e.acStreet);
if(strlen(e.acStreet)>30||strlen(e.acStreet)<5)
goto a5;
a6:
printf("\n \t\tENTER CITY: ");
scanf("%s",e.acCity);
if(strlen(e.acCity)>24||strlen(e.acCity)<3)
goto a6;
a:
printf("\n \t\tENTER CONTACT NUMBER: ");
scanf("%s",e.acPhno);
if(strlen(e.acPhno)>10||strlen(e.acPhno)<10)
goto a;
if(iCh1!=3){
a2:
printf("\n \t\tENTER PATIENT HISTORY: ");
scanf("%s",e.acPhistory);
if(strlen(e.acPhistory)>50)
goto a2;
}
if(iCh1==3) {
printf("\n \t\tENTER DATE OF JOIN(dd-mmm-yy): ");
scanf("%s",e.acDoj);
v:
printf("\n\t\tSALARY/DAY: ");
scanf("%d",&e.iSal);
if(e.iSal<100 || e.iSal>9000)
goto v;
}
if(iCh1==2)
{
printf("\n\t\tENTER ROOM NUMBER: ");
scanf("%s",e.acRoom);
printf("\n \t\tENTER DATE OF JOIN: ");
scanf("%s",e.acDoj);
}
fwrite(&e,lRecsize,1,fp);
/*Flushes a stream On success returns 0 , On error returns EOF */
fflush(stdin);
}
break;
case '2':
//Searching and displaying all the information by id
textcolor(7);
printf("\n\n\n\t\tENTER ID: ");
scanf("%s",icPid);
rewind(fp);
while(fread(&e,lRecsize,1,fp)!=0)
{
printf("hai");
if(strcmp(e.acP_id,icPid)==0)
{ printf("bye");
iC=1;
clrscr();
//Display according to Main menu
gotoxy(0,20);
//outpatient
if(iCh1==1){
printf("\n\n\n\t\tDETAILS OF OUTPATIENT:%s",strupr(e.acName));
printf("\n_____________________________________________________________________\n\n");
printf("\n\n NAME : %s\t ID : %s\t CONSULTANT NAME : %s\n\n SEX : %s\t AGE : %d \n\n STREET: %s\n\n CITY : %s\n\n PHONE : %s\n\n PATIENT HISTORY: %s",strupr(e.acName),strupr(e.acP_id),strupr(e.acDesiq),strupr(e.acSex),e.iAge,strupr(e.acStreet),strupr(e.acCity),strupr(e.acPhno),strupr(e.acPhistory));
printf("\n_____________________________________________________________________\n\n");
getch(); }
//Staff
else if(iCh1==3){
printf("\n\n\n\t\tDETAILS OF :%s %s",strupr(e.acDesiq),strupr(e.acName));
printf("\n_____________________________________________________________________\n\n");
printf("\n\n NAME : %s\t ID : %s \t DESIGNATION: %s\n\n SALARY : Rs %d(/day)\n\n AGE : %d \t SEX : %s \n\n DATE OF JOIN : %s\n\n STREET: %s\n\n CITY : %s\n\n PHONE : %s ",strupr(e.acName),strupr(e.acP_id),strupr(e.acDesiq),e.iSal,e.iAge,strupr(e.acSex),strupr(e.acDoj),strupr(e.acStreet),strupr(e.acCity),strupr(e.acPhno),strupr(e.acPhistory));
printf("\n_____________________________________________________________________\n\n");
getch(); }
//Inpatient
else if(iCh1==2){
printf("\n\n\n\t\tDETAILS OF INPATIENT:%s",strupr(e.acName));
printf("\n_____________________________________________________________________\n\n");
printf("\n\n NAME : %s\t ID : %s\t CONSULTANT NAME : %s\n\n AGE : %d\t SEX : %s \t STREET: %s\n\n CITY : %s\n\n PHONE : %s\n\n PATIENT HISTORY: %s\n\n ROOM NUMBER : %s\n\n DATE OF ADMISSION:%s ",strupr(e.acName),strupr(e.acP_id),strupr(e.acDesiq),e.iAge,strupr(e.acSex),strupr(e.acStreet),strupr(e.acCity),strupr(e.acPhno),strupr(e.acPhistory),strupr(e.acRoom),strupr(e.acDoj));
printf("\n_____________________________________________________________________\n\n");
getch(); }
}
}
if(iC==0)
{
printf("\n\t\tRECORD DOESN'T EXISTS..");
getch();
}iC=0;
break;
case '3':
//Searching and modifying Records by id
cAns='y';
while(cAns=='y')
{
printf("\n\n\n\t\tENTER ID: ");
scanf("%s",icPid);
rewind(fp);
while(fread(&e,lRecsize,1,fp)==1)
{
if(strcmp(e.acP_id,icPid)==0)
{
b:
printf("\n\n\t\tENTER NAME: %s : ",strupr(e.acName));
scanf("%s",e.acName);
if(strlen(e.acName)>20||strlen(e.acName)<3)
goto b;
b1:
printf(" \n\t\tENTER SEX : %s : ",strupr(e.acSex));
scanf("%s",e.acSex);
if(strlen(e.acSex)>1)
goto b1;
r:
printf(" \n\t\tENTER AGE: %d : " ,e.iAge);
scanf("%d",&e.iAge);
if(e.iAge<20||e.iAge>65)
goto r;
b3:
printf(" \n\t\tENTER STREET: %s : ",strupr(e.acStreet));
scanf("%s",e.acStreet);
if(strlen(e.acStreet)>30||strlen(e.acStreet)<5)
goto b3;
b4:
printf(" \n\t\tENTER CITY: %s :",strupr(e.acCity));
scanf("%s",e.acCity);
if(strlen(e.acCity)>24||strlen(e.acCity)<3)
goto b4;
a1:
printf(" \n\t\tENTER CONTACT NUMBER: %s :",strupr(e.acPhno));
scanf("%s",e.acPhno);
if(strlen(e.acPhno)>10||strlen(e.acPhno)<10)
goto a1;
if(iCh1==3){
b2:
printf("\n \t\tENTER DESIGNATION: %s : ",strupr(e.acDesiq));
scanf("%s",e.acDesiq);
if(strlen(e.acDesiq)>20||strlen(e.acDesiq)<3)
goto b2;
o:
printf("\n \t\tENTER SALARY: %d :",e.iSal);
scanf("%d",&e.iSal);
if(e.iSal<100||e.iSal>9000)
goto o;
}
if(iCh1!=3){
b5:
printf("\n \t\tENTER PATIENT HISTORY: %s : ",e.acPhistory);
scanf("%s",e.acPhistory);
if(strlen(e.acPhistory)>50)
goto b5;
}
fseek(fp,-lRecsize,SEEK_CUR); //Repositions the file pointer of a stream
fwrite(&e,lRecsize,1,fp);
printf("\n \t\tRECORD MODIFIED ");
break;
}else
printf("\n \t\tRECORD DOESNT EXISTS ");
}
printf("\n\n\n\t\tDO U WANT TO MODIFY ANY RECORD[y/n]");
/*Flushes a stream On success returns 0 , On error returns EOF */
fflush(stdin);
cAns=getche();
}
break;
case '4':
//Searching and deleting records by id
cAns='y';
while(cAns=='y')
{
printf("\n\n\t\tENTER ID TO DELETE RECORD : ");
scanf("%s",icPid);
ft=fopen("temp.dat","wb");
rewind(fp); //Repositions file pointer to stream's beginning
while(fread(&e,lRecsize,1,fp)!=0)
{
if(strcmp(e.acP_id,icPid)!=0) {
fwrite(&e,lRecsize,1,ft);
}
else {
iF1=1;
printf("\n\n\t\t RECORD DELETED SUCCESSFULLY");
}
}
if(iF1!=1){iF1=0;
printf("\n\n\t\t NO SUCH RECORD FOUND");}
fclose(fp);
fclose(ft);
remove("hp.dat");
rename("temp.dat","hp.dat");
fp=fopen("hp.dat","rb+");
printf("\n\n\t\tDO U WANT TO DELETE ANOTHER RECORD[y/n]");
fflush(stdin);
cAns=getche();
}
break;
case '0':
fclose(fp);
goto e;
}
}
}
}
/*******************************************************************
* End of HOSPITAL.c
********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -