/*
Array of Object's and Parameterized Constructor
*/
#include<iostream>
#include<string.h>
using namespace std;
class Person
{
int age;
char name[20];
public:
// Default Constructor
Person()
{
}
// Parameterized Constructor
Person(int a,char n[])
{
age=a;
strcpy(name,n);
}
void display()
{
cout<<"\n Name: "<<name;
cout<<"\n Age: "<<age;
}
};
int main()
{
Person P[5];
int age,i;
char name[20];
for(i=0;i<5;i++)
{
cout<<"\n\n Enter for Person "<<i+1<<" name and age: ";
cin>>name>>age;
P[i]=Person(age,name);
}
for(i=0;i<5;i++)
{
cout<<"\n\n Person:"<<i+1;
P[i].display();
}
return 0;
}
Array of Object's and Parameterized Constructor
*/
#include<iostream>
#include<string.h>
using namespace std;
class Person
{
int age;
char name[20];
public:
// Default Constructor
Person()
{
}
// Parameterized Constructor
Person(int a,char n[])
{
age=a;
strcpy(name,n);
}
void display()
{
cout<<"\n Name: "<<name;
cout<<"\n Age: "<<age;
}
};
int main()
{
Person P[5];
int age,i;
char name[20];
for(i=0;i<5;i++)
{
cout<<"\n\n Enter for Person "<<i+1<<" name and age: ";
cin>>name>>age;
P[i]=Person(age,name);
}
for(i=0;i<5;i++)
{
cout<<"\n\n Person:"<<i+1;
P[i].display();
}
return 0;
}