Advertisement
Guest User

asdasdasdasd

a guest
Apr 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. /*
  2. Author: Jula Marius
  3. Date: 23/4/18
  4. Description: Implement a C++ application that defines the class called CurrentHour with hour, minute, second as
  5. private members. The class has public setter/getter methods for each attribute. Add a friend function that
  6. copies the content of a CurrentHour object into another instance of the class. Use the computer current
  7. time.
  8. */
  9. #define _CRT_SECURE_NO_WARNINGS
  10.  
  11. #include <iostream>
  12. #include <ctime>
  13. using namespace std;
  14.  
  15. class CurrentHour {
  16. int hour;
  17. int minute;
  18. int second;
  19. public:
  20. CurrentHour();
  21. CurrentHour(int, int, int);
  22. ~CurrentHour();
  23. void setHour(int);
  24. void setMinutes(int);
  25. void setSeconds(int);
  26. int getHour();
  27. int getMinutes();
  28. int getSeconds();
  29. friend void copy(CurrentHour);
  30. };
  31.  
  32. //Constructor w/o parameters
  33. CurrentHour::CurrentHour() {
  34. this->hour = 12;
  35. this->minute = 30;
  36. this->second = 0;
  37. }
  38.  
  39. //Constructor w/ parameters
  40. CurrentHour::CurrentHour(int newH, int newM, int newS) {
  41. this->hour = newH;
  42. this->minute = newM;
  43. this->second = newS;
  44. }
  45.  
  46. //Destructor
  47. CurrentHour::~CurrentHour() {
  48. this->hour = 0;
  49. this->minute = 0;
  50. this->second = 0;
  51. }
  52.  
  53. //Setter for the hour
  54. void CurrentHour::setHour(int newHour) {
  55. this->hour = newHour;
  56. }
  57.  
  58. //Setter for the minutes
  59. void CurrentHour::setMinutes(int newMinutes) {
  60. this->minute = newMinutes;
  61. }
  62.  
  63. //Setter for the seconds
  64. void CurrentHour::setSeconds(int newSeconds) {
  65. this->second = newSeconds;
  66. }
  67.  
  68. //Getter for the hour
  69. int CurrentHour::getHour() {
  70. return this->hour;
  71. }
  72.  
  73. //Getter for the minutes
  74. int CurrentHour::getMinutes() {
  75. return this->minute;
  76. }
  77.  
  78. //Getter for the seconds
  79. int CurrentHour::getSeconds() {
  80. return this->second;
  81. }
  82.  
  83. //Method that copies the content of a CurrentHour object into another instance of the clas
  84. void copy(CurrentHour ob) {
  85. time_t now = time(0);
  86. // convert now to string form
  87. char* dt = ctime(&now);
  88. cout << dt;
  89. }
  90.  
  91. int main() {
  92. CurrentHour ob1, ob2;
  93. ob2.setHour(13);
  94. ob2.setMinutes(24);
  95. ob2.setSeconds(25);
  96. ob1.copy(ob2);
  97. cout<<ob2.getHour();
  98.  
  99. cin.get();
  100. cin.ignore();
  101. return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement