Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program Name: Employee info
- //Programmer: Trevor England
- //Date: 1/17/16//Program Description: Program inputs data from the user and then returns it using a class
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- #include <iomanip>
- using namespace std;
- void DisplayDivider(string);
- string GetInput(string);
- class employee
- {
- private:
- string firstName,lastName;
- int empID, dependents;
- char gender;
- double annualSalary;
- public:
- employee(){firstName = " " , lastName = " ", empID = 0, dependents = 0, gender = 'U', annualSalary = 0;}
- employee(string first, string last, int ID, char gen, int dep, double sal): firstName(first), lastName(last), empID(ID), dependents(dep), gender(gen), annualSalary(sal){};
- double calcPay(){return annualSalary / 52;}
- void displayEmployee();
- string getFirstName(){return firstName;}
- void setFirstName(string first){firstName = first;}
- string getLastName(){return lastName;}
- void setLastName(string last){lastName = last;}
- int getEmpID(){return empID;}
- void setEmpID(int ID){empID = ID;}
- char getGender(){return gender;}
- void setGender(char gen){gender = gen;}
- int getDependents(){return dependents;}
- void setDependents(int dep){dependents = dep;}
- double getAnnualSalary(){return annualSalary;}
- void setAnnualSalary(double sal){annualSalary = sal;}
- };
- void employee::displayEmployee()
- {
- cout << "Name : " << firstName << " " << lastName << endl;
- cout << "Employee ID: " << empID << endl;
- cout << "Gender: " << gender << endl;
- cout << "Dependent: " << dependents << endl;
- cout << "Annual Salary: " << fixed << setprecision(2) << annualSalary << endl;
- cout << "Weekly Salary: " << fixed << setprecision(2) << calcPay() << endl;
- }
- void main()
- {
- string input;
- DisplayDivider("Employee 1");
- cout << endl << endl ;
- employee employee1;
- input = GetInput("first name: ");
- employee1.setFirstName(input);
- cout << endl;
- input = GetInput("last name: ");
- employee1.setLastName(input);
- cout << endl;
- input = GetInput("employee's ID number: ");
- employee1.setEmpID(atoi(input.c_str()));
- cout << endl;
- input = GetInput("employee's gender as (M - Male, F - Female:");
- employee1.setGender(input); // RIGHT HERE
- cout << endl;
- input = GetInput("number of dependents: ");
- employee1.setDependents(atoi(input.c_str()));
- cout << endl;
- input = GetInput("annual salary: ");
- employee1.setAnnualSalary(atof(input.c_str()));
- cout << endl;
- DisplayDivider("Employee Information");
- cout << endl;
- employee1.displayEmployee();
- DisplayDivider("Employee 2");
- cout << endl << endl;
- employee emp2("George", "Washington", 12345, 'M', 2, 12000);
- DisplayDivider("Employee Information");
- emp2.displayEmployee();
- system("PAUSE");
- }
- void DisplayDivider(string title)
- {
- cout << "**************** "<< title << "****************\n";
- }
- string GetInput(string item)
- {
- string strInput;
- cout << "Please enter the " << item << endl;
- cin >> strInput;
- return strInput;
- }
Advertisement
Add Comment
Please, Sign In to add comment