Advertisement
Guest User

Programming

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