Guest User

Untitled

a guest
Jan 19th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. //Program Name: Employee info
  2. //Programmer: Trevor England
  3. //Date: 1/17/16//Program Description: Program inputs data from the user and then returns it using a class
  4.  
  5.  
  6. #include <iostream>
  7. #include <string>
  8. #include <stdlib.h>
  9. #include <iomanip>
  10.  
  11.  
  12. using namespace std;
  13. void DisplayDivider(string);
  14. string GetInput(string);
  15.  
  16.  
  17.  
  18. class employee
  19. {
  20. private:
  21. string firstName,lastName;
  22. int empID, dependents;
  23. char gender;
  24. double annualSalary;
  25. public:
  26. employee(){firstName = " " , lastName = " ", empID = 0, dependents = 0, gender = 'U', annualSalary = 0;}
  27. 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){};
  28. double calcPay(){return annualSalary / 52;}
  29. void displayEmployee();
  30. string getFirstName(){return firstName;}
  31. void setFirstName(string first){firstName = first;}
  32. string getLastName(){return lastName;}
  33. void setLastName(string last){lastName = last;}
  34. int getEmpID(){return empID;}
  35. void setEmpID(int ID){empID = ID;}
  36. char getGender(){return gender;}
  37. void setGender(char gen){gender = gen;}
  38. int getDependents(){return dependents;}
  39. void setDependents(int dep){dependents = dep;}
  40. double getAnnualSalary(){return annualSalary;}
  41. void setAnnualSalary(double sal){annualSalary = sal;}
  42.  
  43. };
  44.  
  45. void employee::displayEmployee()
  46. {
  47.  
  48. cout << "Name : " << firstName << " " << lastName << endl;
  49. cout << "Employee ID: " << empID << endl;
  50. cout << "Gender: " << gender << endl;
  51. cout << "Dependent: " << dependents << endl;
  52. cout << "Annual Salary: " << fixed << setprecision(2) << annualSalary << endl;
  53. cout << "Weekly Salary: " << fixed << setprecision(2) << calcPay() << endl;
  54.  
  55. }
  56. void main()
  57. {
  58. string input;
  59.  
  60. DisplayDivider("Employee 1");
  61. cout << endl << endl ;
  62. employee employee1;
  63.  
  64. input = GetInput("first name: ");
  65. employee1.setFirstName(input);
  66. cout << endl;
  67. input = GetInput("last name: ");
  68. employee1.setLastName(input);
  69. cout << endl;
  70. input = GetInput("employee's ID number: ");
  71. employee1.setEmpID(atoi(input.c_str()));
  72. cout << endl;
  73. input = GetInput("employee's gender as (M - Male, F - Female:");
  74. employee1.setGender(input); // RIGHT HERE
  75. cout << endl;
  76. input = GetInput("number of dependents: ");
  77. employee1.setDependents(atoi(input.c_str()));
  78. cout << endl;
  79. input = GetInput("annual salary: ");
  80. employee1.setAnnualSalary(atof(input.c_str()));
  81. cout << endl;
  82. DisplayDivider("Employee Information");
  83. cout << endl;
  84. employee1.displayEmployee();
  85.  
  86.  
  87. DisplayDivider("Employee 2");
  88. cout << endl << endl;
  89. employee emp2("George", "Washington", 12345, 'M', 2, 12000);
  90. DisplayDivider("Employee Information");
  91.  
  92. emp2.displayEmployee();
  93.  
  94.  
  95.  
  96. system("PAUSE");
  97. }
  98.  
  99. void DisplayDivider(string title)
  100. {
  101. cout << "**************** "<< title << "****************\n";
  102. }
  103.  
  104. string GetInput(string item)
  105. {
  106. string strInput;
  107. cout << "Please enter the " << item << endl;
  108. cin >> strInput;
  109. return strInput;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment