Thursday, October 7, 2010

Sunil Rai Project Clinic

/*Coded and Compiled By: Sunil Rai (sunilplayer@gmail.com)*/
/*(c)Lateral Guys,2010*/
#include
#include
#include
void add();
void view();
void search();
void search1();
void search2();
void del();
void del1();
void del2();
void update();
void up1();
void up2();
void up3();
void up4();
void up5();
void copy();
class clinic
{
private:
char name[20],address[20];
char age[4];
char dis[20];
char tele[9];
public:
clinic()
{
strcpy(name,"\0");
strcpy(address,"\0");
strcpy(dis,"\0");
strcpy(age,"\0");
strcpy(tele,"\0");
}
void get()
{
strcpy(name,"\0");
strcpy(address,"\0");
strcpy(dis,"\0");
strcpy(age,"\0");
strcpy(tele,"\0");
cout<<"\n\n\nENTER PATIENT NAME :";
cin>>name;
cout<<"ENTER PATIENT AGE :";
cin>>age;
cout<<"ENTER PATIENT ADDRESS :";
cin>>address;
cout<<"ENTER PATIENT TELEPHONE NO. :";
cin>>tele;
cout<<"ENTER PATIENT DISEASE :";
cin>>dis;
}
void show()
{
cout<<"\nNAME OF THE PATIENT IS :"< cout<<"\nAGE OF PATIENT IS :"< cout<<"\nADDRESS OF PATIENT IS :"< cout<<"\nTELEPHONE NO. OF PATIENT IS :"< cout<<"\nDISEASE OF PATIENT IS :"< }
int check1(char home[])
{
if(strcmp(address,home)==0)
return 1;
else
return 0;
}
int check2(char ph[])
{
if(strcmp(ph,tele)==0)
return 1;
else
return 0;
}
void upname()
{
cout<<"\nENTER NEW NAME :";
cin>>name;
}
void upadd()
{
cout<<"\nENTER THE NEW ADDRESS :";
cin>>address;
}
void uptele()
{
cout<<"\nENTER THE NEW TELEPHONE NO. :";
cin>>tele;
}
void upadd_tele()
{
cout<<"\nENTER THE NEW ADDRESS :";
cin>>address;
cout<<"\nENTER THE NEW TELEPHONE NO. :";
cin>>tele;
}
};

void main()
{
clrscr();
char ans;
int ch;
do
{
clrscr();
cout<<"!!!!!!!!!!!!!!!!!!!!!! MAIN MENU !!!!!!!!!!!!!!!!!!";
cout<<"\n\t[1]. TO ADD NEW RECORD";
cout<<"\n\t[2]. TO VIEW ALL RECORDS";
cout<<"\n\t[3]. TO SEARCH A RECORD";
cout<<"\n\t[4]. TO DELETE A RECORD";
cout<<"\n\t[5]. TO UPDATE A RECORD";
cout<<"\n\t[6]. TO MAKE A NEW COPY OF RECORDS";
cout<<"\n\t[7]. TO QUIT";
cout<<"\n\nENTER YOUR CHOICE :";
cin>>ch;
switch(ch)
{
case 1:
add();
break;
case 2:
view();
break;
case 3:
search();
break;
case 4:
del();
break;
case 5:
update();
break;
case 6:
copy();
break;
case 7:
cout<<"\nARE YOU SURE YOU WANT TO QUIT (Y/N) :";
cin>>ans;
if(ans=='y' || ans=='Y')
ch=7;
else
ch=0;
break;
default:
cout<<"\n\tWRONG CHOICE" ;
cout<<"\n\tENTER THE CHOICE BETWEEN 1-7 ";
getch();
}
}
while(ch!=7);
cout<<"\n Press any Key to Continue!!!";
getch();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ADD~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

void add()
{
char ch;
clinic c;
fstream cfile;
do
{
clrscr();
cout<<"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
cout<<"\nENTER PATIENT'S DATA ";
cout<<"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
cfile.open("CLINI.DAT",ios::app);
c.get();
cfile.write((char*)&c,sizeof(c));
cfile.close();
cout<<"\n\n\nDO YOU WANT TO ADD MORE RECORDS (Y/N) :";
cin>>ch;
}while(ch=='y' || ch=='Y');
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~VIEW~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

void view()
{
clinic c;
fstream cfil;
int i=0;
cfil.open("CLINI.DAT",ios::in);
cfil.read((char*)&c,sizeof(c));
while(!cfil.eof())
{
clrscr();
cout<<"\n##############################";
cout<<"\n\tPATIENT NO. :"<<++i;
cout<<"\n##############################";
c.show();
getch();
cfil.read((char*)&c,sizeof(c));
}
cout<<"\n Press Key To Continue!!";
getch();
cfil.close();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SEARCH~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

void search()
{
clrscr();
char ans;
int ch;
do
{
clrscr();
cout<<"!!!!!!!!!!!!!!!!!!!!! SEARCH MENU !!!!!!!!!!!!!!!!!!!!";
cout<<"\n\t[1]. TO SEARCH BY ADDRESS";
cout<<"\n\t[2]. TO SEARCH BY TELEPHONE NO.";
cout<<"\n\t[3]. TO QUIT";
cout<<"\n\nENTER YOUR CHOICE :";
cin>>ch;
switch(ch)
{
case 1:
search1();
break;
case 2:
search2();
break;
case 3:
cout<<"\nARE YOU SURE YOU WANT TO QUIT (Y/N) :";
cin>>ans;
if(ans=='y' || ans=='Y')
ans=3;
else
ans=0;
break;
default:
cout<<"\n\tWRONG CHOICE" ;
cout<<"\n\tENTER THE CHOICE BETWEEN 1-3 ";
getch();
}
}while(ch!=3);
getch();
}

void search1()
{
char add[20];
strcpy(add,"\0");
clinic c;
fstream cfile;
cfile.open("CLINI.DAT",ios::in);
if(!cfile)
{
cout<<"\n\nTHERE IS NO FILE";
return;
}
cout<<"\nENTER THE ADDRESS :";
cin>>add;
cfile.read((char*)&c,sizeof(c));
int flag=0;
while(!cfile.eof())
{
if(c.check1(add)==1)
{
c.show();
flag=1;
}
cfile.read((char*)&c,sizeof(c));
}
if(flag==0)
{
cout<<"SORRY!";
cout<<"THERE IS NO RECORD";
}
cout<<"\n Press any Key to Continue!!!";
getch();
cfile.close();
}

void search2()
{
char telno[8];
clinic c;
fstream cfile;
cfile.open("CLINI.DAT",ios::in|ios::out|ios::app);
cout<<"\nENTER THE TELEPHONE NO. :";
cin>>telno;
cfile.seekg(0);
cfile.read((char*)&c,sizeof(c));
int flag=0;
while(!cfile.eof())
{
if(c.check2(telno)==1)
{
c.show();
flag=1;
}
cfile.read((char*)&c,sizeof(c));
}
if(flag==0)
{
cout<<"SORRY!";
cout<<"THERE IS NO RECORD";
}
cout<<"\n Press any Key to Continue!!!";
getch();
cfile.close();
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~DELETE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

void del()
{
int ch;
char ans;
do
{
clrscr();
cout<<"!!!!!!!!!!!!!!!!!! DELETE MENU !!!!!!!!!!!!!!!!!!!!!!!";
cout<<"\n\t[1]. TO ENTER THE ADDRESS";
cout<<"\n\t[2]. TO ENTER THE TELEPHONE NO.";
cout<<"\n\t[3]. TO QUIT";
cout<<"\n\nENTER YOUR CHOICE :";
cin>>ch;
switch(ch)
{
case 1:
del1();
break;
case 2:
del2();
break;
case 3:
cout<<"\nARE YOU SURE YOU WANT TO QUIT (Y/N) :";
cin>>ans;
if(ans=='y' || ans=='Y')
ch=3;
else
ch=0;
break;
default:
cout<<"\n\tWRONG CHOICE" ;
cout<<"\n\tENTER THE CHOICE BETWEEN 1-3 ";
getch();
}
}
while(ch!=3);
getch();
}

void del1()
{
clinic c;
char ans;
char add[20];
strcpy(add,"\0");
fstream cfile,nfile;
cfile.open("CLINI.DAT",ios::in);
nfile.open("CLI.DAT",ios::out);
cfile.read((char*)&c,sizeof(c));
cout<<"\nENTER THE ADDRESS :";
cin>>add;
while(!cfile.eof())
{
if(c.check1(add)!=1)
{
nfile.write((char*)&c,sizeof(c));
}
else
{
c.show();
cout<<"\nIS THIS THE RECORD YOU WANT TO DELETE (Y/N) :";
cin>>ans;
if(ans=='n' || ans=='N')
{
nfile.write((char*)&c,sizeof(c));
}
else
cout<<"\nONE RECORD DELETED";
}
cfile.read((char*)&c,sizeof(c));
}
nfile.close();
cfile.close();
cfile.open("CLINI.DAT",ios::out);
nfile.open("CLI.DAT",ios::in);
nfile.read((char*)&c,sizeof(c));
while(!nfile.eof())
{
cfile.write((char*)&c,sizeof(c));
nfile.read((char*)&c,sizeof(c));
}
getch();
nfile.close();
cfile.close();
}

void del2()
{
clinic c;
char ans;
char telno[8];
strcpy(telno,"\0");
fstream cfile,nfile;
cfile.open("CLINI.DAT",ios::in);
nfile.open("CLI.DAT",ios::out);
cfile.read((char*)&c,sizeof(c));
cout<<"\nENTER THE TELEPHONE NO. :";
cin>>telno;
while(!cfile.eof())
{
if(c.check2(telno)!=1)
{
nfile.write((char*)&c,sizeof(c));
}
else
{
c.show();
cout<<"\nIS THIS THE RECORD YOU WANT TO DELETE (Y/N) :";
cin>>ans;
if(ans=='n' || ans=='N')
{
nfile.write((char*)&c,sizeof(c));
}
else
cout<<"\nONE RECORD DELETED";
}
cfile.read((char*)&c,sizeof(c));
}
nfile.close();
cfile.close();
cfile.open("CLINI.DAT",ios::out);
nfile.open("CLI.DAT",ios::in);
nfile.read((char*)&c,sizeof(c));
while(!nfile.eof())
{
cfile.write((char*)&c,sizeof(c));
nfile.read((char*)&c,sizeof(c));
}
getch();
nfile.close();
cfile.close();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~UPDATE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

void update()
{
int ch;
char ans;
do
{
clrscr();
cout<<"!!!!!!!!!!!!!!!!!!! UPDATE MENU !!!!!!!!!!!!!!!!!!!!!";
cout<<"\n\t[1]. TO CHANGE NAME";
cout<<"\n\t[2]. TO CHANGE ADDRESS";
cout<<"\n\t[3]. TO CHANGE TELEPHONE NO.";
cout<<"\n\t[4]. TO CHANGE ADDRESS AND TELEPHONE NO.";
cout<<"\n\t[5]. TO QUIT";
cout<<"\n\nENTER YOUR CHOICE :";
cin>>ch;
switch(ch)
{
case 1:
up1();
break;
case 2:
up2();
break;
case 3:
up3();
break;
case 4:
up4();
break;
case 5:
cout<<"\nARE YOU SURE YOU WANT TO QUIT (Y/N) :";
cin>>ans;
if(ans=='y' || ans=='Y')
ch=5;
else
ch=0;
break;
default:
cout<<"\n\tWRONG CHOICE" ;
cout<<"\n\tENTER THE CHOICE BETWEEN 1-5 ";
getch();
}
}
while(ch!=5);
getch();
}


void up1()
{
clinic c;
fstream cfile,nfile;
char teleno[8],ans;
strcpy(teleno,"\0");
cfile.open("CLINI.DAT",ios::in|ios::out|ios::app);
nfile.open("NEW.DAT",ios::in|ios::out);
cout<<"\nENTER THE TELPHONE NO. OF THE PERSON :";
cin>>teleno;
cfile.read((char*)&c,sizeof(c));
while(!cfile.eof())
{
if(c.check2(teleno)==1)
{
c.show();
cout<<"\n\nIS THIS THE RECORD YOU WANT TO UPDATE (Y/N) :";
cin>>ans;
if(ans=='y' || ans=='Y')
{
c.upname();
nfile.write((char*)&c,sizeof(c));
c.show();
}
else
nfile.write((char*)&c,sizeof(c));
}
else
nfile.write((char*)&c,sizeof(c));
cfile.read((char*)&c,sizeof(c));
}
nfile.close();
cfile.close();
cfile.open("CLINI.DAT",ios::out);
nfile.open("NEW.DAT",ios::in);
nfile.read((char*)&c,sizeof(c));
while(!nfile.eof())
{
cfile.write((char*)&c,sizeof(c));
nfile.read((char*)&c,sizeof(c));
}
getch();
nfile.close();
cfile.close();
}


void up2()
{
clinic c;
fstream cfile,nfile;
char teleno[8],ans;
strcpy(teleno,"\0");
cfile.open("CLINI.DAT",ios::in|ios::out|ios::app);
nfile.open("NEW.DAT",ios::in|ios::out);
cout<<"\nENTER THE TELPHONE NO. OF THE PERSON :";
cin>>teleno;
cfile.read((char*)&c,sizeof(c));
while(!cfile.eof())
{
if(c.check2(teleno)==1)
{
c.show();
cout<<"\n\nIS THIS THE RECORD YOU WANT TO UPDATE (Y/N) :";
cin>>ans;
if(ans=='y' || ans=='Y')
{
c.upadd();
nfile.write((char*)&c,sizeof(c));
c.show();
}
else
nfile.write((char*)&c,sizeof(c));
}
else
nfile.write((char*)&c,sizeof(c));
cfile.read((char*)&c,sizeof(c));
}
nfile.close();
cfile.close();
cfile.open("CLINI.DAT",ios::out);
nfile.open("NEW.DAT",ios::in);
nfile.read((char*)&c,sizeof(c));
while(!nfile.eof())
{
cfile.write((char*)&c,sizeof(c));
nfile.read((char*)&c,sizeof(c));
}
getch();
nfile.close();
cfile.close();
}


void up3()
{
clinic c;
fstream cfile,nfile;
char teleno[8],ans;
strcpy(teleno,"\0");
cfile.open("CLINI.DAT",ios::in|ios::out|ios::app);
nfile.open("NEW.DAT",ios::in|ios::out);
cout<<"\nENTER THE TELPHONE NO. OF THE PERSON :";
cin>>teleno;
cfile.read((char*)&c,sizeof(c));
while(!cfile.eof())
{
if(c.check2(teleno)==1)
{
c.show();
cout<<"\n\nIS THIS THE RECORD YOU WANT TO UPDATE (Y/N) :";
cin>>ans;
if(ans=='y' || ans=='Y')
{
c.uptele();
nfile.write((char*)&c,sizeof(c));
c.show();
}
else
nfile.write((char*)&c,sizeof(c));
}
else
nfile.write((char*)&c,sizeof(c));
cfile.read((char*)&c,sizeof(c));
}
nfile.close();
cfile.close();
cfile.open("CLINI.DAT",ios::out);
nfile.open("NEW.DAT",ios::in);
nfile.read((char*)&c,sizeof(c));
while(!nfile.eof())
{
cfile.write((char*)&c,sizeof(c));
nfile.read((char*)&c,sizeof(c));
}
getch();
nfile.close();
cfile.close();
}


void up4()
{
clinic c;
fstream cfile,nfile;
char teleno[8],ans;
strcpy(teleno,"\0");
cfile.open("CLINI.DAT",ios::in|ios::out|ios::app);
nfile.open("NEW.DAT",ios::in|ios::out);
cout<<"\nENTER THE TELPHONE NO. OF THE PERSON :";
cin>>teleno;
cfile.read((char*)&c,sizeof(c));
while(!cfile.eof())
{
if(c.check2(teleno)==1)
{
c.show();
cout<<"\n\nIS THIS THE RECORD YOU WANT TO UPDATE (Y/N) :";
cin>>ans;
if(ans=='y' || ans=='Y')
{
c.upadd_tele();
nfile.write((char*)&c,sizeof(c));
c.show();
}
else
nfile.write((char*)&c,sizeof(c));
}
else
nfile.write((char*)&c,sizeof(c));
cfile.read((char*)&c,sizeof(c));
}
nfile.close();
cfile.close();
cfile.open("CLINI.DAT",ios::out);
nfile.open("NEW.DAT",ios::in);
nfile.read((char*)&c,sizeof(c));
while(!nfile.eof())
{
cfile.write((char*)&c,sizeof(c));
nfile.read((char*)&c,sizeof(c));
}
getch();
nfile.close();
cfile.close();
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~COPY~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

void copy()
{
int i=0;
char file[12];
strcpy(file,"\0");
fstream cfile,efile;
clinic c;
char ch;
cout<<"\nENTER THE NAME OF THE NEW FILE :";
cin>>file;
cfile.open("CLINI.DAT",ios::in|ios::out|ios::app);
efile.open(file,ios::in|ios::out|ios::app);
cfile.read((char*)&c,sizeof(c));
while(!cfile.eof())
{
efile.write((char*)&c,sizeof(c));
cfile.read((char*)&c,sizeof(c));
}
cout<<"\n\n\nDO YOU WANT TO VIEW THE NEW COPIED FILE (Y/N) :";
cin>>ch;
if(ch=='y' || ch=='Y')
{
efile.seekg(0);
efile.read((char*)&c,sizeof(c));
while(!efile.eof())
{
clrscr();
cout<<"\n##############################";
cout<<"\n\tPATIENT NO. :"<<++i;
cout<<"\n##############################";
c.show();
efile.read((char*)&c,sizeof(c));
getch();
}
}
getch();
efile.close();
cfile.close();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

/*Coded and Compiled By: Sunil Rai (sunilplayer@gmail.com)*/
/*(c)Lateral Guys,2010*/

No comments: