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
#include <iostream>
#include <string>
using namespace std;
 
class Printer {
    string model;
    string manufacturer;
    int printedCount;
    int availableCount;
public:
    Printer(string model, string manufacturer, int availableCount) {
        this->model = model;
        this->manufacturer = manufacturer;
        this->availableCount = availableCount;
    }
    string getModel() { return model; }
    string getManufacturer() { return manufacturer; }
    int getAvailableCount() { return availableCount; }
    virtual void show() = 0;
    bool print(int pages);
};
 
bool Printer::print(int pages) {
    printedCount = pages;
    if (availableCount < printedCount) {
        cout << "용지가 부족하여 프린트할 수 없습니다.\n";
        return false;
    }
    else {
        availableCount -= printedCount;
        return true;
    }
}
 
class Ink :public Printer {
    int availableInk;
public:
    Ink(string model, string manufacturer, int availableCount, int availableInk) :Printer(model, manufacturer, availableCount) {
        this->availableInk = availableInk;
    }
    void show() { cout << "잉크젯 : " << getModel() << " ," << getManufacturer() << " ,남은 종이 " << getAvailableCount() << ", 남은 잉크 " << availableInk << '\n'; }
    void printInkJet(int pages) {
        if (print(pages)) {
            if (availableInk > pages) {
                availableInk -= pages;
                cout << "프린트하였습니다.\n";
            }
            else {
                cout << "잉크가 부족하여 프린트할 수 없습니다\n";
            }
        }
    }
};
 
class Laser :public Printer {
    int availableToner;
public:
    Laser(string model, string manufacturer, int availableCount, int availableToner) :Printer(model, manufacturer, availableCount) {
        this->availableToner = availableToner;
    }
    void show() { cout << "잉크젯 : " << getModel() << " ," << getManufacturer() << " ,남은 종이 " << getAvailableCount() << ", 남은 토너 " << availableToner << '\n'; }
    void printLaser(int pages) {
        if (print(pages)) {
            if (availableToner > pages) {
                availableToner -= pages;
                cout << "프린트하였습니다.\n";
            }
            else {
                cout << "토너가 부족하여 프린트할 수 없습니다\n";
            }
        }
    }
};
 
int main() {
    int printSelect, pages;
    char con;
 
    Ink *= new Ink("Officejet V40""HP"510);
    Laser *= new Laser("SCX-6x45""삼성전자"320);
 
    cout << "현재 작동중인 2 대의 프린터는 아래와 같다\n";
    I->show();
    L->show();
    cout << '\n';
 
    while (1) {
        cout << "프린터(1:잉크젯, 2:레이저)와 매수 입력>>";
        cin >> printSelect >> pages;
        switch (printSelect) {
        case 1:
            I->printInkJet(pages);
            I->show();
            L->show();
            break;
        case 2:
            L->printLaser(pages);
            I->show();
            L->show();
            break;
        default:
            cout << "잘못된 선택입니다\n";
            break;
        }
        cout << "계속 프린트 하시겠습니까(y/n)>>";
        cin >> con;
        cout << '\n';
        if (con == 'y'continue;
        else if (con == 'n'break;
        cin.ignore();
    }
}
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
#include <iostream>
#include <string>
using namespace std;
 
class BaseMemory {
    char *mem;
    int size;
    int index;
protected:
    BaseMemory(int size) { this->size = size; mem = new char[size]; index = 0; }
public:
    char read(int i) { return mem[i]; }
    void burn(char *mem, int size);
    void write(int i, char c) { mem[i] = c; }
};
 
void BaseMemory::burn(char *mem, int size) {
    if (this->size < index) return;
    for (int i = index; i < index + size; i++this->mem[i] = mem[i - index];
    index += size;
}
 
class ROM :public BaseMemory {
public:
    ROM(int cap, char *mem, int size) :BaseMemory(cap) { burn(mem, size); }
};
 
class RAM :public BaseMemory {
public:
    RAM(int cap) :BaseMemory(cap) {};
};
 
int main() {
    char x[5= { 'h''e''l''l''o' };
    ROM biosROM(1024 * 10, x, 5);
    RAM mainMemory(1024 * 1024);
 
    for (int i = 0; i < 5; i++) mainMemory.write(i, biosROM.read(i));
    for (int i = 0; i < 5; i++cout << mainMemory.read(i);
}
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
#include <iostream>
#include <string>
using namespace std;
 
class BaseArray {
private:
    int capacity;
    int *mem;
protected:
    BaseArray(int capacity = 100) {
        this->capacity = capacity; mem = new int[capacity];
    }
    ~BaseArray() { delete[]mem; }
    void put(int index, int val) { mem[index] = val; }
    int get(int index) { return mem[index]; }
    int getCapacity() { return capacity; }
};
 
class MyStack :public BaseArray {
    int index;
public:
    MyStack(int capacity) :BaseArray(capacity) { index = 0; }
    void push(int n) { put(index, n); index++; }
    int pop() { index--return get(index); }
    int capacity() { return getCapacity(); }
    int length() { return index; }
};
 
int main() {
    MyStack mStack(100);
    int n;
    cout << "스택에 삽입할 5개의 정수를 입력하라>> ";
    for (int i = 0; i < 5; i++) {
        cin >> n;
        mStack.push(n);
    }
    cout << "스택의 용량:" << mStack.capacity() << ", 스택의 크기:" << mStack.length() << '\n';
    cout << "스택의 원소를 순서대로 제거하여 출력한다>> ";
    while (mStack.length() != 0) {
        cout << mStack.pop() << ' ';
    }
    cout << '\n' << "스택의 현재 크기 : " << mStack.length() << '\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
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>
using namespace std;
 
class BaseArray {
private:
    int capacity;
    int *mem;
protected:
    BaseArray(int capacity = 100) {
        this->capacity = capacity; mem = new int[capacity];
    }
    ~BaseArray() { delete[]mem; }
    void put(int index, int val) { mem[index] = val; }
    int get(int index) { return mem[index]; }
    int getCapacity() { return capacity; }
};
 
class MyQueue :public BaseArray {
    int index;
public:
    MyQueue(int capacity) :BaseArray(capacity) { index = 0; }
    void enqueue(int n) { put(index, n); index++; }
    int dequeue() { index--return get(index); }
    int capacity() { return getCapacity(); }
    int length() { return index; }
};
 
int main() {
    MyQueue mQ(100);
    int n;
    cout << "큐에 삽입할 5개의 정수를 입력하라>> ";
    for (int i = 0; i < 5; i++) {
        cin >> n;
        mQ.enqueue(n);
    }
    cout << "큐의 용량:" << mQ.capacity() << ", 큐의 크기:" << mQ.length() << '\n';
    cout << "큐의 원소를 순서대로 제거하여 출력한다>> ";
    while (mQ.length() != 0) {
        cout << mQ.dequeue() << ' ';
    }
    cout << '\n' << "큐의 현재 크기 : " << mQ.length() << '\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
32
#include <iostream>
#include <string>
using namespace std;
 
class Point {
    int x, y;
public:
    Point(int x, int y) { this->= x; this->= y; }
    int getX() { return x; }
    int getY() { return y; }
protected:
    void move(int x, int y) { this->= x; this->= y; }
};
 
class ColorPoint :public Point {
    string color;
public:
    ColorPoint(int x = 0int y = 0string color = "BLACK") :Point(x, y) { this->color = color; }
    void setPoint(int x, int y) { move(x, y); }
    void setColor(string color) { this->color = color; }
    void show() { cout << color << "색으로 (" << getX() << ", " << getY() << ")에 위치한 점입니다.\n"; }
};
 
int main() {
    ColorPoint zeroPoint;
    zeroPoint.show();
 
    ColorPoint cp(55);
    cp.setPoint(1020);
    cp.setColor("BLUE");
    cp.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
#include <iostream>
#include <string>
using namespace std;
 
class Point {
    int x, y;
public:
    Point(int x, int y) { this->= x; this->= y; }
    int getX() { return x;}
    int getY() { return y;}
protected:
    void move(int x, int y) { this->= x; this->= y; }
};
 
class ColorPoint:public Point {
    string color;
public:
    ColorPoint(int x, int y, string color) :Point(x, y) { this->color = color; }
    void setPoint(int x, int y) { move(x, y); }
    void setColor(string color) { this->color = color; }
    void show() { cout << color << "색으로 (" << getX() << ", " << getY() << ")에 위치한 점입니다.\n"; }
};
 
int main() {
    ColorPoint cp(55"RED");
    cp.setPoint(1020);
    cp.setColor("BLUE");
    cp.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
#include <iostream>
#include <string>
using namespace std;
 
class Circle {
    int radius;
public:
    Circle(int radius = 0) { this->radius = radius; }
    int getRadius() { return radius; }
    void setRadius(int radius) { this->radius = radius; }
    double getArea() { return 3.14*radius*radius; }
};
 
class NamedCircle :public Circle {
    string name;
public:
    void setName(string name) { this->name = name; }
    string getName() { return name; }
};
 
int main() {
    int radius;
    string pizzaName;
    NamedCircle pizza[5];
    cout << "5 개의 정수 반지름과 원의 이름을 입력하세요\n";
    for (int i = 0; i < 5; i++) {
        cout << i + 1 << ">> ";
        cin >> radius;
        getline(cin, pizzaName);
        pizza[i].setRadius(radius);
        pizza[i].setName(pizzaName);
    }
    double maxArea = pizza[0].getArea();
    int index = 0;
    for (int i = 1; i < 5; i++) {
        if (maxArea < pizza[i].getArea()) {
            maxArea = pizza[i].getArea();
            index = i;
        }
    }
    cout << "가장 면적이 큰 피자는 " << pizza[index].getName() << "입니다\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
#include <iostream>
#include <string>
using namespace std;
 
class Circle {
    int radius;
public:
    Circle(int radius = 0) { this->radius = radius; }
    int getRadius() { return radius;}
    void setRadius(int radius) { this->radius = radius; }
    double getArea() { return 3.14*radius*radius; }
};
 
class NamedCircle :public Circle {
    string name;
public:
    NamedCircle(int radius, string name) :Circle(radius) { this->name = name; }
    void show() { cout << "반지름이 " << getRadius() << "인 " << name << '\n'; }
};
 
int main() {
    NamedCircle waffle(3"waffle");
    waffle.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <string>
using namespace std;
 
class Product {
protected:
    int id;
    string info;
    string prod;
    string price;
public:
    Product(){}
    Product(int id, string info, string prod, string price) {
        this->id = id; this->info = info; this->prod = prod; this->price = price;
    }
    virtual void show() = 0;
};
 
class Book :public Product {
protected:
    string ISBN;
    string writer;
    string sub;
public:
    Book(int id, string info, string prod, string price, string ISBN, string writer, string sub) :Product(id, info, prod, price) {
        this->ISBN = ISBN;
        this->writer = writer;
        this->sub = sub;
    }
    void show() {
        cout << "---- 상품 ID : " << id << '\n';
        cout << "상품설명 : " << info << '\n';
        cout << "생산자 : " << prod << '\n';
        cout << "가격 : " << price << '\n';
        cout << "ISBN : " << ISBN << '\n';
        cout << "책제목 : " << sub << '\n';
        cout << "저자 : " << writer << '\n';
    }
};
 
class ConversationBook :public Book {
protected:
    string lan;
public:
    ConversationBook(int id, string info, string prod, string price, string ISBN, string writer, string sub, string lan) :Book(id, info, prod, price, ISBN, writer, sub) {
        this->lan = lan;
    }
    void show() {
        cout << "---- 상품 ID : " << id << '\n';
        cout << "상품설명 : " << info << '\n';
        cout << "생산자 : " << prod << '\n';
        cout << "가격 : " << price << '\n';
        cout << "ISBN : " << ISBN << '\n';
        cout << "책제목 : " << sub << '\n';
        cout << "저자 : " << writer << '\n';
        cout << "언어 : " << lan << '\n';
    }
};
 
class CompactDisk :public Product {
protected:
    string a_sub;
    string singer;
public:
    CompactDisk(int id, string info, string prod, string price, string a_sub, string singer) :Product(id, info, prod, price) {
        this->a_sub = a_sub;
        this->singer = singer;
    }
    void show() {
        cout << "---- 상품 ID : " << id << '\n';
        cout << "상품설명 : " << info << '\n';
        cout << "생산자 : " << prod << '\n';
        cout << "가격 : " << price << '\n';
        cout << "앨범제목 : " << a_sub << '\n';
        cout << "가수 : " << singer << '\n';
    }
};
 
int main() {
    Product* p[100];
    int menu, o_menu;
    int index = 0;
    string info, prod, price, ISBN, writer, sub, lan, a_sub, singer;
    cout << "***** 상품 관리 프로그램을 작동합니다 *****" << '\n';
    while (1) {
        cout << "상품 추가(1), 모든 상품 조회(2), 끝내기(3) ? ";
        cin >> menu;
        switch (menu) {
        case 1:
            cout << "상품 종류 책(1), 음악CD(2), 회화책(3) ? ";
            cin >> o_menu;
            cin.ignore();
            switch (o_menu) {
            case 1: {
                cout << "상품설명>>"; getline(cin, info);
                cout << "생산자>>"; getline(cin, prod);
                cout << "가격>>"; getline(cin, price);
                cout << "책제목>>"; getline(cin, sub);
                cout << "저자>>"; getline(cin, writer);
                cout << "ISBN>>"; getline(cin, ISBN);
                cout << "\n";
                Book *= new Book(index, info, prod, price, ISBN, writer, sub);
                p[index] = b;
                break;
            }
            case 2: {
                cout << "상품설명>>"; getline(cin, info);
                cout << "생산자>>"; getline(cin, prod);
                cout << "가격>>"; getline(cin, price);
                cout << "앨범제목>>"; getline(cin, a_sub);
                cout << "가수>>"; getline(cin, singer);
                cout << "\n";
                CompactDisk *= new CompactDisk(index, info, prod, price, a_sub, singer);
                p[index] = c;
                break;
            }
            case 3: {
                cout << "상품설명>>"; getline(cin, info);
                cout << "생산자>>"; getline(cin, prod);
                cout << "가격>>"; getline(cin, price);
                cout << "책제목>>"; getline(cin, sub);
                cout << "저자>>"; getline(cin, writer);
                cout << "언어>>"; getline(cin, lan);
                cout << "ISBN>>"; getline(cin, ISBN);
                cout << "\n";
                ConversationBook *cb = new ConversationBook(index, info, prod, price, ISBN, writer, sub, lan);
                p[index] = cb;
                break;
            }
            }
            index++;
            break;
        case 2:
            for (int i = 0; i < index; i++)
                p[i]->show();
            break;
        case 3:
            return 0;
        }
    }
}
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
#include <iostream>
using namespace std;
 
class Statistics {
    int *stack;
    int index;
public:
    Statistics() { stack = new int[100]; index = 0; }
    ~Statistics() { delete[]stack; }
    Statistics& operator<<(int x);
    bool operator!();
    void operator>> (int &x);
};
 
Statistics& Statistics::operator<<(int x) {
    stack[index] = x;
    index++;
    return *this;
}
 
bool Statistics::operator!() {
    if (index == 0return true;
    else return false;
}
 
void Statistics::operator>>(int &x) {
    x = stack[index - 1];
    index--;
}
 
int main() {
    Statistics stack;
    stack << 3 << 5 << 10;
    while (true) {
        if (!stackbreak;
        int x;
        stack >> x;
        cout << x << ' ';
    }
    cout << '\n';
}
cs


+ Recent posts