본문 바로가기

c++

(5)
c++ public protected private public #include using namespace std; /* 상속 ==> 코드의 재활용 유지보수 부모클래스: 자식의 공통된 사황을 가지고 있다 자식클래스: 자신만의 고유한 기능을 추가만 하면된다. 1.상속방식 1> private 상속 : has ~ a; 부모의 멤버가 모두 자식으로 상속했을 때 : private로 변한다. (내부적으로 변한다.) 2> protected 상속: has ~ a; 부모의 public 멤버가 protected로 변환하여 상속된다. 3> public 상속 : is ~a; 있는 그대로 상속이 된다. */ class A { private: int a1 =1; protected: int b1 =2; public: int c1 =3 ; int getA1() { return a1..
reference 레퍼런스 계산기 구현 #include using namespace std; int input(int *a, int *b, char *op) { float opp=0; cout *a >> *b; cout op; switch (*op) { case '+': opp = *a + *b; break; case '-': opp = *a - *b; break; case '*': opp = *a * *b; break; case '/': opp =(float) *a / *b; break; } return opp; } void print(int opp) { cout
c++ operator 연산자 구현 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 #include using namespace std; class A{ int a; public: A(int a = 0) { this-> a = a; } void setA(int a) { this->a = a; } int getA() { return a; } friend ostream & operator (ostream &in, A &aa); friend istream & operator >> (istream & in, A &aa); }; ostream & operator aa...
c++ 동적 계산기 구현 ver1 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 #include using namespace std; class cal { private: int a; int b; char op; int opp = 0; public: int input() { cout a >> b; cout op; switch (op) { case '+': opp = a + b; break; case '-': opp = a - b; break; case '*': opp = a * b; break; case '/': opp = a / b; br..
c++ string을 나만의 것으로 구현 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 12..