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
#include <iostream>
#include <string>
using namespace std;
 
class Player {
    string name;
public:
    Player() {};
    void setName(string name) { this->name = name; }
    string getName() { return name; }
};
 
class WordGame {
    int playernumber;
    string before;
    string later;
    string name;
public:
    Player *p;
    WordGame() { before = "아버지"; }
    ~WordGame() { delete[]p; }
    void playgame();
};
 
void WordGame::playgame() {
    int index = 0;
    cout << "게임에 참가하는 인원은 몇명입니까?";
    cin >> playernumber;
    p = new Player[playernumber];
    for (int i = 0; i < playernumber; i++) {
        cout << "참가자의 이름을 입력하세요. 빈칸없이>>";
        cin >> name;
        p[i].setName(name);
    }
    cout << "시작하는 단어는 " << before << "입니다." << endl;
    while (1) {
        if (index == playernumber) {
            index = 0;
        }
        cout << p[index].getName() << ">>";
        cin >> later;
        if (before.at(4== later.at(0&& before.at(5== later.at(1)) {
            before = later;
            index++;
            continue;
        }
        else {
            cout << p[index].getName() << "이(가) 졌습니다.";
            break;
        }
    }
}
 
int main() {
    cout << "끝말 잇기 게임을 시작합니다" << endl;
    WordGame start;
    start.playgame();
}
cs

AP10_Ram.h

1
2
3
4
5
6
7
8
9
class Ram {
    char mem[100 * 1024];
    int size;
public:
    Ram();
    ~Ram();
    char read(int address);
    void write(int address, char value);
};
cs
AP10_Ram.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include "AP10_Ram.h"
using namespace std;
 
Ram::Ram() {
    size = 100 * 1024;
    for (int i = 0; i < size; i++) {
        mem[i] = 0;
    }
}
Ram::~Ram() {
    cout << "메모리 제거됨" << endl;
}
char Ram::read(int address) {
    return mem[address];
}
void Ram::write(int address, char value) {
    mem[address] = value;
}
cs
AP10_main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include "AP10_Ram.h"
using namespace std;
 
int main() {
    Ram ram;
    ram.write(10020);
    ram.write(10130);
    char res = ram.read(100+ ram.read(101);
    ram.write(102, res);
    cout << "102 번지의 값 = " << (int)ram.read(102<< endl;
}
cs


AP9_Box.h

1
2
3
4
5
6
7
8
9
class Box {
    int width, height;
    char fill;
public:
    Box(int w, int h) { setSize(w, h); fill = '*'; }
    void setFill(char f) { fill = f; }
    void setSize(int w, int h) { width = w; height = h; }
    void draw();
};
cs

AP9_Box.cpp

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include "AP9_Box.h"
using namespace std;
 
void Box::draw() {
    for (int n = 0; n < height; n++) {
        for (int m = 0; m < width; m++)cout << fill;
        cout << endl;
    }
}
cs

AP9_main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include "AP9_Box.h"
using namespace std;
 
int main() {
    Box b(102);
    b.draw();
    cout << endl;
    b.setSize(74);
    b.setFill('^');
    b.draw();
}
cs


AP8_(2)_Calculator.h

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
class Add {
    int a;
    int b;
public:
    void setValue(int x, int y);
    int calculate();
};
class Sub {
    int a;
    int b;
public:
    void setValue(int x, int y);
    int calculate();
};
class Mul {
    int a;
    int b;
public:
    void setValue(int x, int y);
    int calculate();
};
class Div {
    int a;
    int b;
public:
    void setValue(int x, int y);
    int calculate();
};
cs

AP8_(2)_Calculator.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
#include "AP8_(2)_Calculator.h"
 
void Add::setValue(int x, int y) {
    a = x; b = y;
}
void Sub::setValue(int x, int y) {
    a = x; b = y;
}
void Mul::setValue(int x, int y) {
    a = x; b = y;
}
void Div::setValue(int x, int y) {
    a = x; b = y;
}
int Add::calculate() {
    return a + b;
}
int Sub::calculate() {
    return a - b;
}
int Mul::calculate() {
    return a * b;
}
int Div::calculate() {
    return a / b;
}

cs

AP8_(2)_main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
 
#include "AP8_(2)_Calculator.h"
 
int main() {
    int x, y;
    char op;
    while (1) {
        cout << "두 정수와 연산자를 입력하세요>>";
        cin >> x >> y >> op;
        switch (op) {
        case '+':Add a; a.setValue(x, y); cout << a.calculate() << endlbreak;
        case '-':Sub s; s.setValue(x, y); cout << s.calculate() << endlbreak;
        case '*':Mul m; m.setValue(x, y); cout << m.calculate() << endlbreak;
        case '/':Div d; d.setValue(x, y); cout << d.calculate() << endlbreak;
        default:cout << "잘못된 연산자 입니다" << endlbreak;
        }
    }
}
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
#include <iostream>
using namespace std;
 
class Add {
    int a;
    int b;
public:
    void setValue(int x, int y) { a = x; b = y; }
    int calculate() { return a + b; }
};
class Sub {
    int a;
    int b;
public:
    void setValue(int x, int y) { a = x; b = y; }
    int calculate() { return a - b; }
};
class Mul {
    int a;
    int b;
public:
    void setValue(int x, int y) { a = x; b = y; }
    int calculate() { return a * b; }
};
class Div {
    int a;
    int b;
public:
    void setValue(int x, int y) { a = x; b = y; }
    int calculate() { return a / b; }
};
 
int main() {
    int x, y;
    char op;
    while (1) {
        cout << "두 정수와 연산자를 입력하세요>>";
        cin >> x >> y >> op;
        switch (op) {
        case '+':Add a; a.setValue(x, y); cout << a.calculate() << endlbreak;
        case '-':Sub s; s.setValue(x, y); cout << s.calculate() << endlbreak;
        case '*':Mul m; m.setValue(x, y); cout << m.calculate() << endlbreak;
        case '/':Div d; d.setValue(x, y); cout << d.calculate() << endlbreak;
        default:cout << "잘못된 연산자 입니다" << endlbreak;
        }
    }
}
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 Oval {
    int width;
    int height;
public:
    Oval() { width = 1; height = 1; }
    Oval(int width, int height) { this->width = width; this->height = height; }
    ~Oval() { cout << "Oval 소멸 : width = " << width << ", height = " << height << endl; }
    void set(int width, int height) { this->width = width; this->height = height; }
    int getWidth() { return width; }
    int getHeight() { return height; }
    void show() { cout << "width = " << width << ", height = " << height << endl; }
};
 
int main() {
    Oval a, b(34);
    a.set(1020);
    a.show();
    cout << b.getWidth() << "," << b.getHeight() << endl;
}
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
#include <iostream>
#include <string>
using namespace std;
 
class Integer {
    int number;
public:
    Integer(int n) { number = n; }
    Integer(const char *n) { number = stoi(n); }
    int get() { return number; }
    void set(int n) { number = n; }
    int isEven();
};
 
int Integer::isEven() {
    if (number % 2 == 0return 1;
    else return 0;
}
 
int main() {
    Integer n(30);
    cout << n.get() << ' ';
    n.set(50);
    cout << n.get() << ' ';
 
    Integer m("300");
    cout << m.get() << ' ';
    cout << m.isEven();
}
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
 
class SelectableRandom {
public:
    SelectableRandom() { srand((unsigned)time(0)); }
    int next();
    int nextInRange(int low, int high);
};
 
int SelectableRandom::next() {
    int number;
    while (1) {
        number = rand();
        if (number % 2 == 0break;
    }
    return number;
}
 
int SelectableRandom::nextInRange(int low, int high) {
    int number;
    while (1) {
        number = rand() % (high - low + 1+ low;
        if (number % 2 != 0break;
    }
    return number;
}
 
int main() {
    SelectableRandom r;
    cout << "-- 0에서 " << RAND_MAX << "까지의 랜덤 정수 10 개--" << endl;
    for (int i = 0; i < 10; i++) {
        int n = r.next();
        cout << n << ' ';
    }
    cout << endl << endl << "-- 2에서 " << "9 까지의랜덤 정수 10 개 --" << endl;
    for (int i = 0; i < 10; i++) {
        int n = r.nextInRange(29);
        cout << n << ' ';
    }
    cout << endl;
}
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
 
class EvenRandom {
public:
    EvenRandom() { srand((unsigned)time(0)); }
    int next();
    int nextInRange(int low, int high);
};
 
int EvenRandom::next() {
    int number;
    while (1) {
        number = rand();
        if (number % 2 == 0break;
    }
    return number;
}
 
int EvenRandom::nextInRange(int low, int high) {
    int number;
    while (1) {
        number = rand() % (high - low + 1+ low;
        if (number % 2 == 0break;
    }
    return number;
}
 
int main() {
    EvenRandom r;
    cout << "-- 0에서 " << RAND_MAX << "까지의 랜덤 정수 10 개--" << endl;
    for (int i = 0; i < 10; i++) {
        int n = r.next();
        cout << n << ' ';
    }
    cout << endl << endl << "-- 2에서 " << "10 까지의랜덤 정수 10 개 --" << endl;
    for (int i = 0; i < 10; i++) {
        int n = r.nextInRange(210);
        cout << n << ' ';
    }
    cout << endl;
}
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
 
class Random {
public:
    Random() { srand((unsigned)time(0)); }
    int next();
    int nextInRange(int low, int high);
};
 
int Random::next() {
    int number = rand();
    return number;
}
 
int Random::nextInRange(int low, int high) {
    int number = rand() % (high - low + 1+ low;
    return number;
}
 
int main() {
    Random r;
    cout << "-- 0에서 " << RAND_MAX << "까지의 랜덤 정수 10 개--" << endl;
    for (int i = 0; i < 10; i++) {
        int n = r.next();
        cout << n << ' ';
    }
    cout << endl << endl << "-- 2에서 " << "4 까지의랜덤 정수 10 개 --" << endl;
    for (int i = 0; i < 10; i++) {
        int n = r.nextInRange(24);
        cout << n << ' ';
    }
    cout << endl;
}
cs


+ Recent posts