the program asks user to add employee and save using of stream, and delete :
Delete an Employee. This should ask for the last name of the employee (your program does not
need to handle duplicate last names). You then need to write code to search the database for the
given employee and delete him/her from the database (i.e., the std::vector). If the user
enters in a name that does not exist in the database, report that information to the user and return
to the main menu.”"
inheritance employee database
</code>#include <vector>
#include <iostream>
#include <string>
#include<fstream>
#include<limits.h>
using namespace std;
class employee
{
public:
employee(string name,string last,int sal)
{mName =name;mLastName =last; mSalary= sal;}
virtual void printStats()
{
cout<<"Name ="<<mName<<endl<<"LastName ="<<mLastName<<endl<<"Salary ="<<mSalary<<endl;
}
virtual void save(ofstream& out)
{
out<<"Name ="<<mName<<endl;
out<<"Last Name ="<<mLastName<<endl;
out<<"Salary ="<<mSalary<<endl;
}
protected:
string mName;
string mLastName;
int mSalary;
};
class manager :public employee
{
public:
manager(string name,string last,int sal,int meet,int vac)
:employee(name,last,sal)
{mMeet=meet; mVac =vac;}
void printStats()
{
employee::printStats();
cout<<"Meeting ="<<mMeet<<endl<<"Vacation ="<<mVac<<endl;
}
void save(ofstream& out)
{
employee::save(out);
out<<"MANAGER:";
out<<"Meeting ="<<mMeet<<endl;
out<<"Vacation ="<<mVac<<endl;
out<<endl<<endl;
}
protected:
int mMeet;
int mVac;
};
class engineer:public employee
{
public:
engineer(string name,string last,int sal,int numC,int exp,string trade)
:employee(name,last,sal)
{mNumC=numC; mExp =exp; mTrade =trade;}
void printStats()
{
employee::printStats();
cout<<"C++ members ="<<mNumC<<endl<<"Experience ="<<mExp<<endl<<"Trade ="<<mTrade<<endl;
}
void save(ofstream& out)
{
employee::save(out);
out<<"ENGINEER:";
out<<"Members with c++"<<mNumC<<endl;
out<<"Experiance"<<mExp<<endl;
out<<"Trade ="<<mTrade<<endl;
out<<endl<<endl;
}
protected:
int mNumC;
int mExp;
string mTrade;
};
class researcher:public employee
{
public:
researcher( string name,string last,int sal,string school,string topic)
:employee(name,last,sal)
{mSchool =school; mTopic =topic;}
void printStats()
{
employee::printStats();
cout<<"School ="<<mSchool<<endl<<"Topic ="<<mTopic<<endl;
}
void save(ofstream& out)
{
employee::save(out);
out<<"RESEARCHER:";
out<<"School ="<<mSchool<<endl;
out<<"Topic ="<<mTopic<<endl;
out<<endl<<endl;
}
protected:
string mSchool;
string mTopic;
};
int main()
{
vector<employee*> database;
int count =1;
ofstream out("~Spam~");
employee* emp[50];
string garbage;
bool done =false;
int input=0;
int select1 =0;
int select2 =0;
int j=0;
string first; string last; int sal; int exp; int num; string trade1;string school;string topic;
int meet; int vac;
while(!done)
{
cout<<"Database size="<<database.size()<<endl;
cout<<"Databse contains:" ;
if(database.size()==0)
{
cout<<"Null"<<endl;
cout<<endl<<endl;
}
else
{
for(int i=0;i<database.size();i++)
{
emp[i]->printStats();
cout<<endl<<endl;
}
}
cout<<"1.Add Employee 2.Remove Employee 3.Quit!";
cin>>select1;
switch(select1)
{
case 1:
start: cout<<"1.Engineer 2.Manager 3.Researcher";
cin>>select2;
switch(select2)
{
case 1:
getline(cin,garbage);
cout<<"Enter Name :"; getline(cin,first);
cout<<"Enter last name: "; getline(cin,last);
cout<<"Enter trade: ";
getline(cin,trade1);
cout<<"Enter salary:"; cin>>sal;
cout<<"Enter experience:"; cin>>exp;
cout<<"Enter number of members with c++:"; cin>>num;
emp[j] = new engineer(first,last,sal,num,exp,trade1);
database.push_back( emp[j]);
emp[j]->save(out);
j++;
break;
case 2:
getline(cin,garbage);
cout<<"Enter Name :"; getline(cin,first);
cout<<endl;
cout<<"Enter last name: "; getline(cin,last);
cout<<endl;
cout<<"Enter salary:"; cin>>sal;
cout<<endl;
cout<<"Enter Meeting:"; cin>>meet;
cout<<endl;
cout<<"Enter Vacation"; cin>>vac;
cout<<endl;
emp[j]=new manager(first,last,sal,meet,vac);
database.push_back( emp[j]);
emp[j]->save(out);
j++;
break;
case 3:
getline(cin,garbage);
cout<<"Enter Name :"; getline(cin,first);
cout<<endl;
cout<<"Enter last name: "; getline(cin,last);
cout<<endl;
cout<<"Enter salary:"; cin>>sal;
cout<<endl;
cout<<"Enter School:"; cin>>school;
cout<<endl;
cout<<"Enter Phd Topic:"; cin>>topic;
cout<<endl;
emp[j] =new researcher(first,last,sal,school,topic);
database.push_back(emp[j]);
emp[j]->save(out);
j++;
break;
default:
cout<<"Wrong input"<<endl;
goto start;
break;
}
break;
case 2:
cout<<"Enter index of employee"; cin>>input;
database.erase(database.begin()+input);
break;
default:
done =true;
break;
}
}
for(int k =0;k<database.size();k++)
{
delete emp[k];
}
system("pause");
}
<code>
</code>cout<<"Enter last name"<<endl;
getline(cin,LastName);
for(int i=0;i<database.size();i++)
{
if(LastName ==emp[i]->LastName()
database.erase(database.begin()+i);
else
cout<<"Miss Match..Testing..."<<endl;
}...<code>