Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 주가예측
- 코딩독학
- backend
- 코딩
- 개발자
- frontend
- 자바독학
- Project
- 자바
- SNS
- 코테
- Reflex
- 사물인터넷
- 프로그래머스
- 모의 주식
- Python
- 자바정리
- C++
- java
- 이웃한 칸
- 개인프로젝트
- 백준
- java정리
- 풀스택프레임워크
- 코스닥
- 프로그램
- 코딩테스트
- 개발
- 빅데이터
- 프로그래밍
Archives
- Today
- Total
Creative Code
main.cpp(employee클래스) 본문
※main.cpp파일
#include <iostream>
#include "employee.h"
int main() {
Employee *pEmployees[5];
pEmployees[0] = new Employee(1,"Park Jung Seok ",0);
pEmployees[1] = new Employee(2,"Sung Young Ho",pEmployees[0]);
pEmployees[2] = new Employee(3,"Sim Sung Suk",pEmployees[0]);
pEmployees[3] = new Employee(4,"Choi Su Gil",pEmployees[2]);
pEmployees[4] = new Employee(5,"Kim Young Gin",pEmployees[0]);
for (int i = 0; i<5; i++) {
std::cout << pEmployees[i] -> getId() << ", " << pEmployees[i] -> getName() << " : " ;
if (pEmployees[i] -> isManager()) std::cout << "None";
else std::cout << pEmployees[i]->getManager() ->getName();
std::cout << std::endl;
}
return 0;
for (int i = 0; i<5; i++) {
delete pEmployees[i];
}
}
※employee.h파일
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include "string.h"
class Employee {
private:
int id;
String name;
const Employee *pManager;
Employee(const Employee& rhs); //컴파일러가 자동으로 생성한 함수 중 쓰고싶지 않은 함수는 private에 선언만 해 둔다.
Employee& operator=(const Employee& rhs);
public:
//Employee() { }
Employee(int id, String name, const Employee *pManager);
//~Employee() { }
//Employee *operator&() { return this; }
//const Employee *operator&() const { return this; }
int getId() const;
String getName() const;
const Employee *getManager() const;
bool isManager() const;
};
#endif
※employee.cpp 파일
#include "employee.h"
Employee::Employee(int id, String name, const Employee *pManager) {
this->id = id;
this->name = name;
this->pManager = pManager;
}
int Employee::getId() const {
return this->id;
}
String Employee::getName() const {
return this->name;
}
const Employee *Employee::getManager() const {
return this->pManager;
}
bool Employee::isManager() const {
return this->pManager == 0;
}
'C++ Programming' 카테고리의 다른 글
main.cpp(rational클래스 증감연산자) (0) | 2023.09.04 |
---|---|
main.cpp(complex클래스 증감연산자) (0) | 2023.09.01 |
main.cpp(컴파일러가 자동생성하는 함수) (0) | 2023.09.01 |
main.cpp(string2) (0) | 2023.09.01 |
main.cpp(string) (0) | 2023.08.31 |