문제 04-2번
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstring>
using namespace std;
class Point
{
private:
int xpos;
int ypos;
public:
void Init(int x, int y)
{
xpos = x;
ypos = y;
}
void ShowPointInfo() const
{
cout << "[" << xpos << "," << ypos << "]" << endl;
}
};
class Circle
{
private:
int Radius;
Point Center;
public:
void Init(int x, int y, int r)
{
Radius = r;
Center.Init(x, y);
}
void ShowCircleInfo() const
{
cout << "Radius: " << Radius << endl;
Center.ShowPointInfo();
}
};
class Ring
{
private:
Circle FirstCircle;
Circle SecondCircle;
public:
void Init(int X,int Y,int R, int X2,int Y2, int R2)
{
FirstCircle.Init(X, Y, R);
SecondCircle.Init(X2, Y2, R2);
}
void ShowRingInfo() const
{
cout << "Inner Circle Info..." << endl;
FirstCircle.ShowCircleInfo();
cout << "Outter Circle Info..." << endl;
SecondCircle.ShowCircleInfo();
}
};
int main(void)
{
Ring ring;
ring.Init(1, 1, 4, 2, 2, 9);
ring.ShowRingInfo();
return 0;
}
생성자 추가 버전 4-3 문제
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstring>
using namespace std;
class Point
{
private:
int xpos;
int ypos;
public:
Point(int x, int y)
:xpos(x), ypos(y)
{
//empty
}
void ShowPointInfo() const
{
cout << "[" << xpos << "," << ypos << "]" << endl;
}
};
class Circle
{
private:
int Radius;
Point Center;
public:
Circle(int x, int y, int r)
:Center(x,y)
{
Radius = r;
}
void ShowCircleInfo() const
{
cout << "Radius: " << Radius << endl;
Center.ShowPointInfo();
}
};
class Ring
{
private:
Circle FirstCircle;
Circle SecondCircle;
public:
Ring(int X, int Y, int R, int X2, int Y2, int R2)
:FirstCircle(X,Y,R),SecondCircle(X2, Y2, R2)
{
//EMPTY
}
void ShowRingInfo() const
{
cout << "Inner Circle Info..." << endl;
FirstCircle.ShowCircleInfo();
cout << "Outter Circle Info..." << endl;
SecondCircle.ShowCircleInfo();
}
};
int main(void)
{
Ring ring(1, 1, 4, 2, 2, 9);
ring.ShowRingInfo();
return 0;
}
'프로그래밍 언어 > c++' 카테고리의 다른 글
집의 평수를 제곱 미터로 바꾸는 프로그램(C++ espresso) (0) | 2022.03.28 |
---|---|
다양한 자료형의 이해(LPSTR, LPTSTR, LPCSTR, LPWSTR, LPCTSTR, LPCWSTR) (0) | 2022.03.28 |
C++로 상자의 부피 구하는 프로그램 (0) | 2022.03.25 |
윤성우 열현 C++ 프로그래밍 문제 03-2번 (0) | 2022.01.21 |
열혈 c++ 문제 03-1[구조체 내에 함수 정의하기] (0) | 2022.01.13 |