포인터 관련 부분 활용 실습 반복 타이핑 개념 복습 진행
#include <iostream>
using namespace std;
//1단계: 주소 추출 (& 연산자)
void print_num_reference(int& number) {
cout << &number << endl;
};
void print_ch_reference(char& ch) {
std::cout << &ch << endl;
};
void print_ll_reference(long long& number) {
cout << &number << endl;
};
void print_double_reference(double& number) {
cout << &number << endl;
};
void print_bool_reference(bool& boolean) {
cout << &boolean << endl;
};
// 주소값 연결 (= &)
void connect_address(int num, int* ptr) {
ptr = #
}
int main() {
//1단계: 주소 추출 (& 연산자)
int num = 10;
print_num_reference(num);
double pi = 3.14;
print_double_reference(pi);
int age = 20;
print_num_reference(age);
long long big = 10000;
print_ll_reference(big);
bool check = true;
print_bool_reference(check);
//2단계: 포인터 변수 선언(*연산자)
int* ptr;
double* d_ptr;
char* ch_ptr;
bool* b_ptr;
int* number_pointer;
cout << sizeof(num) << endl; //4바이트
cout << sizeof(number_pointer) << endl; //8바이트
//3단계: 주소값 연결 (= &)
num = 10;
connect_address(num, ptr);
cout << *ptr << endl;
pi = 3.14;
double* dd_ptr;
dd_ptr = π
char ch = 'A';
char* cp;
cp = &ch;
bool flag = true;
bool* bp = &flag;
int myAge = 30;
int* pAge = &myAge;
int number = 100;
int* p;
p = &number;
long long bigData = 9999;
long long* lp = &bigData;
int target = 7;
ptr = ⌖
cout << &target << endl;
cout << ptr << endl;
//4단계: 타입 일치 (Type Matching)
int score = 100;
int* p_score;
p_score = &score;
float rate = 5.5;
// int* p_rate = &rate; 이거는 잘못된 타입 연결로 에러 발생 코드
float* p_rate = &rate;
char grade = 'A';
char* p_grade = &grade;
//double* p = # 잘못된 타입 연결로 에러 발생 코드
//5단계: 값 읽기 (Dereference, 역참조)
number = 50;
p = &number;
cout << *p << endl;
}
#include<iostream>
using namespace std;
template<typename T>
void setValue(T* value1,T value2) {
if (value1 == nullptr) {
return;
}
*value1 = value2;
}
template<typename T>
void setAddress(T* ptr, T origin) {
if (ptr == nullptr) {
return;
}
ptr = &origin;
}
void setPI(float* pi) {
if (pi == nullptr) {
return;
}
*pi = 3.14;
}
void ShowAddress(float* pi) {
cout << pi << endl;
}
int main() {
float PI;
char ch;
int* ptr = nullptr;
double* d_ptr = nullptr;
char* cp = nullptr;
bool* bp = nullptr;
bool flag = true;
setPI(&PI);
ShowAddress(&PI);
setValue(&PI, (float) 3.14);
setValue(&ch, 'A');
setValue(&flag, true);
setAddress(d_ptr,(double)PI);
setAddress(cp, ch);
setAddress(bp, flag);
return 0;
}
#include <iostream>
using namespace std;
void SetAge(int* ptr) {
if (ptr == nullptr) {
return;
}
*ptr = 20;
}
void ShowIntAddress(int* ptr) {
if (ptr == nullptr) {
return;
}
cout << ptr << endl;
}
void ShowIntValueFromAddress(int* ptr) {
if (ptr == nullptr) {
return;
}
cout << *ptr << endl;
}
template<typename T>
void ShowValueFromAddress(T* ptr) {
cout << *ptr << endl;
}
void ConnectIntToPointer(int& num, int*& ptr) { //포인터 초기화되지 않은 변수 해결 위해서 포인터 값을 대입만 처리 (int* p; p=&value; 형태)
ptr = #
}
int main() {
int age = 0;
SetAge(&age);
ShowIntAddress(&age);
ShowIntValueFromAddress(&age);
float pi = 3.14;
char ch = 'A';
ShowValueFromAddress(&pi);
ShowValueFromAddress(&ch);
int* p;
int number = 50;
ConnectIntToPointer(number, p);
cout << *p << endl;
return 0;
}
#include <iostream>
using namespace std;
void Swap(int* a, int* b) {
if (a == nullptr || b == nullptr) {
return;
}
int temp = *a;
*a = *b;
*b = temp;
}
void SwapReference(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
void SwapPtrReference(int* a, int& b) {
if (a == nullptr) {
return;
}
int temp = *a;
*a = b;
b = temp;
}
int main() {
int a = 10;
int b = 20;
int c = 30;
int d = 40;
int e = 50;
int f = 60;
Swap(&a, &b);
SwapReference(c, d);
SwapPtrReference(&e, f);
cout << a << endl; // a=20
cout << b << endl; // b=20
cout << c << endl; // c=40
cout << d << endl; // d=30
cout << e << endl; // e=60
cout << f << endl; // f=50
}
발제 설명
여러분들은 팀원분들과 텍스트 기반의 콘솔 RPG 게임을 제작합니다.
CH2 게임 개발자를 위한 C++ 문법 과정에서 익힌 내용을 바탕으로 개발합니다.
플레이
전투
승리
보스
구현
필수 기능 가이드
1. 플레이어 캐릭터 생성
2. 몬스터
3. 전투 시스템
4. 레벨업
(현재 체력 + (레벨 × 20))(현재 공격력 + (레벨 × 5))5. 아이템
6. 게임 로그 확인
도전 기능 가이드
1. 몬스터 보스전
2. 상점 시스템
오늘 팀프로젝트 진행 내용
프로젝트 진행 계획 및 프로젝트 진행 일정 중 스케줄 정리
10:00~10:30 오늘 진행 계획 공유 및 진행 사항 공유
20:30~21:00 오늘 진행 사항 공유 및 피드백 진행
12/29 - 프로젝트 진행 아이디어 발제(구현하고 싶은 기능 아이디어 공유, 어떤 기능들이 필요한지에 대해서 논의)