Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. //Parameterized constructor signature
  2. Hourly::Hourly(int e, string n, string a, string p, double w, double h) :MyEmployee(e, n, a, p)
  3.  
  4. string fileInput;
  5. string employCategory = "";
  6. const string HOURLY = "Hourly";
  7. const string SALARIED = "Salaried";
  8. int answer;
  9. int count = 0;
  10. const int ONE = 1;
  11. const int TWO = 2;
  12. const int ARRAY_SIZE = 4;
  13. MyEmployee* payroll[ARRAY_SIZE];
  14. ifstream myOpenFile;
  15. ofstream myWrittenFile;
  16. payroll[0] = new Hourly(1, "H. Potter", "Privet Drive", "201-9090", 40, 12.00);
  17. payroll[1] = new Hourly(3, "R. Weasley", "The Burrow", "892-2000", 40, 10.00);
  18. payroll[2] = new Salaried(2, "A. Dumbledore", "Hogwarts", "803-1230", 1200);
  19. payroll[3] = new Salaried(4, "R. Hagrid", "Hogwarts", "910-8765", 1000);
  20. cout << "This program has two options:n1 - Create a data filen2 - Read data from a file and print paychecks.";
  21. //This loop will test if the user's input is valid.
  22. do
  23. {
  24. //Here, the user will enter a value to be used to either print checks or write a file.
  25. cout << "nPlease enter <1> to create a file or <2> to print checks: ";
  26. cin >> answer;
  27. //The user entered one, so we'll write a file.
  28. if (answer == ONE)
  29. {
  30. cin.sync();
  31. cin.clear();
  32. cout << "nPlease enter in the name of the file you wish to write to. Please don't forget to add .txt to the end: ";
  33. getline(cin, fileInput);
  34. myWrittenFile.open(fileInput);
  35. for (int i = 0; i < ARRAY_SIZE; i++)
  36. {
  37. MyEmployee* empPtr = payroll[i];
  38. if (typeid(*empPtr) == typeid(Hourly))
  39. {
  40. Hourly* empHPtr = static_cast<Hourly*>(empPtr);
  41. }
  42. else if (typeid(*empPtr) == typeid(Salaried))
  43. {
  44. Salaried* empSPtr = static_cast<Salaried*>(empPtr);
  45. }
  46. }
  47. for (int i = 0; i < ARRAY_SIZE; i++)
  48. {
  49. payroll[i]->writeData(myWrittenFile);
  50. }
  51. myWrittenFile.close();
  52. cout << "nData saved .....";
  53. for (int i = 0; i < ARRAY_SIZE; i++)
  54. {
  55. delete payroll[i];
  56. payroll[i] = NULL;
  57. }
  58.  
  59.  
  60. }
  61.  
  62. void MyEmployee::writeData(ofstream& out)
  63. {
  64. out << empNum << "n";
  65. out << name << "n";
  66. out << address << "n";
  67. out << phoneNum << "n";
  68. }
  69.  
  70. void Hourly::writeData(ofstream& out)
  71. {
  72. out << hoursWorked << "n";
  73. out << wage << "n";
  74. MyEmployee::writeData(out);
  75. }
  76.  
  77. typeid(*empPtr) == typeid(Hourly)
  78. typeid(*empPtr) == typeid(Salaried)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement