티스토리 뷰
문제 05-1 [복사 생성자의 정의]
#include <iostream>
#include <cstring>
using namespace std;
namespace COMP_POS
{
enum { CLERK, SENIOR, ASSIST, MANAGER };
void ShowRank(int _rank)
{
switch(_rank)
{
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 * company;
char * phoneNumber;
int rank;
public:
NameCard(char * _name, char * _company, char * _phoneNumber, int _rank) : rank(_rank)
{
name = new char[strlen(_name)+1];
strcpy(name, _name);
company = new char[strlen(_company)+1];
strcpy(company, _company);
phoneNumber = new char[strlen(_phoneNumber)+1];
strcpy(phoneNumber, _phoneNumber);
}
NameCard(const NameCard ©) : rank(copy.rank)
{
name = new char[strlen(copy.name) + 1];
strcpy(name, copy.name);
company = new char[strlen(copy.company) + 1];
strcpy(company, copy.company);
phoneNumber = new char[strlen(copy.phoneNumber) + 1];
strcpy(phoneNumber, copy.phoneNumber);
}
void ShowNameCardInfo()
{
cout << "이름: " << name << endl;
cout << "회사: " << company << endl;
cout << "전화번호: " << phoneNumber << endl;
cout << "직급: "; COMP_POS::ShowRank(rank);
cout << endl;
}
~NameCard()
{
delete name;
delete company;
delete phoneNumber;
cout << "소멸자 실행" << endl;
}
};
int main()
{
NameCard manClerk("Lee", "ABCEng", "010-1111-2222", COMP_POS::CLERK);
NameCard copy1 = manClerk;
NameCard manSENIOR("Hong", "OrangeEng", "010-3333-4444", COMP_POS::SENIOR);
NameCard copy2 = manSENIOR;
copy1.ShowNameCardInfo();
copy2.ShowNameCardInfo();
}
'윤성우의 열헐 C++' 카테고리의 다른 글
윤성우의 열혈 c++) OOP 단계별 프로젝트 05단계 (0) | 2022.03.19 |
---|---|
윤성우의 열혈 c++) Chapter 07. 상속의 이해 (0) | 2022.03.19 |
윤성우의 열혈 c++) OOP 단계별 프로젝트 04단계 (0) | 2022.03.19 |
윤성우의 열혈 c++) OOP 단계별 프로젝트 03단계 (0) | 2022.03.16 |
윤성우의 열혈 c++) OOP 단계별 프로젝트 02단계 (0) | 2022.03.16 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- floyd warshall
- Kruskal
- C++
- priority queue
- Python
- greedy
- C
- Spring
- DP
- binary search
- MVC
- Tree
- 자료구조
- CSS
- BFS
- Brute Force
- permutation
- 조합
- Dijkstra
- recursion
- 이분탐색
- dfs
- Stack
- 재귀
- Unity
- two pointer
- graph
- db
- back tracking
- Implementation
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함