May 2012
Intermediate to advanced
679 pages
16h 56m
English
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.
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 ...
Read now
Unlock full access