Whats in this post?
- Background and Explanation of the code
To copy code: Click “View Source” on the right of this code snippet.
Background and Explanation of the code
In this program we first define a class date for maintaining date information.Then we define a student class that not only contains member rollno, name, read ( ) and show ( ) but also contains object dob of class date as its data member which maintains student’s date of birth information.The object dob gets memory only when the object of composite class student is created.In main ( ) the statement
creates an object s1 of class student which in turn also creates the object dob contained within it.The statement s1.read ( ); on execution first inputs rollno and name and then inputs dd, mm, yy by invoking the read ( ) member function through the object dob of date class.Similarly all the information is displayed.
Enter rollno and name = 101 rahul
Enter date, month and year = 2 11 2000
Rollno = 101 name = rahul date = 2/11/2000