#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
char ch, c, cs;
int id;
class docnur //class containing staff's info
{
char name[40];
int age;
char gender[10];
unsigned long long phoneno;
int exp;
char dept[40];
float salary;
char nd;
public:
int dnid;
void dadd();
};
docnur dn;
void docnur::dadd() //funtion to add a staff record
{
cout<<"\nEnter staff ID:"; cin>>dnid;
cin.get(ch);
cout<<"\nEnter name of the staff member:"; cin.getline(name, 40);
cout<<"\nEnter age of the staff member:"; cin>>age;
cin.get(ch);
cout<<"\nGender of staff member:"; cin.getline(gender, 10);
cout<<"\nEnter phone number:"; cin>>phoneno;
cout<<"\nEnter experience:"; cin>>exp;
cin.get(ch);
cout<<"\nEnter department:"; cin.getline(dept, 40);
cout<<"\nEnter salary:"; cin>>salary;
label:
cout<<"\nEnter job: \n\t1. Press 'n' for nusrse. \n\t2. Press 'd' for doctor.";
cin>>ch;
switch (ch)
{
case 'n': nd='n';
break;
case 'd': nd='d';
break;
default:cout<<"\nWrong Choice! \nEnter Again!!";
goto label;
break;
}
ofstream fout;
fout.open("Staff.txt", ios::app);
fout.write((char *)&dn, sizeof(dn));
fout.close();
cout<<"\nRecord added to file.";
cout<<"\nWant to add more staff records?";
cin>>c;
cin.get(ch);
if (c=='y'||c=='Y')
dn.dadd();
}
void docnur::dnview()
{
char f='f';
cout<<"\n\nEnter ID of the staff member to be viewed:"; cin>>id;
ifstream fin;
fin.open("Staff.txt", ios::in);
if (fin.fail())
{
cout<<"\n";
for (int x=0;x<40;x++)
cout<<"-";
cout<<"\n";
for (int x=0;x<10;x++)
cout<<"-";
cout<<"File Empty";
for (int x=0;x<10;x++)
cout<<"-";
return;
}
while (!fin.eof())
{
fin.read((char *)&dn, sizeof(dn));
if (id==dnid)
{
f='t';
cout<<"\nStaff member ID:"<<dnid;
cout<<"\nName: ";
if ('d'==nd) cout<<"Dr. "<<name;
if ('n'==nd) cout<<"Nurse "<<name;
cout<<"\nAge:"<<age;
cout<<"\nGender:"<<gender;
cout<<"\nPhone number:"<<phoneno;
cout<<"\nExperience:"<<exp;
cout<<"\nSalary per month:"<<salary;
cout<<"\nDepartment in which admitted:"<<dept;
fin.close();
}
if (f=='f')
{
cout<<"\n";
for (int A=0; A<30; A++)
cout<<"-";
cout<<"ID not found!!";
for (int A=0; A<30; A++)
cout<<"-";
}
}