#include<iostream.h>
#include<conio.h>
class person
{
private:
char name[50];
public:
void get()
{
cout<<"Enter Name: ";
cin>>name;
}
void show()
{
cout<<"your name: "<<name<<endl;
}
};
void main()
{
person * ptr[5]; //declare pointer
for(int i=0;i<5;i++)
{
ptr[i] = new person; //used to locate memory at runtime
//u can say new will create an object and transfer it in ptr[i]
ptr[i] -> get();
}
cout<<"\n\n";
for(int i=0;i<5;i++)
ptr[i] -> show();
getch();
}
#include<conio.h>
class person
{
private:
char name[50];
public:
void get()
{
cout<<"Enter Name: ";
cin>>name;
}
void show()
{
cout<<"your name: "<<name<<endl;
}
};
void main()
{
person * ptr[5]; //declare pointer
for(int i=0;i<5;i++)
{
ptr[i] = new person; //used to locate memory at runtime
//u can say new will create an object and transfer it in ptr[i]
ptr[i] -> get();
}
cout<<"\n\n";
for(int i=0;i<5;i++)
ptr[i] -> show();
getch();
}
0 comments:
Post a Comment