Advertisement
Guest User

Untitled

a guest
Feb 26th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class numDays {
  6.  
  7. private: // member variables
  8. int hours;
  9. double days;
  10.  
  11. public: // member functions
  12.  
  13. numDays(int h = 0) {
  14. hours = h;
  15. days = h / 8;
  16. }
  17.  
  18. void setHours(int s) {
  19. hours = s;
  20. days = s / 8;
  21. }
  22.  
  23. double getDays() {
  24. return days;
  25. }
  26.  
  27. numDays operator+(numDays& obj) {
  28. // what to put here?
  29. }
  30.  
  31. numDays operator- (numDays& obj) { // Overloaded subtraction
  32. // and here?
  33. }
  34. numDays operator++ () { // Overloaded postfix increment
  35. hours++;
  36. days = hours / 8.0;
  37. numDays temp_obj(hours);
  38. return temp_obj;
  39. }
  40. numDays operator++ (int) { // Overloaded prefix increment
  41. numDays temp_obj(hours);
  42. hours++;
  43. days = hours / 8.0;
  44. return temp_obj;
  45. }
  46. numDays operator-- () { // Overloaded postfix decrement
  47. hours--;
  48. days = hours / 8.0;
  49. numDays temp_obj(hours);
  50. return temp_obj;
  51. }
  52. numDays operator-- (int) { // Overloaded prefix decrement
  53. numDays temp_obj(hours);
  54. hours--;
  55. days = hours / 8.0;
  56. return temp_obj;
  57. }
  58. };
  59.  
  60.  
  61. int main() {
  62. // insert code here...
  63. numDays one(25), two(15), three, four;
  64.  
  65. // Display one and two.
  66. cout << "One: " << one.getDays() << endl;
  67. cout << "Two: " << two.getDays() << endl;
  68. // Add one and two, assign result to three.
  69. three = one + two;
  70. // Display three.
  71. cout << "Three: " << three.getDays() << endl;
  72. // Postfix increment...
  73. four = three++;
  74. cout << "Four = Three++: " << four.getDays() << endl;
  75. // Prefix increment...
  76. four = ++three;
  77. cout << "Four = ++Three: " << four.getDays() << endl;
  78. // Postfix decrement...
  79. four = three--;
  80. cout << "Four = Three--: " << four.getDays() << endl;
  81. // Prefix increment...
  82. four = --three;
  83. cout << "Four = --Three: " << four.getDays() << endl;
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement