InterviewSolution
Saved Bookmarks
| 1. |
Write A Program That Implements A Date Class Containing Day, Month And Year As Data Members. Implement Assignment Operator And Copy Constructor In This Class. |
|
Answer» Answer :This is shown in following program: #include CLASS date { private : int day ; int month ; int year ; public : date ( int d = 0, int m = 0, int y = 0 ) { day = d ; month = m ; year = y ; } // copy constructor date ( date &d ) { day = d.day ; month = d.month ; year = d.year ; } // an overloaded ASSIGNMENT operator date operator = ( date d ) { day = d.day ; month = d.month ; year = d.year ; return d ; } void DISPLAY( ) { COUT << day << "/" << month << "/" << year ; } } ; void main( ) { date d1 ( 25, 9, 1979 ) ; date d2 = d1 ; date d3 ; d3 = d2 ; d3.display( ) ; } |
|