-
Shape클래스- 상속을 위한 클래스
private접근자를 갖는name필드가 존재Shape클래스를 상속받는 클래스는getArea메서드를 반드시 구현해야만 함getArea메서드는 도형의 넓이를 반환
-
Rect클래스Shape클래스를 상속받는 클래스private접근자를 갖는width,height필드가 존재getArea메서드를 구현
-
printShape프렌드 함수- 도형(
Shape)의 이름(name)과 넓이(getArea)를 출력하는 프렌드 함수
- 도형(
Last active
November 28, 2019 07:24
-
-
Save Gumball12/6703549470e170e85d2df6a58e8bffa2 to your computer and use it in GitHub Desktop.
19-2 튜터링 문제 목록
다음과 같은 Apple과 People 클래스를 작성하도록 하겠습니다.
-
Apple"Apple"문자열을 출력하는print()메서드를 가짐
-
People- 생성자의 파라미터를 통해
Apple인스턴스를 전달받을 수 있음 eat()메서드 내에서Apple인스턴스의print()메서드 실행
- 생성자의 파라미터를 통해
new 키워드를 사용하여 동적으로 클래스 인스턴스를 생성하는 방법으로 진행해주세요.
class Apple {
// ...
};
class People {
// ...
public:
People(Apple * a) {
apple = a;
}
};
int main(void) {
Apple * a = new Apple();
People * p = new People(a);
return 0;
}-
클래스
A와B가 있음A에는int타입의numberA필드가 있음 (private)B에는int타입의numberB필드가 있음 (private)
-
add()는 friend 함수A의numberA와B의numberB를 더하는 동작을 함
class B;
class A {
private:
int numberA;
public:
A(): numberA(100) { }
/* ... */
};
class B {
private:
int numberB;
public:
B(): numberB(200) { }
/* ... */
};
int add (/* ... */) {
/* ... */
}
int main() {
/* ... */
std::cout << add(/* ... */) // "300" 출력
return 0;
}-
int타입의value필드가 있음 (private) -
++연산자를 오버로딩하여 다음과 같은 동작을 진행함- 각
++마다 2씩 더함 - 더한 수를 출력 (
cout)
- 각
-
오버로딩과 생성자를 제외한 메서드는 없음
class Counter {
private:
int value;
public:
Counter(): value(0) { }
/* ... */
};
int main() {
Counter c;
++c; // "2" 출력
++c; // "4" 출력
++c; // "6" 출력
return 0;
}
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

답: https://git.io/Je4rg