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
#include <iostream>
using namespace std;
 
class Statistics {
    int *stack;
    int index;
public:
    Statistics() { stack = new int[100]; index = 0; }
    ~Statistics() { delete[]stack; }
    bool operator!();
    Statistics& operator<< (int x);
    void operator~();
    void operator>>(int &avg);
};
 
bool Statistics::operator!() {
    if (index == 0return true;
    else return false;
}
 
Statistics& Statistics::operator<<(int x) {
    stack[index] = x;
    index++;
    return *this;
}
 
void Statistics::operator~() {
    for (int i = 0; i < index; i++cout << stack[i] << ' ';
    cout << '\n';
}
 
void Statistics::operator>>(int &avg) {
    int sum = 0;
    for (int i = 0; i < index; i++) sum += stack[i];
    avg = sum / index;
}
 
int main() {
    Statistics stat;
    if (!stat) cout << "현재 통계 데이타가 없습니다." << '\n';
 
    int x[5];
    cout << "5 개의 정수를 입력하라>>";
    for (int i = 0; i < 5; i++cin >> x[i];
 
    for (int i = 0; i < 5; i++) stat << x[i];
    stat << 100 << 200;
    ~stat;
 
    int avg;
    stat >> avg;
    cout << "avg=" << avg << '\n';
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
 
class Circle {
    int radius;
public:
    Circle(int radius = 0) { this->radius = radius; }
    void show() { cout << "radius = " << radius << " 인 원" << '\n'; }
    friend Circle operator+(int x, Circle a);
};
 
Circle operator+(int x, Circle a) {
    a.radius += x;
    return a;
}
 
int main() {
    Circle a(5), b(4);
    b = 1 + a;
    a.show();
    b.show();
}
cs


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
#include <iostream>
using namespace std;
 
class Circle {
    int radius;
public:
    Circle(int radius = 0) { this->radius = radius; }
    void show() { cout << "radius = " << radius << " 인 원" << '\n'; }
    Circle operator++();
    Circle operator++(int x);
};
 
Circle Circle::operator++() {
    radius++;
    return *this;
}
 
Circle Circle::operator++(int x) {
    Circle tmp = *this;
    radius++;
    return tmp;
}
 
int main() {
    Circle a(5), b(4);
    ++a;
    b = a++;
    a.show();
    b.show();
}
cs


AP6_(1).cpp

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
#include <iostream>
using namespace std;
 
class Matrix {
    int a1, a2, a3, a4;
public:
    Matrix() {}
    Matrix(int a1, int a2, int a3, int a4) { this->a1 = a1; this->a2 = a2; this->a3 = a3; this->a4 = a4; }
    void show() { cout << "Matrix = { " << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << " }" << '\n'; }
    void operator>>(int x[]);
    void operator<<(int y[]);
};
 
void Matrix::operator>>(int x[]) {
    x[0= a1;
    x[1= a2;
    x[2= a3;
    x[3= a4;
}
 
void Matrix::operator<<(int y[]) {
    a1 = y[0];
    a2 = y[1];
    a3 = y[2];
    a4 = y[3];
}
 
int main() {
    Matrix a(4321), b;
    int x[4], y[4= { 1,2,3,4 };
    a >> x;
    b << y;
 
    for (int i = 0; i < 4; i++cout << x[i] << ' ';
    cout << '\n';
    b.show();
}
cs

AP6_(2).cpp

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
#include <iostream>
using namespace std;
 
class Matrix {
    int a1, a2, a3, a4;
public:
    Matrix() {}
    Matrix(int a1, int a2, int a3, int a4) { this->a1 = a1; this->a2 = a2; this->a3 = a3; this->a4 = a4; }
    void show() { cout << "Matrix = { " << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << " }" << '\n'; }
    friend void operator>>(Matrix a, int x[]);
    friend void operator<<(Matrix &a, int y[]);
};
 
void operator>>(Matrix a, int x[]) {
    x[0= a.a1;
    x[1= a.a2;
    x[2= a.a3;
    x[3= a.a4;
}
 
void operator<<(Matrix &a, int y[]) {
    a.a1 = y[0];
    a.a2 = y[1];
    a.a3 = y[2];
    a.a4 = y[3];
}
 
int main() {
    Matrix a(4321), b;
    int x[4], y[4= { 1,2,3,4 };
    a >> x;
    b << y;
 
    for (int i = 0; i < 4; i++cout << x[i] << ' ';
    cout << '\n';
    b.show();
}
cs


AP5_(1).cpp

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
#include <iostream>
#include <string>
using namespace std;
 
class Matrix {
    int a1, a2, a3, a4;
public:
    Matrix() {};
    Matrix(int a1, int a2, int a3, int a4) { this->a1 = a1; this->a2 = a2; this->a3 = a3; this->a4 = a4; }
    void show() {
        cout << "Matrix = { " << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << " }\n";
    }
    Matrix operator+(Matrix b);
    Matrix operator+=(Matrix b);
    bool operator== (Matrix b);
};
 
Matrix Matrix::operator+(Matrix b) {
    Matrix tmp = *this;
    tmp.a1 = this->a1 + b.a1;
    tmp.a2 = this->a2 + b.a2;
    tmp.a3 = this->a3 + b.a3;
    tmp.a4 = this->a4 + b.a4;
    return tmp;
}
 
Matrix Matrix::operator+=(Matrix  b) {
    a1 += b.a1;
    a2 += b.a2;
    a3 += b.a3;
    a4 += b.a4;
    return *this;
}
 
bool Matrix::operator==(Matrix b) {
    if (a1 == b.a1&&a2 == b.a2&&a3 == b.a3&&a4 == b.a4) return true;
    else return false;
}
 
int main() {
    Matrix a(1234), b(2345), c;
    c = a + b;
    a += b;
    a.show(); b.show(); c.show();
    if (a == c)
        cout << "a and c are the same" << '\n';
}
cs

AP5_(2).cpp

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
#include <iostream>
#include <string>
using namespace std;
 
class Matrix {
    int a1,a2,a3,a4;
public:
    Matrix() {};
    Matrix(int a1, int a2, int a3, int a4) { this->a1 = a1; this->a2 = a2; this->a3 = a3; this->a4 = a4; }
    void show() {
        cout << "Matrix = { " << a1 << ' ' << a2 << ' ' << a3 << ' ' << a4 << " }\n";
    }
    friend Matrix operator+(Matrix a, Matrix b);
    friend Matrix operator+=(Matrix a, Matrix b);
    friend bool operator== (Matrix a, Matrix b);
};
 
Matrix operator+(Matrix a, Matrix b) {
    Matrix tmp = a;
    tmp.a1 = a.a1 + b.a1;
    tmp.a2 = a.a2 + b.a2;
    tmp.a3 = a.a3 + b.a3;
    tmp.a4 = a.a4 + b.a4;
    return tmp;
}
 
Matrix operator+=(Matrix a, Matrix  b) {
    a.a1 += b.a1;
    a.a2 += b.a2;
    a.a3 += b.a3;
    a.a4 += b.a4;
    return a;
}
 
bool operator==(Matrix a, Matrix b) {
    if (a.a1 == b.a1&&a.a2 == b.a2&&a.a3 == b.a3&&a.a4 == b.a4) return true;
    else return false;
}
 
int main() {
    Matrix a(1234), b(2345), c;
    c = a + b;
    a += b;
    a.show(); b.show(); c.show();
    if (a == c)
        cout << "a and c are the same" << '\n';
}
cs


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
#include <iostream>
#include <string>
using namespace std;
 
class Book {
    string title;
    int price, pages;
public:
    Book(string title = ""int price = 0int pages = 0) {
        this->title = title; this->price = price; this->pages = pages;
    }
    void show() {
        cout << title << ' ' << price << "원 " << pages << " 페이지" << '\n';
    }
    string getTitle() { return title; }
    friend bool operator<(string b, Book a);
};
 
bool operator<(string b, Book a) {
    if (b < a.title) return true;
    else return false;
}
 
int main() {
    Book a("청춘"20000300);
    string b;
    cout << "책 이름을 입력하세요>>";
    getline(cin, b);
    if (b < a)
        cout << a.getTitle() << "이 " << b << "보다 뒤에 있구나!" << '\n';
}
cs


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
#include <iostream>
#include <string>
using namespace std;
 
class Book {
    string title;
    int price, pages;
public:
    Book(string title = ""int price = 0int pages = 0) {
        this->title = title; this->price = price; this->pages = pages;
    }
    void show() {
        cout << title << ' ' << price << "원 " << pages << " 페이지" << '\n';
    }
    string getTitle() { return title; }
    bool operator!();
};
 
bool Book::operator!() {
    if (price == 0return true;
    else return false;
}
 
int main() {
    Book book("벼룩시장"050);
    if (!book) cout << "꽁짜다" << '\n';
}
cs


AP2_(1).cpp

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
#include <iostream>
#include <string>
using namespace std;
 
class Book {
    string title;
    int price, pages;
public:
    Book(string title = ""int price = 0int pages = 0) {
        this->title = title; this->price = price; this->pages = pages;
    }
    void show() {
        cout << title << ' ' << price << "원 " << pages << " 페이지" << '\n';
    }
    string getTitle() { return title; }
    bool operator==(int price);
    bool operator==(string book);
    bool operator==(Book b);
};
 
bool Book::operator==(int price) {
    if (this->price == price) return true;
    else return false;
}
 
bool Book::operator==(string title) {
    if (this->title == title) return true;
    else return false;
}
 
bool Book::operator==(Book b) {
    if (b.price == price && b.pages == pages && b.title == title) return true;
    else return false;
}
 
int main() {
    Book a("명품 C++"30000200), b("고품 C++"30000500);
    if (a == 30000cout << "정가 30000원" << '\n';
    if (a == "명품 C++"cout << "명품 C++ 입니다." << '\n';
    if (a == b) cout << "두 책이 같은 책입니다." << '\n';
}
cs

AP2_(2).cpp

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
#include <iostream>
#include <string>
using namespace std;
 
class Book {
    string title;
    int price, pages;
public:
    Book(string title = ""int price = 0int pages = 0) {
        this->title = title; this->price = price; this->pages = pages;
    }
    void show() {
        cout << title << ' ' << price << "원 " << pages << " 페이지" << '\n';
    }
    string getTitle() { return title; }
    friend bool operator==(Book a, int price);
    friend bool operator==(Book a, string book);
    friend bool operator==(Book a, Book b);
};
 
bool operator==(Book a, int price) {
    if (a.price == price) return true;
    else return false;
}
 
bool operator==(Book a, string title) {
    if (a.title == title) return true;
    else return false;
}
 
bool operator==(Book a, Book b) {
    if (b.price == a.price && b.pages == a.pages && b.title == a.title) return true;
    else return false;
}
 
int main() {
    Book a("명품 C++"30000200), b("고품 C++"30000500);
    if (a == 30000cout << "정가 30000원" << '\n';
    if (a == "명품 C++"cout << "명품 C++ 입니다." << '\n';
    if (a == b) cout << "두 책이 같은 책입니다." << '\n';
}
cs


AP1_(1).cpp

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
#include <iostream>
#include <string>
using namespace std;
 
class Book {
    string title;
    int price, pages;
public:
    Book(string title = ""int price = 0int pages = 0) {
        this->title = title; this->price = price; this->pages = pages;
    }
    void show() {
        cout << title << ' ' << price << "원 " << pages << " 페이지" << '\n';
    }
    string getTitle() { return title; }
    Book operator+=(int price);
    Book operator-=(int price);
};
 
Book Book::operator+=(int price) {
    this->price += price;
    return *this;
}
 
Book Book::operator-=(int price) {
    this->price -= price;
    return *this;
}
 
int main() {
    Book a("청춘"20000300), b("미래"30000500);
    a += 500;
    b -= 500;
    a.show();
    b.show();
}
cs

AP1_(2).cpp

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
#include <iostream>
#include <string>
using namespace std;
 
class Book {
    string title;
    int price, pages;
public:
    Book(string title = ""int price = 0int pages = 0) {
        this->title = title; this->price = price; this->pages = pages;
    }
    void show() {
        cout << title << ' ' << price << "원 " << pages << " 페이지" << '\n';
    }
    string getTitle() { return title; }
    friend Book operator+=(Book &b, int price);
    friend Book operator-=(Book &b, int price);
};
 
Book operator+=(Book &b, int price) {
    b.price += price;
    return b;
}
 
Book operator-=(Book &b, int price) {
    b.price -= price;
    return b;
}
 
int main() {
    Book a("청춘"20000300), b("미래"30000500);
    a += 500;
    b -= 500;
    a.show();
    b.show();
}
cs


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
#include <iostream>
#include <string>
using namespace std;
 
class Histogram {
    string histo;
public:
    Histogram(string histo) { this->histo = histo; }
    Histogram& operator<<(string str);
    Histogram& operator<<(char c);
    void operator!();
};
 
Histogram& Histogram::operator<<(string str) {
    histo += str;
    return *this;
}
 
Histogram& Histogram::operator<<(char c) {
    histo += c;
    return *this;
}
 
void Histogram::operator!() {
    int len = 0;
    int abc[26= { 0 };
    for (int i = 0; i < histo.length(); i++) {
        cout << histo[i];
        if (isalpha(histo[i])) {
            len++;
            for (int j = 0; j < 26; j++) {
                if ((char)(j + 97== tolower(histo[i])) abc[j]++;
            }
        }
    }
    cout << "\n\n" << "총 알파벳 수 " << len << '\n';
    for (int i = 0; i < 26; i++) {
        cout << (char)(i + 97<< ":";
        for (int j = 0; j < abc[i]; j++)
            cout << "*";
        cout << '\n';
    }
}
 
int main() {
    Histogram song("Wise men say, \nonly fools rush in But I can't help, \n");
    song << "falling" << " in love with you." << "- by ";
    song << 'k' << 'i' << 't';
    !song;
}
cs


+ Recent posts