본문 바로가기

c++

[C++](example) class 생성/ friend/ spy 용용 #include using namespace std; class Point { double x; double y; static int countCreatedObjects; public: Point(); Point(int x, int y); void setPoint(int x, int y); int getX(void) const; int getY(void) const; static int getCreatedObject(void); Point operator+ (const Point& point); Point& operator= (const Point& point); friend ostream& operatory = y; countCreatedObjects++; } void Point::setPoint.. 더보기
[C++] class 생성/ this pointer/ 함수오버로딩/ 동적할당 #include using namespace std; //this pointer : 객체 자기자신의 주소값을 가지고있는 포인터, 자동적으로 생성 //Point pt; pt.x == this ->x class Point { private: int x; int y; public: Point():x(0),y(0){}// default 값 Point(int _x,int _y):x(_x),y(_y){} // void setXY(int _x, int _y) { // x = _x; //y = _y; // } void setXY(int _x, int _y) { this->x = _x; this->y = _y; // 시작주소값을 저장하는것 } int getX() const{ return x; } // 맴버변수를 메인에 .. 더보기
[C++] (example) private& public/ 계좌만들기/ 분자& 분모 #include #include #include using namespace std; class Point { public: double x; double y; }; int main() { Point pt1, pt2; pt1.x = 8.5; pt1.y = 0.0; pt2.x = -4; pt2.y = 2.5; cout 더보기
[C++] 계좌만들기/ private & public 계좌만들기 생성자를 활용 #include #include using namespace std; //default constructor(account(){}):아무런 생성자, 기능을 정의하지않는다 class account { private: //data string name; string id; double balance; public: //method account():name("XXX"),id("0000"),balance(0){} //생성자, return타입이없다 //initializtion list를 적극 추천한다 /* account() { name = "XXX"; id = "0000"; balance = 0; } */ account(string _name,string _id, double _bal).. 더보기
[C++] class & object/ private & public class : 설계도, 추상적인것 실제를 만들기 위한 구상도 fstream object : 객체, 내 눈앞에 나타난것 설계도를 가지고 만들어낸 실제 myfile Objectis an instance of aClass #include using namespace std; //private:리모컨의 트렌지스터,칩->class내부에서만 사용/외부에서 사용못함 //public: 리모컨의 버튼 -> class 내부, 외부 모두에서 사용가능 //setter: private 변수들의 값(내부)을 설정하는 함수 //getter: private 변수들을 외부로 반환 class point { private: //사용자의 편의성 증대, 보안의 목적 int x; int y; public: void setXY(int _x, i.. 더보기
[C++] Vector Matrix Matrix 2D vector of doubles 1) void print(const vector& m) { for (unsigned row = 0; row < m.size(); row++) { for (unsigned col = 0; col < m[row].size(); col++) cout 더보기
[C++] Array / Dynamic array/ static array array 는 list의 포인터 형태이다 int main() { int ary[3] = { 10,20,30 }; cout 더보기
[C++] (example) Vector 예시 1번 #include #include using namespace std; int main() { double sum = 0.0; const int Number_of_entries = 5; vector numbers(Number_of_entries); cout 더보기