
<code>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
class Circle { | |
int radius; | |
string name; | |
public: | |
void setCircle(string name, int radius) | |
{ | |
this->name = name; | |
this->radius = radius; | |
} | |
double getArea() { return 3.14 * radius * radius; }; | |
string getName() { return name; }; | |
}; | |
class CircleManager { | |
Circle* p; | |
int size; | |
public: | |
CircleManager(int size) | |
{ | |
p = new Circle[size]; | |
this->size = size; | |
}; | |
~CircleManager() { delete[]p; } | |
void searchByName() | |
{ | |
string n; | |
cin >> n; | |
for (int i = 0; i < size; i++) | |
{ | |
if (p[i].getName() == n) | |
cout << n << "의 면적은 " << p[i].getArea() << endl; | |
} | |
}; | |
void searchByArea() | |
{ | |
int a; | |
cin >> a; | |
cout << a << "보다 큰 원을 검색합니다." << endl; | |
for (int i = 0; i < size; i++) | |
{ | |
if (p[i].getArea() > a) | |
{ | |
cout << p[i].getName() << "의 면적은 " << p[i].getArea()<<","; | |
} | |
} | |
} | |
void setcircle() | |
{ | |
string name; | |
int radius; | |
for (int i = 0; i < size; i++) | |
{ | |
cout << "원 " << i + 1 << "의 이름과 반지름 >>"; | |
cin >> name >> radius; | |
p[i].setCircle(name, radius); | |
} | |
} | |
}; | |
int main() | |
{ | |
int size; | |
string name; | |
cout << "원의 개수 >>"; | |
cin >> size; | |
CircleManager circle(size); | |
circle.setcircle(); | |
cout << "검색하고자 하는 원의 이름 >>"; | |
circle.searchByName(); | |
cout << "최소 면적을 정수로 입력하세요 >>"; | |
circle.searchByArea(); | |
} |
'C++ > 명품 c++ programming' 카테고리의 다른 글
명품 Programming C++ chapter 4 챕터 4장 실습 문제 14번 (0) | 2020.07.28 |
---|---|
명품 Programming C++ chapter 4 챕터 4장 실습 문제 13번 (0) | 2020.07.28 |
명품 Programming C++ chapter 4 챕터 4장 실습 문제 11번 (0) | 2020.07.28 |
명품 Programming C++ chapter 4 챕터 4장 실습 문제 10번 (0) | 2020.07.27 |
명품 Programming C++ chapter4 챕터 4장 실습 문제 9번 (0) | 2020.07.24 |