You are on page 1of 13

#include<fstream.

h>
#include<process.h>
#include<iomanip.h>
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class hospital
{
private:
int patientid;
char patientname[30];
char address[40];
char dob[15];
char disease[15];
char doctor[25];
float amount;
public:
int retpatientid()
{
return patientid;
}
void getpatient()
{
gotoxy(20,5);
cout<<"Enter Patient Id:";

gotoxy(50,5);
cin>>patientid;

gotoxy(20,7);
cout<<"Enter Patient Name:";
gotoxy(50,7);
gets(patientname);

gotoxy(20,9);
cout<<"Enter Address:";
gotoxy(50,9);
gets(address);

gotoxy(20,11);
cout<<"Enter Date of Birth:";
gotoxy(50,11);
gets(dob);

gotoxy(20,13);
cout<<"Enter Disease:";
gotoxy(50,13);
gets(disease);

gotoxy(20,15);
cout<<"Enter name of doctor:";

gotoxy(50,15);
gets(doctor);

gotoxy(20,17);
cout<<"Enter amount:";
gotoxy(50,17);
cin>>amount;
}
void showpatient()
{

gotoxy(20,5);
cout<<"Patient Id:";
gotoxy(50,5);
cout<<patientid;

gotoxy(20,7);
cout<<"Patient Name:";
gotoxy(50,7);
cout<<patientname;

gotoxy(20,9);
cout<<"Address:";
gotoxy(50,9);
cout<<address;

gotoxy(20,11);
cout<<"Date of Birth:";
gotoxy(50,11);
cout<<dob;

gotoxy(20,13);
cout<<"Disease:";
gotoxy(50,13);
cout<<disease;

gotoxy(20,15);
cout<<"Name of doctor:";
gotoxy(50,15);
cout<<doctor;

gotoxy(20,17);
cout<<"Amount:";
gotoxy(50,17);
cout<<amount;
}
void viewpatients()
{
cout<<endl<<patientid<<setw(20)<<patientname<<setw(20)<<address<<setw(15)<<dob<<setw(20)<<di
sease;
}

};

void main()
{
clrscr();
fstream f,f1; //
hospital obj; //
int choice,id;
char ch;
textbackground(BLUE);
textcolor(WHITE);
clrscr();
gotoxy(25,5);
cout<<"Software for Hospital Management System";
gotoxy(25,6);
cout<<"=======================================";

gotoxy(38,9);
cout<<"MENU OPTIONS";
gotoxy(38,10);
cout<<"*************";
textcolor(YELLOW);
gotoxy(35,12);
cprintf("1. Add New Record");
gotoxy(35,14);

cprintf("2. Modify Record");


gotoxy(35,16);
cprintf("3. Delete Record");
gotoxy(35,18);
cprintf("4. Search Record");
gotoxy(35,20);
cprintf("5. List Records");
gotoxy(35,22);
cprintf("6. Exit");

textcolor(BLINK);
gotoxy(30,35);
cprintf("DEVELOPED BY : ER.RAHUL GUPTA ");
textcolor(WHITE);
gotoxy(38,23);

gotoxy(35,25);
cout<<"Enter your choice:";

gotoxy(55,25); //
cin>>choice; //
switch(choice)
{
case 1:
f.open("hospital.dat",ios::app|ios::binary);

clrscr();
gotoxy(30,1);
cout<<"ADD A PATIENT RECORD";
gotoxy(30,2);
cout<<"=====================";

obj.getpatient();
f.write((char *)&obj,sizeof(obj));
f.close();
gotoxy(30,20);
cout<<"RECORD SAVED...!";
getch();
break;
case 2:
f.open("hospital.dat",ios::in|ios::binary);
f1.open("temp.dat",ios::out|ios::binary);
clrscr();
gotoxy(10,15);
cout<<"Enter Patient id of patient whose record is to be modified=";
cin>>id;
clrscr();
gotoxy(30,1);
cout<<"INFORMATION OF PATIENT";
gotoxy(30,2);
cout<<"======================";

while(f.read((char *)&obj,sizeof(obj)))
{
if(id==obj.retpatientid())
{
obj.showpatient();
gotoxy(30,20);
cout<<"Do you want to modify this record(Y/N)=";
cin>>ch;
if(ch=='y'||ch=='Y')
{
clrscr();
gotoxy(30,1);
cout<<"NEW INFORMATION OF PATIENT";
gotoxy(30,2);
cout<<"================";
obj.getpatient();
f1.write((char *)&obj,sizeof(obj));
gotoxy(30,20);
cout<<"RECORD MODIFIED...!";
getch();
}
else
{
f1.write((char *)&obj,sizeof(obj));
}

}
else
{
f1.write((char *)&obj,sizeof(obj));
}
}
f.close();
f1.close();
remove("hospital.dat");
rename("temp.dat","hospital.dat");
break;

case 3:
f.open("hospital.dat",ios::in|ios::binary);
f1.open("temp.dat",ios::out|ios::binary);
clrscr();
gotoxy(10,35);
cout<<"Enter Patient id of patient whose record is to be deleted=";
cin>>id;
clrscr();
gotoxy(30,1);
cout<<"INFORMATION OF PATIENT";
gotoxy(30,2);
cout<<"================";
while(f.read((char *)&obj,sizeof(obj)))

{
if(id==obj.retpatientid())
{
obj.showpatient();
gotoxy(30,29);
cout<<"Do you want to delete this record(Y/N)=";
cin>>ch;
if(ch=='y'||ch=='Y')
{
clrscr();
gotoxy(30,10);
cout<<"RECORD DELETED...!";
getch();
}
else
{
f1.write((char *)&obj,sizeof(obj));
}
}
else
{
f1.write((char *)&obj,sizeof(obj));
}
}
f.close();

f1.close();
remove("hospital.dat");
rename("temp.dat","hospital.dat");
break;
case 4:
f.open("hospital.dat",ios::in|ios::binary);
clrscr();
gotoxy(10,15);
cout<<"Enter Patient id of patient whose record is required=";
cin>>id;
clrscr();
gotoxy(30,1);
cout<<"INFORMATION OF PATIENT";
gotoxy(30,2);
cout<<"================";
while(f.read((char *)&obj,sizeof(obj)))
{
if(id==obj.retpatientid())
obj.showpatient();
}
f.close();
gotoxy(30,20);
cout<<"PRESS ANY KEY...!";
getch();

break;
case 5:
f.open("hospital.dat",ios::in|ios::binary);
clrscr();
gotoxy(30,1);
cout<<"LIST OF PATIENTS";
gotoxy(30,2);
cout<<"================";

cout<<endl<<"Patient id"<<setw(18)<<"Patientname"<<setw(15)<<"Address"<<setw(20)<<"Date of
Birth"<<setw(16)<<"Disease";
cout<<endl<<"=========================================================================
=======";
while(f.read((char *)&obj,sizeof(obj)))
{
obj.viewpatients();
}
f.close();
gotoxy(30,20);
cout<<"PRESS ANY KEY...!";
getch();

break;
case 6:
exit(0);
}

main();
}