1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
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
{
.......................}
class researcher:public employee
{
......................}
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");
}
| |