Write a program to add two dates object using constructor to initialize the object and display in standard format.

Sep 2, 2019

Source code:

//program to initialize and display the date
//in proper format
#include <iostream>
using namespace std;

class Date{
    private:
        int dd;
        int mm;
        int yy;
    public:
        //using member initializer list
        Date(int d = 0, int m = 0, int y = 0):dd(d), mm(m), yy(y){}
        void display(){
            cout<<"Date = "<<yy<<"/"<<mm<<"/"<<dd<<endl;
        }
};

int main(){
    Date d(22, 10 , 2019);
    d.display();
    return 0;
}

 

Sample run:

Date = 2019/10/22