Complete the following class, then, separate the header file from the source fil
ID: 3546012 • 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
//employee.h 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<<"================================== "; } }; //company.H file #include <iostream> #include "employee.h" using namespace std; class Company{ string CompanyName ; string workType ; Employee e ; public: // initialize all data Company(string n,string wt, Employee emp) { CompanyName = n; workType = wt; e = emp; } Company (Company& ob) { CompanyName = ob.CompanyName ; workType = ob.workType; e = ob.e; } // print the information void print (){ cout<<"=======Company Information======= "; cout<<"Company Name: "<<CompanyName<<endl ; cout<<"Work Type: "<<workType<<endl ; e.print();//print the employee information using print function of employee class cout<<"================================== "; } }; //MAIN file #include<iostream> #include "company.h" #include "employee.h" int main () { Employee employee1 ("Ahmed" , 42848) ; Company c1 ("AOI","Projects managment",employee1) ; c1.print(); system ("pause") ; return 0 ; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.