본문 바로가기

분류 전체보기140

문제 01-1 [C++ 기반의 데이터 입출력] 문제1#include using namespace std;int main(){ int val[5]; int sum=0; for (int i = 0; i > val[i]; sum += val[i]; } cout 문제2#include using namespace std;typedef struct information { char name[100]; char number[1000];}info;int main(){ info person1; cout > person1.name >> person1.number; cout 문제3int main(){ int num; cout > num; for (int i = 1; i 문제4int main(){ int pay; while (true) { co.. 2024. 7. 31.
임시파일 #include #include typedef struct studentTag { char name[10]; int age; double gpa;}student;typedef struct point { int xpos; int ypos;}Point;double get_distance(Point *p1, Point *p2){ return sqrt((pow(((p1->xpos) - (p2->xpos)), 2) + pow(((p1->ypos) - (p2->ypos)), 2)));}int main(){ student a = { "kim",20,4.3 }; student b = { "park",21,4.2 }; Point p1 = { 1,2 }; Point p2 = { 9,8 }; printf("%.2lf",g.. 2024. 7. 30.
순환 (하노이 탑) #include void hanoi_tower(int n, char A, char B, char C){ if (n == 1) printf("원판 1을 %c에서 %c로 옮긴다.\n", A, C); else { hanoi_tower(n - 1, A, C, B); printf("원판 %d을 %c에서 %c로 옮긴다.\n", n, A, C); hanoi_tower(n - 1, B, A, C); }}int main(){ hanoi_tower(4, 'A', 'B', 'C'); return 0;}하노이 탑 가장 위의 원판을 1부터 아래로 갈수록 커지는 것으로 생각하자.출력이 맞는지 검증해 보자.원판 1을 A에서 B로 옮긴다.원판 2을 A에서 C로 옮긴다.원판 1을 B에서 C로 옮긴다.원판 3을 A에서 B로 옮긴.. 2024. 7. 28.
생성자 (Constructor) 와 소멸자 (Destructor) 2024. 7. 26.
캡슐화 (Encapsulation) 2024. 7. 26.
정보은닉 (Information Hiding) 2024. 7. 26.