#include<iostream>
usingnamespace std;
class person
{
protected:
char name[40];
public:
void setName()
{
cout<<"Enter name: ";
cin>>name;
}
void printname()
{
cout<<"\n Name is: "<<name;
}
};
int main()
{
person* persptr[100];
int n=0;
char choice;
do
{
persptr[n]=new person;
persptr[n]->setName();
n++;
cout<<"Enter another(y/n)?";
cin>>choice;
}while(choice=='y');
for(int j=0;j<n;j++)
{
cout<<"\nPerson number "<<j+1;
persptr[j]->printname();
}
cout<<endl;
delete[] *persptr;
cout<<"After deleting..\n, 4th person is: ";
persptr[3]->printname();
return 0;
}
and the output is:
Enter name: Tushar
Enter another(y/n)?y
Enter name: Gaurav
Enter another(y/n)?y
Enter name: Saurav
Enter another(y/n)?y
Enter name: Suvam
Enter another(y/n)?n
Person number 1
Name is: Tushar
Person number 2
Name is: Gaurav
Person number 3
Name is: Saurav
Person number 4
Name is: Suvam
After deleting..
, 4th person is:
Name is: Suvam