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 | #include <iostream> #include <list> using namespace std; //포인터 구조체 struct point { int Xp; // x 좌표 int Yp; // y 좌표 point(int xp, int yp) { Xp = xp; Yp = yp; } }; void main() { //과제 1) cout << "과제 1" << endl; list< point > circle; point A(50, 200); circle.push_back(A); point B(20, 80); circle.push_back(B); point C(75, 10); circle.push_back(C); point D(130, 80); circle.push_back(D); point E(100, 200); circle.push_back(E); list< point >::iterator circleEnd = circle.end(); for (list< point >::iterator circlePos = circle.begin(); circlePos != circleEnd; ++circlePos) { cout << "점 : " << circlePos->Xp << ' ' << circlePos->Yp << endl; } //과제 2 cout << "과제 2" << endl; point F(180, 150); circle.push_back(F); for (list< point >::iterator circlePos = circle.begin(); circlePos != circleEnd; ++circlePos) { cout << "점 : " << circlePos->Xp << ' ' << circlePos->Yp << endl; } //과제 3 cout << "과제 3" << endl; for (list< point >::iterator circlePos = circle.begin(); circlePos != circleEnd; circlePos++) { if (circlePos->Xp == 130 && circlePos->Yp == 80) {//점 D가 나오면 변경 circlePos->Xp = 200; circlePos->Yp = 100; } cout << "점 : " << circlePos->Xp << ' ' << circlePos->Yp << endl; } //과제 4 cout << "과제 4" << endl; for (list< point >::iterator circlePos = circle.begin(); circlePos != circleEnd; ++circlePos) { if (circlePos->Xp == 75 && circlePos->Yp == 10) { circle.erase(circlePos); break; } } for (list< point >::iterator circlePos = circle.begin(); circlePos != circleEnd; circlePos++) { cout << "점 : " << circlePos->Xp << ' ' << circlePos->Yp << endl; } } |
'C,C++' 카테고리의 다른 글
Microsoft Visual C++ 프로그래밍 자료형 총정리 (0) | 2018.07.23 |
---|---|
[C++] STL : Standard Template Library 4 -Vector (0) | 2018.07.11 |
[C++] STL : Standard Template Library 3 - 연결 리스트 (0) | 2018.07.06 |
[C++] STL : Standard Template Library 2.2 -클래스 템플릿 (0) | 2018.07.06 |
[C++] STL : Standard Template Library 2.1 -함수 템플릿 (0) | 2018.07.06 |
댓글