Day04-04

C,C++/CONCEPT 2018. 3. 10. 20:30 |
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<string>
using namespace std;
 
/*
class
1. has a (data 와 달리  class)>>포함 오브젝트
2. (is a)상속구조, ~는 ~이다
*/
class A
{
    string name;
public:
    void setName(string name) 
    {
        this->name = name;
    }
 
    string getName()const
    {
        return name;
    }
};
 
class B
{
    A aa; // 포함오브젝트 // private임
    int age;
 
public:
 
    void setName(string name){
        aa.setName(name);
    }
 
    void setAge(int age ){
        this->age = age;
    }
    string getName()const{
        return aa.getName();
    }
    int getAge()const
    {
        return age;
    }
};
 
 
void main()
{
    B bb;
    bb.setName("superman");    // 이름입력
    bb.setAge(100);    // 나이입력
    cout<<bb.getName()<<endl;    // 이름출력
    cout<<bb.getAge()<<endl;    // 나이출력
}
 
cs


'C,C++ > CONCEPT' 카테고리의 다른 글

Day04-06  (0) 2018.03.10
Day04-05  (0) 2018.03.10
Day04-03  (0) 2018.03.10
[c++]has~a 관계를 이용한 사람수 제한없는 성적프로그램  (0) 2018.03.09
XAMPP 프로젝트 경로 설정  (0) 2018.03.08
Posted by 너래쟁이
: