Please help me i dont understand whats wrong with my code

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 18
Reputation: sanfan49er is an unknown quantity at this point 
Solved Threads: 0
sanfan49er's Avatar
sanfan49er sanfan49er is offline Offline
Newbie Poster

Please help me i dont understand whats wrong with my code

 
0
  #1
Mar 13th, 2008
I have been working on this code and I can't get it to work any help out there? I am a new user and would really appreciate it if somebody can correct whats going wrong with it.
  1. // DEBUG10-4
  2. // PartTimeEmployee derives from Employee
  3. // Employees make $800 per week
  4. // PartTimeEmployees make $7.85 per hour
  5. #include<iostream>
  6. #include<string>
  7. using namespace std;
  8. class Employee
  9. {
  10. protected:
  11. string firstName;
  12. string lastName;
  13. double salary;
  14. public:
  15. Employee(string, string);
  16. void showEmployee();
  17. void setData();
  18. string getfirstName();
  19. string getlastName();
  20. };
  21. Employee::Employee(string first, string last)
  22. {
  23. firstName = firstName;
  24. lastName = lastName;
  25. salary = 800;
  26. };
  27. void Employee::setData()
  28. {
  29. cout<<"Enter Employee's first name ";
  30. cin>>firstName;
  31. cout<<"Enter last name ";
  32. cin>>lastName;
  33. salary = 800;
  34. }
  35. void Employee::showEmployee()
  36. {
  37. cout<<firstName<<" "<<lastName<<
  38. " Salary $"<<salary<<endl;
  39. }
  40. string Employee::getlastName()
  41. {
  42. return lastName;
  43. }
  44. string Employee::getfirstName()
  45. {
  46. return firstName;
  47. }
  48. class PartTimeEmployee : public Employee
  49. {
  50. public:
  51. PartTimeEmployee(string, string);
  52. };
  53. PartTimeEmployee::PartTimeEmployee(string first, string last) :
  54. Employee(first,last)
  55. {
  56. salary = 7.85;
  57. }
  58.  
  59. int main()
  60. {
  61. const int NUMEMPS = 3;
  62. string first;
  63. string last;
  64. Employee workers(first, last);
  65. int x;
  66. for(x = 0; x < NUMEMPS; ++x)
  67. {
  68. Employee temp;
  69. char pt;
  70. temp.setData();
  71. cout<<"Is employee part time - y or n? ";
  72. cin>>pt;
  73. if(pt = 'y')
  74. {
  75. PartTimeEmployee tempPartTime(temp.getfirstName(), temp.getlastName());
  76. temp = tempPartTime;
  77. }
  78. workers[NUMEPS] = temp;
  79. }
  80. cout<<endl<<"Employees: "<<endl;
  81. for(x = 0; x <= NUMEMPS; ++x)
  82. workers[NUMEMPS].showEmployee();
  83.  
  84. system("pause");
  85. }
HELP PLEASEEE!!!!
Last edited by Narue; Mar 13th, 2008 at 11:35 am. Reason: Added code tags, please do it yourself next time.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,783
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 744
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Please help me i dont understand whats wrong with my code

 
0
  #2
Mar 13th, 2008
"It doesn't work" isn't helpful. Be specific about how it doesn't work and we'll be in a better position to tell you why it doesn't work.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 18
Reputation: sanfan49er is an unknown quantity at this point 
Solved Threads: 0
sanfan49er's Avatar
sanfan49er sanfan49er is offline Offline
Newbie Poster

Re: Please help me i dont understand whats wrong with my code

 
0
  #3
Mar 13th, 2008
good point well in the int main section of the coding i got everything else to work so far but it doesn't read the employee and I know I need to read the number of employees. I also know that I declared it as string from the class employee from the top. SO... in tail I need to debug the bottom part of the code to make it read the number of employees i just need to run three
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,783
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 744
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Please help me i dont understand whats wrong with my code

 
0
  #4
Mar 13th, 2008
I changed several things in your class, so you'll want to find and study what I did. Your approach in main has some subtle issues, so rather than walk you through it bit by bit, I simply wrote my own version for you to use as a template:
  1. // DEBUG10-4
  2. // PartTimeEmployee derives from Employee
  3. // Employees make $800 per week
  4. // PartTimeEmployees make $7.85 per hour
  5. #include<iostream>
  6. #include<string>
  7. using namespace std;
  8. class Employee
  9. {
  10. protected:
  11. string firstName;
  12. string lastName;
  13. double salary;
  14. public:
  15. Employee();
  16. Employee(string, string);
  17. void showEmployee();
  18. void setData();
  19. string getfirstName();
  20. string getlastName();
  21. };
  22. Employee::Employee()
  23. {
  24. salary = 0;
  25. }
  26. Employee::Employee(string first, string last)
  27. {
  28. firstName = first;
  29. lastName = last;
  30. salary = 800;
  31. };
  32. void Employee::setData()
  33. {
  34. cout<<"Enter Employee's first name ";
  35. cin>>firstName;
  36. cout<<"Enter last name ";
  37. cin>>lastName;
  38. salary = 800;
  39. }
  40. void Employee::showEmployee()
  41. {
  42. cout<<firstName<<" "<<lastName<<
  43. " Salary $"<<salary<<endl;
  44. }
  45. string Employee::getlastName()
  46. {
  47. return lastName;
  48. }
  49. string Employee::getfirstName()
  50. {
  51. return firstName;
  52. }
  53. class PartTimeEmployee : public Employee
  54. {
  55. public:
  56. PartTimeEmployee(string, string);
  57. };
  58. PartTimeEmployee::PartTimeEmployee(string first, string last) :
  59. Employee(first,last)
  60. {
  61. salary = 7.85;
  62. }
  63.  
  64. int main()
  65. {
  66. const int NUMEMPS = 3;
  67.  
  68. Employee workers[NUMEMPS];
  69.  
  70. for ( int i = 0; i < NUMEMPS; i++ ) {
  71. workers[i].setData();
  72.  
  73. // Clean up leftovers from setData()
  74. cin.ignore ( 80, '\n' );
  75.  
  76. cout<<"Is the employee part-time? (y/n): ";
  77.  
  78. if ( cin.get() == 'y' ) {
  79. workers[i] = PartTimeEmployee (
  80. workers[i].getfirstName(), workers[i].getlastName() );
  81. }
  82.  
  83. // Clean up leftovers from cin.get()
  84. cin.ignore ( 80, '\n' );
  85. }
  86.  
  87. cout<<"Employees:\n";
  88.  
  89. for ( int i = 0; i < NUMEMPS; i++ )
  90. workers[i].showEmployee();
  91.  
  92. cin.get();
  93. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC