6.3 PARAMETERIZED CONSTRUCTOR

The name parameterized constructor implies that this type of constructor has parameters. Parameter values are generally assigned to data members of the object. Rules regarding name and return type hold good for this type of constructor too.

Problem: Write a program to demonstrate parameterized constructor.

Solution: See Program 6.3.

Program 6.3 Parameterized constructor

const1.cpp#include<iostream.h>class Date{ private :    int day,month,year;  public://  Date(int d ,int m ,int y)     { day = d ;       month = m ;       year = y ;     } ;  void showDate()     { cout<< day<<“:” << month << “:” <<year<<endl ;     };  } ;int main(){ cout<<“<---const1.cpp--->” << endl ;  Date d1 ( 13, 10, 2003) ;  cout<< “Showing ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.