Guest User

Untitled

a guest
Jul 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>;
  2. using namespace std;
  3.  
  4. class Date {
  5. private:
  6.  
  7. public:
  8. int day;
  9. int month;
  10. int year;
  11. Date();
  12. Date(int day, int month, int year);
  13. void Print(Date date);
  14. Date operator=(const string str);
  15.  
  16. };
  17.  
  18. this is the class cpp file:
  19. #include "Date.h"
  20. Date::Date() {};
  21. Date::Date(int day, int month, int year) :
  22. day(day),month(month), year(year){};
  23. void Date::Print(Date date) {
  24. cout << date.day << "/" << date.month << "/" << date.year;
  25. }
  26. Date Date::operator=(string str) {
  27. Date date;
  28. date.day = 0; date.month = 0; date.year = 0;
  29. int i = 0;
  30. while(str[i] != '/'){
  31. date.day = (10 * date.day) + (int)str[i++]- 48;
  32. }
  33. i++;
  34. while(str[i] != '/'){
  35. date.month = (10 * date.month) + (int)str[i++]- 48;
  36. }
  37. i++;
  38. while(i < str.size()){
  39. date.year = (10 * date.year) + (int)str[i]- 48;
  40. i++;
  41. }
  42. cout << date.day << '/' << date.month << '/' << date.year<< endl;
  43. return date;
  44. }
  45.  
  46. #include <iostream>
  47. #include "Date.h"
  48. using namespace std;
  49. int main() {
  50.  
  51. Date d,d2(15,7,18);
  52. string str = "15/7/18";
  53. d = str;
  54. cout << d.day<< endl;
  55. d.Print(d);
  56. return 0;
  57. }
Add Comment
Please, Sign In to add comment