C++ language. I need to write the getEmp function using a pointer or reference parameter to return the structure

#include <iostream>


using namespace std;

//Create a structure to hold information about an Employee.
//Create fields to hold first and last name, hire date, a code indicating whether the employee works ('w')
//or is a supervisor ('s'), and a field for yearly salary.

struct Employee{
string firstName, lastName;
string hireDate;
int employeeCode;
int year_Salary;
} ;
// Write a function called "getEmp" which prompts for and reads in the information for
// a single Employee structure and then returns the structure.

Employee getEmp();

// Write a function called "putEmp" which prints out the information from a single Employee structure
// (which is passed to the function) along with a label to indicate the field being printed (ex: First Name: David).
// Also print out the meaning of the employment code, not the code itself.

void putEmp(Employee e);


int main(){
Employee e;
e = getEmp();
cout << endl;
putEmp(e);
return 0;
}

Employee getEmp(){
Employee e;
cout << " Enter first name: " ;
getline(cin,e.firstName);
cout << " Enter last name: " ;
getline(cin, e.lastName);
cout << " Enter hire date:" ;
getline(cin, e.hireDate);
cout << " Enter employee code: ";
cin >> e.employeeCode;
cin.ignore();
cout << " Enter yearly salary: ";
cin >> e.year_Salary;
cin.ignore();
return(e);
}

void putEmp(Employee e){
cout << "First name : " << e.firstName << endl;
cout << "Last name : " << e.lastName << endl;
cout << "Hire Date : " << e.hireDate << endl;
if (e.employeeCode == 'W123')
cout << " Employee Code : Worker " << endl;

else if (e.employeeCode == 'W456')
cout << "Employee Code : Supervisor" << endl;

cout << "Yearly Salary: " << e.year_Salary << endl;
}
Last edited on
Topic archived. No new replies allowed.