#include<iostream>
#include<string>
using namespace std;
class Employee
{
private:
int cpr;
string name;
float salary;
string kids[5];
static int count;
int numberkids;
string *kids;
public:
Employee ();
Employee (int c, string n, float s, string ki[]);
void print();
void setSalary(float);
void setData (int c, string n, float s, int numberkids, string *kid);
};
int Employee::count=0; // assign a value to variable in the class ...
Employee::Employee()
{
cpr = 111111;
name= "ALI" ;
salary = 1000.0;
for (int i=0; i<5; i++)
{ kids[i] = "xxxxxx"; }
count++;
}
Employee:: Employee (int c, string n, float s, string kid[])
{
cpr = c;
name= n;
salary = s;
for (int i=0; i<5; i++)
{ kids[i] = kid[i]; }
count++;
}
void Employee::print()
{
cout<<"*********************************"<<endl<<endl;
cout<<"cpr is :"<<cpr<<endl;
cout<<"name is:"<<name<<endl;
cout<<"salary is:"<<salary<<endl;
for (int i=0; i<5 ; i++)
{
cout<<"kid "<<i+1<<"name is :"<<kids[i]<<endl;
}
cout<<"number of employees so far:"<<count;
cout<<endl<<"*********************************"<<endl;
}
void Employee::setSalary(float sal)
{
salary = sal;
}
void Employee::setData(int c, string n, float s, int numberkids, string *kid)
{
cpr = c;
name= n;
salary = s;
kids = new string[numberkids]; // dynamic array
for (int i=0; i<numberkids; i++) //deep copy
{
kids[i]=kid[i];
}
}
int main()
{
int cpr;
string name;
float salary;
string children[5];
int nberKids;
string *children;
Employee staff[5];
cout<<"CPR>>";
cin>>cpr;
cout<<"NAME>>";
cin>>name;
cout<<"SALARY>>";
cin>>salary;
cout<<"NEMBER OF KIDS>>";
cin>>nberKids;
for (int i=0;i<nberKids;i++)
{
cout<<"KID"<<i+1<<" NAME>>";
cin>>children[i];
}
for(int i=0;i<5;i++)
staff[i].setData( cpr, name, salary, nberKids, *children);
for(int i=0;i<5;i++)
staff[i].print();
return 0;
}