Complete the following class, then, separate the header file from the source fil
ID: 3546011 • Letter: C
Question
Complete the following class, then, separate the header file from the source file
#include <iostream>
using namespace std;
class Employee {
string name;
int* ID ;
public:
Employee(string n,int i) {
name =n;
ID= new int (i);
}
Employee (Employee& ob) {
name = ob.name ;
ID = new int;
*ID = *(ob.ID) ;
}
void print (){
cout<<"=======Employee Information======= ";
cout<<"Name: "<<name<<endl ;
cout<<"ID: "<<*ID<<endl ;
cout<<"================================== ";
}
};
class Company{
string CompanyName ;
string workType ;
Employee e ;
public:
// initialize all data
// print the information
};
int main () {
Employee employee1 ("Ahmed" , 42848) ;
Company c1 ("AOI","Projects managment",employee1) ;
c1.print();
system ("pause") ;
return 0 ; }
Explanation / Answer
#include <iostream>
using namespace std;
class Employee {
string name;
int* ID ;
public:
Employee(string n,int i) {
name =n;
ID= new int (i);
}
Employee (Employee& ob) {
name = ob.name ;
ID = new int;
*ID = *(ob.ID) ;
}
void print (){
cout<<"=======Employee Information======= ";
cout<<"Name: "<<name<<endl ;
cout<<"ID: "<<*ID<<endl ;
cout<<"================================== ";
}
};
class Company{
string CompanyName ;
string workType ;
public:
Company(string a,string b,Employee* c)
{CompanyName=a;
workType=b;
c->print();
print(a,b);
}
void print(string a,string b)
{ cout<<"=======Company Information======= ";
cout<<"company Name: "<<a<<endl ;
cout<<"Work type : "<<b<<endl ;
cout<<"================================== ";
}
};
int main () {
Employee employee1 ("Ahmed" , 42848) ;
Company c1 ("AOI","Projects managment",&employee1) ;
return 0 ; }