Problem: It is instructed that take the value from user in setvalue function then what is the use of overloaded constructor in this program?
You are required to implement Employee Management System. There will be an employee class having following attributes: Name(String), Father_Name(String), Emp_id(int), dob(date), bps(1-22), job_Type(Private, public or autonomous) It should have two constructors i.e., default constructor and an overloaded constructor. The attributes in the constructors must be initialized through initializer list. The Employee class should be having following functions i.e., setRecord and showRecord. In the setEmployeeRecord, the data input should be taken from the user while showRecord should print the employee details.
What I have tried:
I tried but it give following error.
1. type 'int' unexpected
2. 'emp_id': undeclared identifier
3. 'bps': undeclared identifier
#include<iostream>
#include<string>
using namespace std;
class Employee
{
string name;
string father_name;
int emp_id;
string date;
int bps;
string job_Type;
public:
Employee();
Employee(string nam, string f_name, int id, string dt, int b, string job) :name(nam), father_name(f_name), emp_id(id), bps(b), job_Type(job) {}
void setRecord(string nam, string f_name, int id, string dt, int b, string job);
void showRecord();
};
Employee::Employee() { }
void Employee::setRecord(string nam, string f_name, int id, string dt, int b, string job)
{
cout << "Name of Employee: ";
cin >> nam;
cin.ignore();
cout << "Father Name: ";
cin >> f_name;
cout << "Employee ID: ";
cin >> id;
cout << "Date of Birth: ";
cin >> dt;
cout << "Basic Pay Scale: ";
cin >> b;
cout << "Job Type: ";
cin.ignore();
cin >> job;
}
void Employee::showRecord()
{
cout << "Name: " << name << endl;
cout << "Father Name: " << father_name << endl;
cout << "Employee ID: " << emp_id << endl;
cout << "Date of Birth: " << date << endl;
cout << "Basic Pay Scale: " << bps << endl;
cout << "Job Type: " << job_Type << endl;
}
int main()
{
string nam, f_name, job, dt,
int id, b;
Employee A;
A.setRecord(nam, f_name, id, dt, b, job);
system("pause");
return 0;
}