CS Electrical And Electronics
@cselectricalandelectronics

How to create array of objects using this pointers using the new operator in Cpp?

All QuestionsCategory: Cpp LanguageHow to create array of objects using this pointers using the new operator in Cpp?
CS Electrical And Electronics Staff asked 4 years ago

I need short information.

1 Answers
CS Electrical And Electronics Staff answered 4 years ago

Create a class of item, and then implement this code.

const int size =3;
int main()
{
item *p = new item[size];
item *d = p;
int x,i;
float y;
for(i=0;i<size;i++)
{
cout<<“Input code and price for item”<<i+1;
cin>>x>>y;
p->getdata(x,y);
p++;
}
for(i=0;i<size;i++)
{
cout<<“Items”<<i=1;
d->show();
d++;
}
return 0;
}