Create a C++ class called Employee which will implement the Employee constructor
ID: 3670027 • Letter: C
Question
Create a C++ class called Employee which will implement the Employee constructor. Remember that once the Name of the Employee is entered and the Address of the Employee is entered, once you add an SSN you are ready to create an employee.
I have all 3 .h files correct, however, there is special criteria for the .cpp file. I am unsure how to add this to my code. My current .cpp works without errors, I simply need to include these special instructions and I am unsure how to do this. Please help - Thank you so much!
Employee (Employee.cpp) class will have:
In the void main() function you would declare:
a Name n;
an Address A;
and an Employee e;
and print e using the printEmployee().
Also you need to declare:
A Name n1: George Victor Meghabghab
an Address a1: your own address
string ssn1: 987-65-4321
An employee e1 which has a name n1, and address A1, and ssn1.
Print e1 using printEmployee()
My .cpp file:
#include<iostream>
#include<iomanip>
#include<string>
#include "Name.h"
#include "Address.h"
#include "Employee.h"
using namespace std;
void main()
{
Name n;
Address A;
Employee e;
cout << "Name: " << endl;
n.prtName(); // Displays name from class Name
cout << "Address: " << endl;
A.prtAddress(); // Displays address from class Address
cout << "Employee: " << endl;
e.prtEmployee(); // Displays name, address, and SSN from class Employee
cin.get();
}
Explanation / Answer
Hi, you have to add prtName in Name calss, prtAddress in Address class and prtEmployee in Employee class. So, you can define like
In Name class
Name::void printName(){
cout<<"Name: "<<name;
}
In Address Class
Address::void printAddress(){
cout<<"Address: "<<address<<endl;
}
In Employee Class
First you include Name.h and Address.h in Employee.h file
Lets assume Employee has Name n, Address a, string ssn -- members, then
Employee::void printEmployee(){
n.printName();
a.printAddress();
cout<<"SSN: "<<ssn<<endl;
}