You are on page 1of 2

Student Aggregation - Example

============================================
#include <string.h>
#include <iostream.h>
class MyInt{

public:

MyInt(){}
MyInt(int d){id=d;}
void setId(int d){id=d;}
int getId(){return id;}

private:

int id;
};

class Student{

public:

Student(){}
Student(int d,char *n,float m):mInt(d)
{
strcpy(name,n);
marks=m;
}

void setName(char *n){strcpy(name,n);}


void setMarks(float m){marks=m;}

char *getName(){return name;}


float getMarks(){return marks;}

void Print()
{
cout<<"\nID: "<<mInt.getId();
cout<<"\nName: "<<name;
cout<<"\nMarks: "<<marks;
}

private:
MyInt mInt;
char name[30];
float marks;
};

void main()
{
int id;
char nm[30];
float mk;

cout<<"\nEnter the ID: ";


cin>>id;
cout<<"\nEnter the Name: ";
cin>>nm;
cout<<"\nEnter the Marks: ";
cin>>mk;

Student s(id,nm,mk);
s.Print();
cout<<endl;
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006