Days, Months, Years Program to show Copy Constructor in C++


#include<iostream.h>
#include<conio.h>

class PERIOD
{
    int days, months,years;
  public:
    void show();
    PERIOD(int d,int m,int y);
    PERIOD(const PERIOD &);
};

void PERIOD::show()
{
      cout<<days<<months<<years<<endl;
}

PERIOD::PERIOD(int d,int m,int y)
{
      days=d;months=m;years=y;
}

PERIOD::PERIOD(const PERIOD &tmp)
{
      cout<<"Copied"<<"\n";
      days=tmp.days;months=tmp.months;years=tmp.years;
}

int main ()
{
clrscr();
   PERIOD p1(10,6,100);
   p1.show();
   PERIOD p2(p1);
   p2.show();
  getch();
  return 0;
}

Custom Search