Advertisement
vvccs

date add/sub

Jun 6th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. class Date
  4. {
  5.       int day;
  6.       int month;
  7.       int year;
  8.       public:
  9.              Date(int d,int m,int y)
  10.              {
  11.                    day=d;
  12.                    month=m;
  13.                    year=y;
  14.              }
  15.  
  16.              friend Date operator -(Date &,int);
  17.              friend Date operator +(Date &,int);
  18.              void display()
  19.              {
  20.                   cout<<"Date:"<<day<<"/"<<month<<"/"<<year<<endl;
  21.              }
  22. };
  23. Date operator-(Date &x,int y)
  24. {
  25.      return Date(x.day-y, x.month, x.year);
  26. }
  27. Date operator+(Date &x,int y)
  28. {
  29.      return Date(x.day+y, x.month, x.year);
  30. }
  31. int main()
  32. {
  33.     int dd,mm,yy;
  34.     cout<<"Enter Day:";
  35.     cin>>dd;
  36.     cout<<"Enter Month:";
  37.     cin>>mm;
  38.     cout<<"Enter Year:";
  39.     cin>>yy;
  40.  
  41.     Date d1(dd,mm,yy);
  42.     Date d2=d1-1;
  43.     d2.display();
  44.     Date d3=d1+1;
  45.     d3.display();
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement