PROGRAM FOR ARRAY OF POINTER
//program for array of pointer
#include<iostream.h>
#include<conio.h>
#include<string.h>
class city
{
protected:
char *name;
int len;
public:
city()
{
len=0;
name=new char[len+1];
}
void printname()
{
cout<<name<<endl;
}
void getname();
};
void city::getname()
{
char *s;
s=new char[30];
cout<<"enter city name:";
cin>>s;
len=strlen(s);
name=new char[len+1];
strcpy(name,s);
}
void main()
{
city *cptr[10];
int n=1,option;
clrscr();
do
{
cptr[n]=new city;
cptr[n]->getname();
n++;
cout<<"do you want to enter one more?\n";
cout<<"enter 1 for yes 0 for no:";
cin>>option;
}while(option);
cout<<endl<<endl;
for(int i=1;i<=n;i++)
{
cptr[i]->printname();
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<string.h>
class city
{
protected:
char *name;
int len;
public:
city()
{
len=0;
name=new char[len+1];
}
void printname()
{
cout<<name<<endl;
}
void getname();
};
void city::getname()
{
char *s;
s=new char[30];
cout<<"enter city name:";
cin>>s;
len=strlen(s);
name=new char[len+1];
strcpy(name,s);
}
void main()
{
city *cptr[10];
int n=1,option;
clrscr();
do
{
cptr[n]=new city;
cptr[n]->getname();
n++;
cout<<"do you want to enter one more?\n";
cout<<"enter 1 for yes 0 for no:";
cin>>option;
}while(option);
cout<<endl<<endl;
for(int i=1;i<=n;i++)
{
cptr[i]->printname();
}
getch();
}

Comments
Post a Comment