C++
C++ 프로그래밍 5주차
asd135
2023. 10. 11. 12:49
728x90
C++ 기본소스
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
구조체
#include <iostream>
struct Man
{
int age; // 멤버
double weight; // 멤버
int getAge() { return age; } // 멤버 함수
void setAge(int a) { age = a; } // 멤버 함수
};
int main()
{
Man a; // C++에서는 struct 생략가능
a.age = 1;
a.weight = 3.5;
std::cout << a.age << " " << a.weight;
}
일반구조체 포인터구조체 차이
객체지향 프로그래밍 등장 이유
구조적 프로그래밍 방식
구조적 프로그래밍 단점
객체 지향 언어 특징
구조적 프로그래밍, 객체 지향 프로그래밍 방식의 차이
클래스와 객체
클래스: 설계도
객체, 인스턴스: 설계도(클래스)로 부터 나온 것
캡슐화
상속
다형성
클래스 다이어그램 그리기
클래스
#include <iostream>
class Man
{
private: // 클래스 내부에서 접근가능
int age;
double weight;
public: // 어디에서나 접근가능
Man(int age, double weight) { // 생성자
this->age = age;
this->weight = weight;
}
void setAge(int age) { this->age = age; } // 입력, 대입
int getAge() { return this->age; } // 출력, 리턴
};
int main()
{
Man a(1,10);
std::cout << a.getAge() << std::endl;
a.setAge(5);
std::cout << a.getAge();
}
이 소스들은 한성현 교수님의 소스를 일부 편집, 수정하여 만들었습니다.