Practical 29
#include <iostream>
#include<fstream>
#include<stdlib.h>
using namespace std;
class Hospital
{
string name,disease;
string a[10];
int c;
long int dateadd,discharge;
public:
Hospital()
{
c=0;
string line;
fstream f1;
f1.open("hosp.txt",ios::in|ios::out|ios::app);
while(getline(f1,line))
{
c++;
}
}
void adddata()
{
fstream f1;
f1.open("hosp.txt",ios::in|ios::out|ios::app);
cout<<"\nEnter Name of Patient:";
cin>>name;
cout<<"\nEnter Date of admission:";
cin>>dateadd;
cout<<"\nEnter Disease:";
cin>>disease;
cout<<"\nEnter date of discharge:";
cin>>discharge;
if(c==0)
{
f1<<endl;
}
f1<<name<<" "<<dateadd<<" "<<disease<<" "<<discharge<<endl;
f1.close();
}
void patients()
{
fstream f1;
f1.open("hosp.txt",ios::in|ios::out|ios::app);
f1.clear();
f1.seekg(0);
string l,l1;
while(getline(f1,l1,' '))
{
f1>>l;
cout<<l1;
}
f1.close();
}
void searchp()
{
fstream f1;
f1.open("hosp.txt",ios::in|ios::out|ios::app);
f1.clear();
f1.seekg(0);
string p,p1;
int i=0;
while(getline(f1,p1,'\n'))
{
f1>>p;
a[i]=p;
f1>>p1;
i++;
}
string s,line;
cout<<"\nEnter the name you want to search";
cin>>s;
for(i=0;i<c-1;i++)
{
if(a[i]==s)
{
cout<<"\n\nFound "<<s<<endl;
break;
}
if(i==c-2)
{
cout<<"\nNot Found";
}
}
f1.close();
}
};
int main()
{
Hospital h;
int ch;
while(1)
{
cout<<"\n1.Enter Information\n2.Display Patients\n3.Search Patient\n5.exit";
cin>>ch;
switch(ch)
{
case 1:
h.adddata();
break;
case 2:
h.patients();
break;
case 3:
h.searchp();
break;
case 5:
exit(0);
break;
default:
cout<<"\nEnter proper choice\n";
}
}
return 0;
}
#include<fstream>
#include<stdlib.h>
using namespace std;
class Hospital
{
string name,disease;
string a[10];
int c;
long int dateadd,discharge;
public:
Hospital()
{
c=0;
string line;
fstream f1;
f1.open("hosp.txt",ios::in|ios::out|ios::app);
while(getline(f1,line))
{
c++;
}
}
void adddata()
{
fstream f1;
f1.open("hosp.txt",ios::in|ios::out|ios::app);
cout<<"\nEnter Name of Patient:";
cin>>name;
cout<<"\nEnter Date of admission:";
cin>>dateadd;
cout<<"\nEnter Disease:";
cin>>disease;
cout<<"\nEnter date of discharge:";
cin>>discharge;
if(c==0)
{
f1<<endl;
}
f1<<name<<" "<<dateadd<<" "<<disease<<" "<<discharge<<endl;
f1.close();
}
void patients()
{
fstream f1;
f1.open("hosp.txt",ios::in|ios::out|ios::app);
f1.clear();
f1.seekg(0);
string l,l1;
while(getline(f1,l1,' '))
{
f1>>l;
cout<<l1;
}
f1.close();
}
void searchp()
{
fstream f1;
f1.open("hosp.txt",ios::in|ios::out|ios::app);
f1.clear();
f1.seekg(0);
string p,p1;
int i=0;
while(getline(f1,p1,'\n'))
{
f1>>p;
a[i]=p;
f1>>p1;
i++;
}
string s,line;
cout<<"\nEnter the name you want to search";
cin>>s;
for(i=0;i<c-1;i++)
{
if(a[i]==s)
{
cout<<"\n\nFound "<<s<<endl;
break;
}
if(i==c-2)
{
cout<<"\nNot Found";
}
}
f1.close();
}
};
int main()
{
Hospital h;
int ch;
while(1)
{
cout<<"\n1.Enter Information\n2.Display Patients\n3.Search Patient\n5.exit";
cin>>ch;
switch(ch)
{
case 1:
h.adddata();
break;
case 2:
h.patients();
break;
case 3:
h.searchp();
break;
case 5:
exit(0);
break;
default:
cout<<"\nEnter proper choice\n";
}
}
return 0;
}
No comments:
Post a Comment