Program To Maintain Student Information By Creating A Composite Class Having One Of Its Data Member As An Object Of Another Predefined Class In C++

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code

Code


To copy code: Click View Source “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

student s1;

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. 

OUTPUT

Enter rollno and name =   101    rahul

Enter date, month and year =  2    11    2000

Rollno =  101    name  =  rahul       date =  2/11/2000