C++ 기반의 데이터 입출력
문제1
#include <iostream>
using namespace std;
class Point
{
private:
int xpos, ypos;
public:
Point(int x, int y) : xpos(x), ypos(y) {}
void ShowPointInfo() const {
cout << "[" << xpos << ", " << ypos << "]" << endl;
}
};
class Circle
{
private:
Point dot;
int radius;
public:
Circle(int x, int y, int r) : dot(x, y), radius(r) {}
void ShowCircleInfo() const {
cout << "radius: " << radius << "\n";
dot.ShowPointInfo();
}
};
class Ring
{
private:
Circle innerCircle, outerCircle;
public:
Ring(int x1, int y1, int r1, int x2, int y2, int r2) : innerCircle(x1, y1, r1), outerCircle(x2, y2, r2) {}
void ShowRingInfo() {
cout << "Inner Circle Info...\n";
innerCircle.ShowCircleInfo();
cout << "Outer Circle Info...\n";
outerCircle.ShowCircleInfo();
}
};
int main(void)
{
Ring ring(1, 1, 4, 2, 2, 9);
ring.ShowRingInfo();
return 0;
}
문제2
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
namespace COMP_POS {
enum
{
CLERK, SENIOR, ASSIST, MANAGER
};
void ShowPositionInfo(int pos)
{
switch (pos)
{
case CLERK: cout << "사원" << endl; break;
case SENIOR: cout << "주임" << endl; break;
case ASSIST: cout << "대리" << endl; break;
case MANAGER: cout << "과장" << endl; break;
}
}
}
class NameCard {
private:
char* name;
char* comp;
char* pnum;
int rank;
public:
NameCard(char* myname, char* mycomp, char* mypnum, int pos) : rank(pos)
{
int len = strlen(myname) + 1;
name = new char[len];
strcpy(name, myname);
len = strlen(mycomp) + 1;
comp = new char[len];
strcpy(comp, mycomp);
len = strlen(mypnum) + 1;
pnum = new char[len];
strcpy(pnum, mypnum);
}
void ShowNameCardInfo() const
{
cout << "이름: " << name << endl;
cout << "회사: " << comp << endl;
cout << "전화번호: " << pnum << endl;
cout << "직급: "; COMP_POS::ShowPositionInfo(rank);
cout << endl;
}
~NameCard()
{
delete[]name;
delete[]comp;
delete[]pnum;
}
};
int main()
{
char cle1[] = "Lee";
char sen1[] = "Hong";
char ass1[] = "Kim";
char cle2[] = "ABCEng";
char sen2[] = "OrangeEng";
char ass2[] = "SoGoodComp";
char cle3[] = "010-1111-2222";
char sen3[] = "010-3333-4444";
char ass3[] = "010-5555-6666";
NameCard manClerk(cle1, cle2, cle3, COMP_POS::CLERK);
NameCard manSENIOR(sen1, sen2, sen3, COMP_POS::SENIOR);
NameCard manAssist(ass1, ass2, ass3, COMP_POS::ASSIST);
manClerk.ShowNameCardInfo();
manSENIOR.ShowNameCardInfo();
manAssist.ShowNameCardInfo();
return 0;
}
책 답지에는 생성자 매개변수 자리에 큰따옴표를 써서 문자열을 입력했는데, 내 컴퓨터에서는 이 부분이 에러가 난다..
728x90
반응형
'etc. > 열혈 C++ 프로그래밍' 카테고리의 다른 글
(열혈 C++ 프로그래밍) 문제 05-1 (0) | 2021.11.17 |
---|---|
(열혈 C++ 프로그래밍) OOP 단계별 프로젝트 02단계 (0) | 2021.11.17 |
(열혈 C++ 프로그래밍) 문제 04-2 (0) | 2021.11.16 |
(열혈 C++ 프로그래밍) 문제 04-1 (0) | 2021.11.15 |
(열혈 C++ 프로그래밍) 문제 03-2 (2) | 2021.11.11 |