Answers for "employee class example"

0

employee class example

#include <iostream>
#include <string>
using namespace std;


class Employee {
    private:
        string firstName;
        string lastName;
        string pid;
        string department;
        double salary;
    public:
        Employee() {}
        Employee(string f, string l, string p, string d, double s) {
            firstName = f;
            lastName = l;
            pid = p;
            department = d;
            salary = s;
        }
        void setFirstName(string f) {
            firstName = f;
        }
        string getFirstName() {
            return firstName;
        }

        void setLastName(string f) {
            lastName = f;
        }
        string getLastName() {
            return lastName;
        }

        void setPid(string f) {
            pid = f;
        }
        string getPid() {
            return pid;
        }

        void setDepartment(string d) {
            department = d;
        }
        string getDepartment() {
            return department;
        }

        void setSalary(double s) {
            salary = s;
        }
        double getSalary() {
            return salary;
        }

        void printInfo() {
            printf("FirsName: %s\nLastName: %s\nSalary: %.2f\n", firstName.c_str(), lastName.c_str(), salary);
        }
};


int main() {

		cout << "Enter first name" << endl;
    string firstName;
    cin >> firstName;
    cout << "Last Name" << endl;
    string lastName;
    cin >> lastName;
    cout << "enter pid" << endl;
    string pid;
    cin >> pid;
    cout << "enter deparment" << endl;
    string dep;
    cin >> dep;
    cout << "eneter salart" << endl;
    double salary;
    cin >> salary;

    Employee emp(firstName, lastName, pid, dep, salary);
    emp.printInfo();

		return 0;

}
Posted by: Guest on March-02-2022

Browse Popular Code Answers by Language