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 |
#include <iostream>
using namespace std;
class Memory {
protected:int *M;
int count;
public:
Memory() {
M = new int[20];
count = 0;
}
virtual void push() = 0;
virtual void pop() = 0;
};
class MyStack : public Memory {
int S_pushNum;
int S_popNum;
int last = 20;//19
public:
void push() {
if (count < last) {
cout << "숫자를 입력하세요" << endl << "==>" << endl;
cin >> S_pushNum;
M[count++] = S_pushNum;
cout << count - 1 << "번째 값입니다 : " << M[count - 1] << endl;
}
else { cout << "가득찼어요" << endl; }
}
void pop() {
if (count > 0) {
cout << "뽑은 값은 " << M[--count] << endl;
}else { cout << "더이상 뺄 값이 없습니다" << endl; }
}
};
class MyQueue : public Memory {
int Q_pushNum;
int Q_popNum;
int front = 0;
public:
void push() {
if (count < 20) {
cout << "숫자를 입력하세요" << endl<<"==>"<<endl;
cin >> Q_pushNum;
M[count++] = Q_pushNum;
cout << count - 1 << "번째 값입니다 :" << M[count-1] << endl;
}
else { cout << "가득찼어요" << endl; }
}
void pop() {
if (front == count) {
cout << "더이상 뺄 값이 없습니다" << endl; }
else { cout <<"뽑은 값은"<< M[front++] << endl; }
}
};
void main() {
Memory *M = 0;
MyStack S;
MyQueue Q;
int SelNum; //스택 큐선택
int num; //푸쉬 팝선택
int i;
do {
cout << "어떤 것을 쓸래?" << endl;
cout << "1. Stack 2. Queue 3. Exit" << endl;
cin >> SelNum;
if (SelNum == 1) {
M = &S;
system("cls");
}
else if (SelNum == 2) {
M = &Q;
system("cls");
}
else if (SelNum == 3) {
exit(-1);
}
do {
cout << "1. Push 2. Pop 3. Menu" << endl;
cin >> num;
switch (num) {
case 1: M->push(); break;
case 2: M->pop(); break;
}
} while (num != 3); {system("cls"); }
} while (SelNum != 3); { exit(-1); }
} |
cs |
'C++' 카테고리의 다른 글
String 클래스 구조 (0) | 2018.03.15 |
---|---|
C++ 클래스를 이용한 성적처리(동적메모리) (0) | 2018.03.08 |
DAY1 (0) | 2018.03.06 |