C언어 동적메모리
너에게제공
458 0 0
void main()
{
int a,b,c;
cout<<"사각형의 갯수 : ";
cin>>c;
Rectangle *r=new Rectangle[c];
for(int i=0;i<c;i++)
{
cout<<"가로 : ";
cin>>a;
cout<<"세로 : ";
cin>>b;
(r+i)->setRectangle(a,b);
(r+i)->calcArea();
(r+i)->print();
}
delete r;
}
{
int a,b,c;
cout<<"사각형의 갯수 : ";
cin>>c;
Rectangle *r=new Rectangle[c];
for(int i=0;i<c;i++)
{
cout<<"가로 : ";
cin>>a;
cout<<"세로 : ";
cin>>b;
(r+i)->setRectangle(a,b);
(r+i)->calcArea();
(r+i)->print();
}
delete r;
}