CodesJava

Easy learning with example program codes

CPP Aggregation


The process of defining a class by some other class as any entity reference is termed as aggregation in CPP programming. In other words, aggregation can be defined as the process of reusing a class in a form of association. In CPP, the term aggregation means “HAS-A relationship.”

Example:

#include <iostream.h>
using namespace std;
 
class Student
{
public:  
string Name;  
float ID;
Student(string Name, float ID) 	 
{    
this-> Name = Name;    
this-> ID = ID;   
}
};
class Details   
{    
private:  
Student* std;  
public:  
int stdclass;    
string section;    
Details(int stdclass, string section, Student* std)    
{    
this->stdclass = stdclass;    
this->section = section;    
this->std = std;    
}    
 
void detail()
{
cout << "Student Class : " << stdclass << endl;
cout << "Student Section : " << section << endl;
cout << "Student Name : " << std->Name<< endl;
cout << "Student ID : "<< std->ID << endl;  
}
};
int main()
{
Student s1 = Student("Khush", 1);    
Details d1 = Details(6, "A", &s1);  
d1.detail(); 	 
return 0;
}

Output

Student Class : 6    
Student Section : A  
Student Name : Khush  
Student ID : 1
Posted in CPP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki