C언어 ver3
너에게제공
359 0 1
#include <iostream>
using namespace std;
class Circle
{
private:
int r;
float area;
public:
Circle(int a){r=a;}
Circle(){r=0;}
void calcArea(){area=(float)r*r*3.14;}
void print(){cout<<"반지름 : "<<r<<", 넓이 : "<<area<<endl;}
void setRadius(){int d; cout<<"반지름 : "; cin>>d; r=d;}
};
int main()
{
Circle c[3];
for(int b=0; b<3; b++)
{
c[b].setRadius();
c[b].calcArea();
}
cout<<"원의 넓이 구하기"<<endl;
for(int k=0; k<3; k++)
{
c[k].print();
}
}
using namespace std;
class Circle
{
private:
int r;
double area;
public:
Circle()
{
}
void calcArea()
{
area=r*r*3.14;
}
void print()
{
cout<<"반지름 : "<<r;
cout<<" 넓이 : "<<area<<endl;
}
void setRadius(int i)
{
r=i;
}
};
int main()
{
Circle cr[3];
for(int i=0; i<3; i++)
{
int a;
cin>>a;
cr[i].setRadius(a);
cr[i].calcArea();
}
for(int j=0; j<3; j++)
cr[j].print();
}