C언어 Rectangle 객체배열
레이나sv
501 0 2
void main()
{
Rectangle r[3];
for(int i=0 ; i<3 ; i++){
r[i].calcArea();
r[i].print();
}
}
--------------------------------------------------
void main()
{
int w,h;
Rectangle r[3];
for(int i=0; i<3; i++)
{
cout<<"가로 : "; cin>>w;
cout<<"세로 : ";cin>>h;
r[i].setRectangle(w,h);
r[i].calcArea();
r[i].print();
}
}
----------------------------------------------
void main(){ Rectangle r[3]; Rectangle *r1=r; // 또는 Rectangle r[3], *r1; // r1 = r; int a,b; for(int i=0;i<3;i++){ cout<<"가로 : "; cin>>a; cout<<"세로 : "; cin>>b; r[i].setWidth(a); r[i].setHeight(b); r[i].calcArea(); } for(int j=0;j<3;j++){ (r1+j)->print(); } } |
{
Rectangle *rp = new Rectangle;
rp->setRectangle(10,20);
rp->calcArea();
rp->print();
delete rp;
}