Computer Science, asked by ppratyushsp, 8 months ago

define a constructor function for a date class that initialize the date object with the initial values. In case initial value are not provided , it should initialize the object with default value​

Answers

Answered by Abhinab08
4

Answer:

by

Explanation:

first create a class named Date

  • write the data types required in private section
  • then create a class constructor named same as class name.
  • write arugument to take values
  • if the value are provided than it will display the date
  • if not given it will give default value

#include<iostream.h>

#include<conio.h>

class Date

{

public:

int day,month,year;

Date()

{

cout<<"\nDefault Constructor:";. // by Abhinab08

day=15;

month=09;

year=2020;

}

Date(int d,int m,int y)

{

cout<<"\nArgumented Constructor:\n";

day=d;

month=m;

year=y;

}

void show()

{

cout<<"\nDay :"<<day<<"\nMonth :"<<month<<"\nYear :"<<year;

}

};

void main()

{

clrscr();

Date d;

d.show();

Date d1(14,09,2020);

d1.show();

getch();

}

Similar questions