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> using namespace std; class MyVector { int *mem; int size; public: MyVector(int n = 100, int val = 0) { mem = new int[n]; size = n; for (int i = 0; i < size; i++) mem[i] = val; } ~MyVector() { delete[]mem; } void show() { int count = 0; for (int i = 0; i < size; i++) { cout << mem[i] << ' '; count++; } cout << endl << "총 " << count << "번 출력됨" << endl << endl; } }; int main() { MyVector a; MyVector b(10); MyVector c(15, 10); a.show(); b.show(); c.show(); } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
| 명품 C++ Programming 실습문제 6장 6번 (0) | 2018.05.26 |
|---|---|
| 명품 C++ Programming 실습문제 6장 5번 (0) | 2018.05.10 |
| 명품 C++ Programming 실습문제 6장 3번 (0) | 2018.05.10 |
| 명품 C++ Programming 실습문제 6장 2번 (0) | 2018.05.10 |
| 명품 C++ Programming 실습문제 6장 1번 (0) | 2018.05.09 |