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


+ Recent posts