-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch8 1~2번문제.cpp
53 lines (48 loc) · 1.22 KB
/
ch8 1~2번문제.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>
using namespace std;
class Circle {
int radius;
public:
Circle(int radius = 0) { this->radius = radius; }
int getRadius() { return radius; }
void setRadius(int radius) { this->radius = radius; }
double getArea() { return radius * radius * 3.14; }
};
class NameCircle : public Circle {
string name;
public:
NameCircle() { this->name = "", setRadius(0); }
NameCircle(int radius, string name) { setRadius(radius), this->name = name; }
void setName(string name) { this->name = name; }
void show() { cout << "반지름이 " << getRadius() << "인 " << this->name << endl; }
string getName() { return name; }
};
int main()
{
NameCircle waffle(3, "waffle");
waffle.show();
//1번
NameCircle pizza[5];
int radius;
string name;
int maxIndex = 0;
int max= 0;
cout << "5개의 정수 반지름과 원의 이름을 입력하세요" << endl;
for (int i = 0; i < 5; i++)
{
cout << i+1 << " >> ";
cin >> radius >> name;
pizza[i].setRadius(radius);
pizza[i].setName(name);
}
for (int i = 0; i < 5; i++)
{
if (pizza[i].getArea() > max)
{
max = pizza[i].getArea();
maxIndex = i;
}
}
cout << "가장 면적이 큰 피자는 " << pizza[maxIndex].getName() << "입니다" << endl;
}