프입2-강의노트-const-friend-static

Size: px
Start display at page:

Download "프입2-강의노트-const-friend-static"

Transcription

1 Chapter 05. const, friend, static 박종혁교수 UCS Lab Tel: SeoulTech nd 프로그래밍입문 (2)

2 Chapter const 멤버변수, 함수, 객체

3 const 멤버변수 멤버변수에 const 를붙이는경우 class Car public: const int serial; string color;... Car(int s, string c) : serial(s) color = c; 이멤버변수의값을변경할수없다.

4 4 const 멤버함수 멤버함수의상수화 함수내부에서멤버변수의값을변경할수없음 이함수내에서상수화되지않은함수의호출을허용하지않음 멤버변수의포인터의리턴을허용하지않음 사용예 void ShowData() const cout<<" 이름 : "<<name<<endl; cout<<" 나이 : "<<age<<endl; cout<<" 학번 : "<<id<<endl; cout<<" 학과 : "<<major<<endl;

5 멤버함수에 const 를붙이는경우 void displayinfo() const cout << " 속도 : " << speed << endl; cout << " 기어 : " << gear << endl; cout << " 색상 : " << color << endl; 이함수안에서는멤버변수의값을변경할수없다.

6 6 const 멤버함수예 #include <iostream> using std::cout; using std::endl; class Count int cnt; public : Count() : cnt(0) int* GetPtr() const return &cnt; void Increment() cnt++; // Compile Error int main() Count count; count.increment(); count.showdata(); return 0; ; void ShowData() const ShowIntro(); // Compile Error cout<<cnt<<endl; void ShowIntro() cout<<" 현재 count의값 : "<<endl;

7 7 const 객체 const 객체 데이터의변경이허용되지않는객체 const 함수이외에는호출불가 const와함수오버로딩 const도함수오버로딩조건에포함 void function(int n) const..... void function(int n).....

8 객체에 const 를붙이는경우 int main() const Car c1(0, 1, "yellow"); c1.setspeed(); // 오류! return 0;

9 9 const 로선언된객체를대상으로는 const 로선언되지않는 멤버함수의호출이불가능함 이객체의데이터변경을허용하지않겠다!

10 10 const 와함수오버로딩 const 객체또는참조자를대상으로멤버함수 호출시 const 선언된멤버함수가호출된다! 함수의 const 선언유무는함수오버 로딩의조건이된다! 실행결과

11 11 ConstOverloading.cpp #include <iostream> using namespace std; class SoSimple private: int num; public: SoSimple(int n) : num(n) SoSimple& AddNum(int n) num+=n; return *this; void SimpleFunc () cout<<"simplefunc: "<<num<<endl; void SimpleFunc () const cout<<"const SimpleFunc: "<<num<<endl; ; void YourFunc(const SoSimple &obj) obj.simplefunc(); int main(void) SoSimple obj1(2); const SoSimple obj2(7); obj1.simplefunc(); obj2.simplefunc(); YourFunc(obj1); YourFunc(obj2); return 0;

12 12 생각해봅시다 - 어느예제가에러날까? - 왜에러가날까? 예1) #include <iostream> using std::cout; using std::endl; class AAA int num; public : AAA(int _num) : num(_num) void Add(int n) num+=n; void ShowData() cout<<num<<endl; ; int main() const AAA aaa(10); aaa.add(10); return 0; 예 2) #include <iostream> using std::cout; using std::endl; class AAA int num; public : AAA(int _num) : num(_num) void ShowData() cout<<"void ShowData() 호출 "<<endl; cout<<num<<endl; void ShowData() const cout<<"void ShowData() const 호출 "<<endl; cout<<num<<endl; ; int main() const AAA aaa1(20); AAA aaa2(70); aaa1.showdata(); aaa2.showdata(); return 0;

13 13 생각해봅시다 - 어느예제가에러날까? - 왜에러가날까? 예1) #include <iostream> using std::cout; using std::endl; class AAA int num; public : AAA(int _num) : num(_num) void Add(int n) num+=n; void ShowData() cout<<num<<endl; ; int main() const AAA aaa(10); aaa.add(10); // Compile Error aaa.showdata(); // Compile Error return 0; 예 2) #include <iostream> using std::cout; using std::endl; class AAA int num; public : AAA(int _num) : num(_num) void ShowData() cout<<"void ShowData() 호출 "<<endl; cout<<num<<endl; void ShowData() const cout<<"void ShowData() const 호출 "<<endl; cout<<num<<endl; ; int main() const AAA aaa1(20); AAA aaa2(70); aaa1.showdata(); // void ShowData() const 호출 aaa2.showdata(); // void ShowData() 호출 return 0;

14 Chapter friend 선언

15 15 친구란? 친구? 내가족의일원은아니지만내가족과동일한권한을가진일원으로인정받은사람 우리집냉장고 우리집 TV 친구 내침대 우리집식탁

16 16 C++ 프렌드 프렌드함수 클래스의멤버함수가아닌외부함수 전역함수 다른클래스의멤버함수 friend 키워드로클래스내에선언된함수 클래스의모든멤버를접근할수있는권한부여 프렌드함수라고부름 프렌드선언의필요성 클래스의멤버로선언하기에는무리가있고, 클래스의모든멤버를자유롭게접근할수있는일부외부함수작성시

17 17 프렌드로초대하는 3 가지유형 프렌드함수가되는 3 가지 전역함수 : 클래스외부에선언된전역함수 다른클래스의멤버함수 : 다른클래스의특정멤버함수 다른클래스전체 : 다른클래스의모든멤버함수

18 18 클래스의 friend 선언 Girl 클래스에대한 friend 선언! - friend 선언은 private 멤버의접근을허용 - friend 선언은정보은닉에반하는선언이기 때문에매우제한적으로선언되어야한다. Girl 이 Boy 의 friend 로선언되었 으므로, private 멤버에직접접근 가능

19 19 Friend 선언예제 #include <iostream> #include <cstring> using namespace std; class Girl; class Boy private: int height; friend class Girl; public: Boy(int len) : height(len) void ShowYourFriendInfo(Girl &frn); ; class Girl private: char phnum[20]; public: Girl(char * num) strcpy(phnum, num); void ShowYourFriendInfo(Boy &frn); friend class Boy; ; void Boy::ShowYourFriendInfo(Girl &frn) cout<<"her phone number: "<<frn.phnum<<endl; void Girl::ShowYourFriendInfo(Boy &frn) cout<<"his height: "<<frn.height<<endl; int main(void) Boy boy(170); Girl girl(" "); boy.showyourfriendinfo(girl); girl.showyourfriendinfo(boy); return 0;

20 20 함수의 friend 선언 전역변수대상의 friend 선언 이렇듯클래스의특정멤버함수를대상 으로도 friend 선언이가능하다. private 멤버접근 private 멤버접근 private 멤버접근

21 21 MyFriendFunction.cpp #include <iostream> using namespace std; class Point; class PointOP private: int opcnt; public: PointOP() : opcnt(0) ; Point PointAdd(const Point&, const Point&); Point PointSub(const Point&, const Point&); ~PointOP() cout<<"operation times: "<<opcnt<<endl; class Point private: int x; int y; public: Point(const int &xpos, const int &ypos) : x(xpos), y(ypos) friend Point PointOP::PointAdd(const Point&, const Point&); friend Point PointOP::PointSub(const Point&, const Point&); friend void ShowPointPos(const Point&); ; Point PointOP::PointAdd(const Point& pnt1, const Point& pnt2) opcnt++; return Point(pnt1.x+pnt2.x, pnt1.y+pnt2.y); Point PointOP::PointSub(const Point& pnt1, const Point& pnt2) opcnt++; return Point(pnt1.x-pnt2.x, pnt1.y-pnt2.y); int main(void) Point pos1(1, 2); Point pos2(2, 4); PointOP op; ShowPointPos(op.PointAdd(pos1, pos2)); ShowPointPos(op.PointSub(pos2, pos1)); return 0; void ShowPointPos(const Point& pos) cout<<"x: "<<pos.x<<", "; cout<<"y: "<<pos.y<<endl;

22 Chapter static

23 23 정적멤버 (static member) 정적멤버 같은클래스형으로선언된여러객체들이동일한하나의자료를공유 클래스의정의시멤버를 static이란키워드로정의 클래스내에선언된정적멤버는정적멤버가선언된클래스로사용영역이제한된전역변수 (global variable) 클래스내에서정적멤버를선언할때정적멤버자체가정의되는것은아니기때문에클래스밖에서정적멤버를정의하는선언필요 모든정적멤버변수는특별히초기값을명시하지않는한 0으로초기화

24 24 정적멤버 (static member) Static 멤버의등장 전역변수와전역함수를일부대처하기위해등장 Static 키워드의효과 모든객체가공유할수있는멤버

25 25 정적멤버 (static member) static 멤버의특징 클래스변수, 클래스함수라한다. main 함수호출이전에메모리공간에올라가서초기화 ( 전역변수와동일 ) 선언된클래스의객체내에직접접근허용 static 멤버초기화문으로초기화해야함

26 26 static 멤버와 non-static 멤버의특성 static 변수와함수에대한기억부류의한종류 생명주기 프로그램이시작될때생성, 프로그램종료시소멸 사용범위 선언된범위, 접근지정에따름 클래스의멤버 static 멤버 프로그램이시작할때생성 클래스당하나만생성, 클래스멤버라고불림 클래스의모든인스턴스 ( 객체 ) 들이공유하는멤버 non-static 멤버 객체가생성될때함께생성 객체마다객체내에생성 인스턴스멤버라고불림

27 27 전역변수가필요한상황 객체지향이기때문에전역변수를사용할것을권하지않음 #include <iostream> using namespace std; int simobjcnt=0; int cmxobjcnt=0; class SoSimple public: SoSimple() simobjcnt++; cout<<simobjcnt<<" 번째 SoSimple 객체 "<<endl; ; class SoComplex public: SoComplex() cmxobjcnt++; cout<<cmxobjcnt<<" 번째 SoComplex 객체 "<<endl; ; SoComplex(SoComplex &copy) cmxobjcnt++; cout<<cmxobjcnt<<" 번째 SoComplex 객체 "<<endl; int main(void) SoSimple sim1; SoSimple sim2; SoComplex com1; SoComplex com2=com1; SoComplex(); return 0;

28 28 static 멤버변수 ( 클래스변수 ) static 변수는객체별로존재하는변수가아닌, 프로그램전 체영역에서하나만존재하는변수이다. 프로그램실행과동시에초기화되어메모리공간에할당된다.

29 29 StaticMember.cpp #include <iostream> using namespace std; class SoSimple private: static int simobjcnt; public: SoSimple() simobjcnt++; cout<<simobjcnt<<" 번째 SoSimple 객체 "<<endl; ; int SoSimple::simObjCnt=0; class SoComplex private: static int cmxobjcnt; public: SoComplex() cmxobjcnt++; cout<<cmxobjcnt<<" 번째 SoComplex 객체 "<<endl; SoComplex(SoComplex &copy) cmxobjcnt++; cout<<cmxobjcnt<<" 번째 SoComplex 객체 "<<endl; ; int SoComplex::cmxObjCnt=0; int main(void) SoSimple sim1; SoSimple sim2; SoComplex cmx1; SoComplex cmx2=cmx1; SoComplex(); return 0;

30 30 C 언어에서이야기한 static 실행결과

31 31 static 멤버사용 : 객체의멤버로접근 static 멤버는객체이름이나객체포인터로접근 보통멤버처럼접근할수있음 객체.static 멤버객체포인터 ->static 멤버 Person 타입의객체 lee 와포인터 p 를이용하여 static 멤버를접근하는예 Person lee; lee.sharedmoney = 500; // 객체.static 멤버방식 Person *p; p = &lee; p->addshared(200); // 객체포인터 ->static 멤버방식

32 #include <iostream> using namespace std; class Person public: double money; // 개인소유의돈 void addmoney(int money) this->money += money; ; static int sharedmoney; // 공금 static void addshared(int n) sharedmoney += n; // static 변수생성. 전역공간에생성 int Person::sharedMoney=10; // 10 으로초기화 - 출력결과는? - 각변수값들이어떻게변경될까생각해봅시다. 32 // main() 함수 int main() Person han; han.money = 100; // han 의개인돈 =100 han.sharedmoney = 200; // static 멤버접근, 공금 =200 Person lee; lee.money = 150; // lee 의개인돈 =150 lee.addmoney(200); // lee 의개인돈 =350 lee.addshared(200); // static 멤버접근, 공금 =400 cout << han.money << ' ' << lee.money << endl; cout << han.sharedmoney << ' ' << lee.sharedmoney << endl;

33 #include <iostream> using namespace std; 33 class Person public: double money; // 개인소유의돈 void addmoney(int money) this->money += money; ; static int sharedmoney; // 공금 static void addshared(int n) sharedmoney += n; // static 변수생성. 전역공간에생성 int Person::sharedMoney=10; // 10 으로초기화 // main() 함수 int main() Person han; han.money = 100; // han 의개인돈 =100 han.sharedmoney = 200; // static 멤버접근, 공금 =200 Person lee; lee.money = 150; // lee 의개인돈 =150 lee.addmoney(200); // lee 의개인돈 =350 lee.addshared(200); // static 멤버접근, 공금 =400 cout << han.money << ' ' << lee.money << endl; cout << han.sharedmoney << ' ' << lee.sharedmoney << endl; han 과 lee 의 money 는각각 100, 350 han 과 lee 의 sharedmoney 는공통 400

34 #include <iostream> using namespace std; class Person public: double money; // 개인소유의돈 void addmoney(int money) this->money += money; main() 이시작하기직전 sharedmoney 10 addshared()... sharedmoney addshared() ; static int sharedmoney; // 공금 static void addshared(int n) sharedmoney += n; Person han; han.money = 100; han.sharedmoney = 200; han money 100 addmoney()... // static 변수생성. 전역공간에생성 int Person::sharedMoney=10; // 10 으로초기화 // main() 함수 int main() Person han; han.money = 100; // han 의개인돈 =100 han.sharedmoney = 200; // static 멤버접근, 공금 =200 Person lee; lee.money = 150; // lee 의개인돈 =150 lee.addmoney(200); // lee 의개인돈 =350 lee.addshared(200); // static 멤버접근, 공금 =400 cout << han.money << ' ' << lee.money << endl; cout << han.sharedmoney << ' ' << lee.sharedmoney << endl; han 과 lee 의 money 는각각 100, 350 Person lee; lee.money = 150; lee.addmoney(200); lee.addshared(200); sharedmoney 200 addshared()... han lee money 100 money addmoney()... addmoney()... sharedmoney addshared()... han lee money 100 money 350 han 과 lee 의 sharedmoney 는공통 400 addmoney()... addmoney()...

35 static 멤버사용 : 클래스명과범위지정연산자 (::) 로접근 35 클래스이름과범위지정연산자 (::) 로접근가능 static 멤버는클래스마다오직한개만생성되기때문 클래스명 ::static 멤버 han.sharedmoney = 200; <-> Person::sharedMoney = 200; lee.addshared(200); <-> Person::addShared(200); non-static 멤버는클래스이름을접근불가 Person::money = 100; // 컴파일오류. non-static 멤버는클래스명으로접근불가 Person::addMoney(200); // 컴파일오류. non-static 멤버는클래스명으로접근불가

36 #include <iostream> using namespace std; class Person public: double money; // 개인소유의돈 void addmoney(int money) this->money += money; ; static int sharedmoney; // 공금 static void addshared(int n) sharedmoney += n; // static 변수생성. 전역공간에생성 int Person::sharedMoney=10; // 10 으로초기화 - 출력결과는? - 각변수값들이어떻게변경될까생각해봅시다. // main() 함수 int main() Person::addShared(50); // static 멤버접근, 공금 =60 cout << Person::sharedMoney << endl; Person han; han.money = 100; han.sharedmoney = 200; // static 멤버접근, 공금 =200 Person::sharedMoney = 300; // static 멤버접근, 공금 =300 Person::addShared(100); // static 멤버접근, 공금 =400 cout << han.money << ' ' << Person::sharedMoney << endl;

37 #include <iostream> using namespace std; class Person public: double money; // 개인소유의돈 void addmoney(int money) this->money += money; ; static int sharedmoney; // 공금 static void addshared(int n) sharedmoney += n; // static 변수생성. 전역공간에생성 int Person::sharedMoney=10; // 10 으로초기화 han 객체가생기기전부터 // main() 함수 static 멤버접근 int main() Person::addShared(50); // static 멤버접근, 공금 =60 cout << Person::sharedMoney << endl; Person han; han.money = 100; han.sharedmoney = 200; // static 멤버접근, 공금 =200 Person::sharedMoney = 300; // static 멤버접근, 공금 =300 Person::addShared(100); // static 멤버접근, 공금 =400 cout << han.money << ' ' << Person::sharedMoney << endl; sharedmoney 400 han 의 money

38 #include <iostream> using namespace std; main() 이시작하기직전 sharedmoney 10 addshared()... class Person public: double money; // 개인소유의돈 void addmoney(int money) this->money += money; Person::addShared(50); sharedmoney 10 addshared() ; static int sharedmoney; // 공금 static void addshared(int n) sharedmoney += n; // static 변수생성. 전역공간에생성 int Person::sharedMoney=10; // 10 으로초기화 han 객체가생기기전부터 // main() 함수 static 멤버접근 int main() Person::addShared(50); // static 멤버접근, 공금 =60 cout << Person::sharedMoney << endl; Person han; han.money = 100; han.sharedmoney = 200; // static 멤버접근, 공금 =200 Person::sharedMoney = 300; // static 멤버접근, 공금 =300 Person::addShared(100); // static 멤버접근, 공금 =400 Person han; han.money = 100; han.sharedmoney = 200; han han sharedmoney 60 addshared()... money addmoney()... sharedmoney 200 addshared()... money 100 addmoney()... cout << han.money << ' ' << Person::sharedMoney << endl; han 의 money 100 sharedmoney 400 Person::sharedMoney = 300; Person::addShared(100); han sharedmoney 200 addshared()... money addmoney()...

39 참고문헌 뇌를자극하는 C++ 프로그래밍, 이현창, 한빛미디어, 2011 열혈 C++ 프로그래밍 ( 개정판 ), 윤성우, 오렌지미디어, 2012 C++ ESPRESSO, 천인국저, 인피니티북스, 2011 명품 C++ Programming, 황기태, 생능출판사,

40 Q & A

41 추가자료

42 42 C 의 const const double PI=3.14; PI=3.1415; // 컴파일오류 const int val; val=20; // 컴파일오류

43 43 C 의 const int n=10; const int* pn=&n; *pn=20; // 컴파일오류 int n1=10; int n2=20; int* const pn=&n1; *pn=20; pn=&n2; // 컴파일오류

44 44 멤버변수의상수화 #include<iostream> using std::cout; using std::endl; class Student const int id; int age; char name[20]; char major[30]; public: Student(int _id, int _age, char* _name, char* _major) id=_id; //error age=_age; strcpy(name, _name); strcpy(major, _major); ; void ShowData() cout<<" 이름 : "<<name<<endl; cout<<" 나이 : "<<age<<endl; cout<<" 학번 : "<<id<<endl; cout<<" 학과 : "<<major<<endl; int main() Student Kim( , 20, "Kim Gil Dong", "Computer Eng."); Student Hong( , 19, "Hong Gil Dong", "Electronics Eng."); Kim.ShowData(); cout<<endl; Hong.ShowData(); return 0; 컴파일에러 상수값을생성자에서초기화하여발생 Member initializer 사용 Const 멤버변수초기화

45 45 멤버변수의상수화 #include<iostream> using std::cout; using std::endl; class Student const int id; int age; char name[20]; char major[30]; public: Student(int _id, int _age, char* _name, char* _major) : id(_id), age(_age) strcpy(name, _name); strcpy(major, _major); void ShowData() cout<<" 이름 : "<<name<<endl; cout<<" 나이 : "<<age<<endl; cout<<" 학번 : "<<id<<endl; cout<<" 학과 : "<<major<<endl; ; int main() Initializer 는 Student Kim( , 20, "Kim Gil Dong", "Computer Eng."); Student Hong( , 19, "Hong Gil Dong", "Electronics Eng."); Kim.ShowData(); cout<<endl; Hong.ShowData(); return 0; 생성자함수호출전에초기화됨.

46 46 const 멤버함수예 #include <iostream> using std::cout; using std::endl; class Count int cnt; public : Count() : cnt(0) const int* GetPtr() const return &cnt; void Increment() cnt++; ; void ShowData() const ShowIntro(); cout<<cnt<<endl; void ShowIntro() const cout<<" 현재 count 의값 : "<<endl; int main() Count count; count.increment(); count.increment(); count.showdata(); return 0;

47 47 static 멤버변수의접근방법 접근 case 2 접근 case 1 접근 case 3 static 변수가선언된외부에서의접근이가능하려면, 해당변수가 public 으로선언되어야한다. 실행결과

48 48 PublicStaticMember #include <iostream> using namespace std; class SoSimple public: static int simobjcnt; public: SoSimple() simobjcnt++; ; int SoSimple::simObjCnt=0; int main(void) cout<<sosimple::simobjcnt<<" 번째 SoSimple 객체 "<<endl; SoSimple sim1; SoSimple sim2; cout<<sosimple::simobjcnt<<" 번째 SoSimple 객체 "<<endl; cout<<sim1.simobjcnt<<" 번째 SoSimple 객체 "<<endl; cout<<sim2.simobjcnt<<" 번째 SoSimple 객체 "<<endl; return 0;

49 49 static 멤버함수 static 멤버변수의특징과일치한다. static 함수는객체내에존재하는함수가아니기때문에멤버변수나멤버함수에접근이불가능하다. static 함수는 static 변수에만접근가능하고, static 함수만호출가능하다.

50 50 const static 멤버와 mutable const static 멤버변수는, 클래스가정의될때지정된값이유지되는상수이기때문에, 위예제에서보이는바와같이초기화가가능하도록문법으로정의하고있다. mutable 로선언된멤버변수는 const 함수내에 서값의변경이가능하다.

51 51 ConstStaticMember.cpp #include <iostream> using namespace std; class CountryArea public: const static int RUSSIA = ; const static int CANADA =998467; const static int CHINA =957290; const static int SOUTH_KOREA =9922; ; int main(void) cout<<" 러시아면적 : "<<CountryArea::RUSSIA<<" km2 "<<endl; cout<<" 캐나다면적 : "<<CountryArea::CANADA<<" km2 "<<endl; cout<<" 중국면적 : "<<CountryArea::CHINA<<" km2 "<<endl; cout<<" 한국면적 : "<<CountryArea::SOUTH_KOREA<<" km2 "<<endl; return 0;

52 52 Mutable.cpp #include <iostream> using namespace std; class SoSimple private: int num1; mutable int num2; public: SoSimple(int n1, int n2) : num1(n1), num2(n2) void ShowSimpleData() const cout<<num1<<", "<<num2<<endl; void CopyToNum2() const num2=num1; ; int main(void) SoSimple sm(1, 2); sm.showsimpledata(); sm.copytonum2(); sm.showsimpledata(); return 0;

53 53 explicit & mutable explicit 명시적호출만허용한다. mutable const 에예외를둔다

54 54 explicit & mutable /* explicit.cpp */ #include<iostream> using std::cout; using std::endl; class AAA public: explicit AAA(int n) cout<<"explicit AAA(int n)"<<endl; ; 컴파일에러발생!! - Explicit 로선언되어, main 함수에서 AAA(10) 으로수정되어야함 int main(void) AAA a1=10; return 0;

55 55 explicit & mutable /* mutable.cpp */ #include<iostream> using std::cout; using std::endl; class AAA private: mutable int val1; int val2; public: void SetData(int a, int b) const val1=a; // val1이 mutable이므로 OK! val2=b; // Error! ; int main(void) AAA a1; a1.setdata(10, 20); return 0;

Microsoft PowerPoint - Chapter 6.ppt

Microsoft PowerPoint - Chapter 6.ppt 6.Static 멤버와 const 멤버 클래스와 const 클래스와 static 연결리스트프로그램예 Jong Hyuk Park 클래스와 const Jong Hyuk Park C 의 const (1) const double PI=3.14; PI=3.1415; // 컴파일오류 const int val; val=20; // 컴파일오류 3 C 의 const (1)

More information

Microsoft PowerPoint - additional06.ppt [호환 모드]

Microsoft PowerPoint - additional06.ppt [호환 모드] 보조자료 6.Static 멤버와 const 멤버 클래스와 const 클래스와 static 연결리스트프로그램예 Jong Hyuk Park 클래스와 const Jong Hyuk Park 복습 : Const 키워드왜사용? C 의 const (1) const double PI=3.14; PI=3.1415; // 컴파일오류 const int val; val=20; //

More information

Microsoft PowerPoint - additional07.ppt [호환 모드]

Microsoft PowerPoint - additional07.ppt [호환 모드] 보충자료 7. 상속 (inheritance) 의이해 상속의기본개념 상속의생성자, 소멸자 protected 멤버 Jong Hyuk Park 상속의기본개념 Jong Hyuk Park 상속의기본개념 상속의예 1 " 철수는아버지로부터좋은목소리와큰키를물려 받았다." 상속의예 2 "Student 클래스가 Person 클래스를상속한다." 아버지 Person 철수 Stduent

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 9 강. 클래스의활용목차 멤버함수의외부정의 this 포인터 friend 선언 static 멤버 임시객체 1 /17 9 강. 클래스의활용멤버함수의외부정의 멤버함수정의구현방법 내부정의 : 클래스선언내에함수정의구현 외부정의 클래스선언 : 함수프로토타입 멤버함수정의 : 클래스선언외부에구현

More information

PowerPoint Template

PowerPoint Template 7. 상속 (inheritance) 의이해 상속의기본개념 상속의생성자, 소멸자 protected 멤버 Jong Hyuk Park 상속의기본개념 Jong Hyuk Park 상속의기본개념 상속의예 1 " 철수는아버지로부터좋은목소리와큰키를물려받았다." 상속의예 2 "Student 클래스가 Person 클래스를상속한다." 아버지 Person 철수 Stduent 3

More information

C++ Programming

C++ Programming C++ Programming 상속과다형성 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 상속의이해 상속과다형성 다중상속 2 상속과다형성 객체의이해 상속클래스의객체의생성및소멸 상속의조건 상속과다형성 다중상속 3 상속의이해 상속 (Inheritance) 클래스에구현된모든특성 ( 멤버변수와멤버함수 )

More information

슬라이드 1

슬라이드 1 정적메모리할당 (Static memory allocation) 일반적으로프로그램의실행에필요한메모리 ( 변수, 배열, 객체등 ) 는컴파일과정에서결정되고, 실행파일이메모리에로드될때할당되며, 종료후에반환됨 동적메모리할당 (Dynamic memory allocation) 프로그램의실행중에필요한메모리를할당받아사용하고, 사용이끝나면반환함 - 메모리를프로그램이직접관리해야함

More information

C++ Programming

C++ Programming C++ Programming 클래스와데이터추상화 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 객체지향프로그래밍 클래스와객체 2 객체지향프로그래밍 객체지향언어 (Object-Oriented Language) 프로그램을명령어의목록으로보는시각에서벗어나여러개의 독립된단위, 즉 객체 (Object) 들의모임으로파악

More information

C++ Programming

C++ Programming C++ Programming 연산자다중정의 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 연산자다중정의 C++ 스타일의문자열 2 연산자다중정의 연산자다중정의 단항연산자다중정의 이항연산자다중정의 cin, cout 그리고 endl C++ 스타일의문자열 3 연산자다중정의 연산자다중정의 (Operator

More information

PowerPoint Presentation

PowerPoint Presentation Class - Property Jo, Heeseung 목차 section 1 클래스의일반구조 section 2 클래스선언 section 3 객체의생성 section 4 멤버변수 4-1 객체변수 4-2 클래스변수 4-3 종단 (final) 변수 4-4 멤버변수접근방법 section 5 멤버변수접근한정자 5-1 public 5-2 private 5-3 한정자없음

More information

Microsoft PowerPoint - additional01.ppt [호환 모드]

Microsoft PowerPoint - additional01.ppt [호환 모드] 1.C 기반의 C++ part 1 함수 오버로딩 (overloading) 디폴트매개변수 (default parameter) 인-라인함수 (in-line function) 이름공간 (namespace) Jong Hyuk Park 함수 Jong Hyuk Park 함수오버로딩 (overloading) 함수오버로딩 (function overloading) C++ 언어에서는같은이름을가진여러개의함수를정의가능

More information

Microsoft PowerPoint - additional08.ppt [호환 모드]

Microsoft PowerPoint - additional08.ppt [호환 모드] 8. 상속과다형성 (polymorphism) 상속된객체와포인터 / 참조자의관계 정적바인딩과동적바인딩 virtual 소멸자 Jong Hyuk Park 상속의조건 public 상속은 is-a 관계가성립되도록하자. 일반화 ParttimeStd 구체화 2 상속의조건 잘못된상속의예 현실세계와완전히동떨어진모델이형성됨 3 상속의조건 HAS-A( 소유 ) 관계에의한상속!

More information

Microsoft PowerPoint - C++ 5 .pptx

Microsoft PowerPoint - C++ 5 .pptx C++ 언어프로그래밍 한밭대학교전자. 제어공학과이승호교수 연산자중복 (operator overloading) 이란? 2 1. 연산자중복이란? 1) 기존에미리정의되어있는연산자 (+, -, /, * 등 ) 들을프로그래머의의도에맞도록새롭게정의하여사용할수있도록지원하는기능 2) 연산자를특정한기능을수행하도록재정의하여사용하면여러가지이점을가질수있음 3) 하나의기능이프로그래머의의도에따라바뀌어동작하는다형성

More information

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a 6 장복사생성자 객체의생성과대입객체의값에의한전달복사생성자디폴트복사생성자복사생성자의재정의객체의값에의한반환임시객체 C++ 프로그래밍입문 1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y;

More information

C++ Programming

C++ Programming C++ Programming 예외처리 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 예외처리 2 예외처리 예외처리 C++ 의예외처리 예외클래스와객체 3 예외처리 예외를처리하지않는프로그램 int main() int a, b; cout > a >> b; cout

More information

1. 클래스와배열 int 형배열선언및초기화 int ary[5] = 1, 2, 3, 4, 5 ; for (int i = 0; i < 5; i++) cout << "ary[" << i << "] = " << ary[i] << endl; 5 장클래스의활용 1

1. 클래스와배열 int 형배열선언및초기화 int ary[5] = 1, 2, 3, 4, 5 ; for (int i = 0; i < 5; i++) cout << ary[ << i << ] =  << ary[i] << endl; 5 장클래스의활용 1 5 장클래스의활용 클래스와배열객체포인터 this 포인터멤버함수오버로딩디폴트매개변수의사용 friend ( 전역함수, 클래스, 멤버함수 ) 내포클래스지역클래스 static 멤버 const 멤버와 const 객체 explicit 생성자 C++ 프로그래밍입문 1. 클래스와배열 int 형배열선언및초기화 int ary[5] = 1, 2, 3, 4, 5 ; for (int

More information

Microsoft PowerPoint - chap06-2pointer.ppt

Microsoft PowerPoint - chap06-2pointer.ppt 2010-1 학기프로그래밍입문 (1) chapter 06-2 참고자료 포인터 박종혁 Tel: 970-6702 Email: jhpark1@snut.ac.kr 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- 포인터의정의와사용 변수를선언하는것은메모리에기억공간을할당하는것이며할당된이후에는변수명으로그기억공간을사용한다. 할당된기억공간을사용하는방법에는변수명외에메모리의실제주소값을사용하는것이다.

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 5 장생성자와접근제어 1. 객체지향기법을이해한다. 2. 클래스를작성할수있다. 3. 클래스에서객체를생성할수있다. 4. 생성자를이용하여객체를초기화할수 있다. 5. 접근자와설정자를사용할수있다. 이번장에서만들어볼프로그램 생성자 생성자 (constructor) 는초기화를담당하는함수 생성자가필요한이유 #include using namespace

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 11 장상속 1. 상속의개념을이해한다. 2. 상속을이용하여자식클래스를작성할수있다. 3. 상속과접근지정자와의관계를이해한다. 4. 상속시생성자와소멸자가호출되는순서를이해한다. 이번장에서만들어볼프로그램 class Circle { int x, y; int radius;... class Rect { int x, y; int width, height;... 중복 상속의개요

More information

4 장클래스와객체 클래스와객체 public과 private 구조체와클래스객체의생성과생성자객체의소멸과소멸자생성자와소멸자의호출순서디폴트생성자와디폴트소멸자멤버초기화멤버함수의외부정의멤버함수의인라인함수선언 C++ 프로그래밍입문

4 장클래스와객체 클래스와객체 public과 private 구조체와클래스객체의생성과생성자객체의소멸과소멸자생성자와소멸자의호출순서디폴트생성자와디폴트소멸자멤버초기화멤버함수의외부정의멤버함수의인라인함수선언 C++ 프로그래밍입문 4 장클래스와객체 클래스와객체 public과 private 구조체와클래스객체의생성과생성자객체의소멸과소멸자생성자와소멸자의호출순서디폴트생성자와디폴트소멸자멤버초기화멤버함수의외부정의멤버함수의인라인함수선언 C++ 프로그래밍입문 1. 클래스와객체 추상데이터형 : 속성 (attribute) + 메서드 (method) 예 : 자동차의속성과메서드 C++ : 주로 class

More information

Microsoft PowerPoint - additional03.ppt [호환 모드]

Microsoft PowerPoint - additional03.ppt [호환 모드] 3. 클래스의기본 객체지향프로그래밍소개 구조체와클래스 클래스의정의 Jong Hyuk Park 객체지향프로그래밍소개 Jong Hyuk Park 구조적프로그래밍개념 기존 C와같은구조적프로그래밍언어는동작되는자료와처리동작자체를서로별도로구분 처리동작과자료사이의관계가서로밀접한연관성을갖지못함 프로그램이커지거나복잡해지면프로그램이혼란스럽게되어에러를찾는디버깅및프로그램의유지보수가어려워짐

More information

윤성우의 열혈 TCP/IP 소켓 프로그래밍

윤성우의 열혈 TCP/IP 소켓 프로그래밍 Chapter 06. 상속의이해 박종혁교수 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr SeoulTech 2017-2 nd 프로그래밍입문 (2) 06-1. 상속의기본개념 상속의기본개념 상속 (inheritance) 한클래스가다른클래스에서정의된속성 ( 자료, 함수 ) 를이어받아그대로사용 이미정의된클래스를바탕으로필요한기능을추가하여정의

More information

윤성우의 열혈 TCP/IP 소켓 프로그래밍

윤성우의 열혈 TCP/IP 소켓 프로그래밍 상속의이해 박종혁교수 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr SeoulTech 프로그래밍입문 3 상속의기본개념 상속의예1 " 철수는아버지로부터좋은목소리와큰키를물려받았다." 상속의예2 "Student 클래스가 Person 클래스를상속한다." 아버지 Person 철수 Stduent 4 파생클래스 (derived

More information

윤성우의 열혈 TCP/IP 소켓 프로그래밍

윤성우의 열혈 TCP/IP 소켓 프로그래밍 Chapter 06. 상속의이해 박종혁교수 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr SeoulTech 2016-2 nd 프로그래밍입문 (2) Chapter 06-1. 상속에들어가기에앞서 3 상속의기본개념 상속의예1 " 철수는아버지로부터좋은목소리와큰키를물려받았다." 상속의예2 "Student 클래스가 Person

More information

PowerPoint Presentation

PowerPoint Presentation public class SumTest { public static void main(string a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // 두수를더하는부분입니다 System.out.println(" 두수의합은 " + sum +

More information

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074>

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074> 객체지향프로그램밍 (Object-Oriented Programming) 1 C++ popular C 객체지향 (object oriented) C++ C : 상위계층언어특징 + 어셈블리언어특징 C++ : 소프트웨어개발플랫폼에객체지향개념제공 객체지향 : 자료와이들자료를어떻게다룰것인지따로생각하지않고단지하나의사물로생각 형 변수가사용하는메모리크기 변수가가질수있는정보

More information

1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout << " 양수입력 : "; cin >> *p; if (*p <= 0) cout << " 양수를입력해야합니다 " << endl; return; 동적할

1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout <<  양수입력 : ; cin >> *p; if (*p <= 0) cout <<  양수를입력해야합니다  << endl; return; 동적할 15 장기타주제들 auto_ptr 변환함수 cast 연산자에의한명시적형변환실행시간타입정보알아내기 (RTTI) C++ 프로그래밍입문 1. auto_ptr 다음프로그램의문제점은무엇인가? void func(void) int *p = new int; cout > *p; if (*p

More information

윤성우의 열혈 TCP/IP 소켓 프로그래밍

윤성우의 열혈 TCP/IP 소켓 프로그래밍 Chapter 08. 상속과다형성 박종혁교수 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr SeoulTech 2013-2 nd 프로그래밍입문 (2) Chapter 08-1. 객체포인터의참조관계 3 상속된객체와포인터관계 객체포인터 객체의주소값을저장할수있는포인터 AAA 클래스의포인터는 AAA 객체의주소뿐만아니라 AAA

More information

금오공대 컴퓨터공학전공 강의자료

금오공대 컴퓨터공학전공 강의자료 C 프로그래밍프로젝트 Chap 14. 포인터와함수에대한이해 2013.10.09. 오병우 컴퓨터공학과 14-1 함수의인자로배열전달 기본적인인자의전달방식 값의복사에의한전달 val 10 a 10 11 Department of Computer Engineering 2 14-1 함수의인자로배열전달 배열의함수인자전달방식 배열이름 ( 배열주소, 포인터 ) 에의한전달 #include

More information

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2 객체지향프로그래밍 IT CookBook, 자바로배우는쉬운자료구조 q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2 q 객체지향프로그래밍의이해 v 프로그래밍기법의발달 A 군의사업발전 1 단계 구조적프로그래밍방식 3 q 객체지향프로그래밍의이해 A 군의사업발전 2 단계 객체지향프로그래밍방식 4 q 객체지향프로그래밍의이해 v 객체란무엇인가

More information

윤성우의 열혈 TCP/IP 소켓 프로그래밍

윤성우의 열혈 TCP/IP 소켓 프로그래밍 예외처리 (Exception Handling) 박종혁교수 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr SeoulTech 2012-2 nd 프로그래밍입문 (1) 예외상황과예외처리의이해 3 예외상황을처리하지않았을때의결과 예외상황은프로그램실행중에발생하는문제의상황을의미한다. 예외상황의예나이를입력하라고했는데, 0보다작은값이입력됨.

More information

Microsoft PowerPoint - [2009] 02.pptx

Microsoft PowerPoint - [2009] 02.pptx 원시데이터유형과연산 원시데이터유형과연산 원시데이터유형과연산 숫자데이터유형 - 숫자데이터유형 원시데이터유형과연산 표준입출력함수 - printf 문 가장기본적인출력함수. (stdio.h) 문법 ) printf( Test printf. a = %d \n, a); printf( %d, %f, %c \n, a, b, c); #include #include

More information

PowerPoint Template

PowerPoint Template 16-1. 보조자료템플릿 (Template) 함수템플릿 클래스템플릿 Jong Hyuk Park 함수템플릿 Jong Hyuk Park 함수템플릿소개 함수템플릿 한번의함수정의로서로다른자료형에대해적용하는함수 예 int abs(int n) return n < 0? -n : n; double abs(double n) 함수 return n < 0? -n : n; //

More information

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Function) 1. 함수의개념 입력에대해적절한출력을발생시켜주는것 내가 ( 프로그래머 ) 작성한명령문을연산, 처리, 실행해주는부분 ( 모듈 ) 자체적으로실행되지않으며,

More information

PowerPoint Template

PowerPoint Template 1.C 기반의 C++ 스트림입출력 함수 오버로딩 (overloading) 디폴트매개변수 (default parameter) 인-라인함수 (in-line function) 이름공간 (namespace) Jong Hyuk Park 스트림입출력 Jong Hyuk Park printf 와 scanf 출력의기본형태 iostream 헤더파일의포함 HelloWorld2.cpp

More information

Microsoft PowerPoint - Chapter 1-rev

Microsoft PowerPoint - Chapter 1-rev 1.C 기반의 C++ part 1 스트림입출력 함수 오버로딩 (overloading) 디폴트매개변수 (default parameter) 인-라인함수 (in-line function) 이름공간 (namespace) Jong Hyuk Park 스트림입출력 Jong Hyuk Park printf 와 scanf 출력의기본형태 : 과거스타일! iostream.h 헤더파일의포함

More information

(Microsoft PowerPoint - 07\300\345.ppt [\310\243\310\257 \270\360\265\345])

(Microsoft PowerPoint - 07\300\345.ppt [\310\243\310\257 \270\360\265\345]) 클래스의응용 클래스를자유자재로사용하자. 이장에서다룰내용 1 객체의치환 2 함수와클래스의상관관계 01_ 객체의치환 객체도변수와마찬가지로치환이가능하다. 기본예제 [7-1] 객체도일반변수와마찬가지로대입이가능하다. 기본예제 [7-2] 객체의치환시에는조심해야할점이있다. 복사생성자의필요성에대하여알아보자. [ 기본예제 7-1] 클래스의치환 01 #include

More information

JAVA PROGRAMMING 실습 05. 객체의 활용

JAVA PROGRAMMING 실습 05. 객체의 활용 public class Person{ public String name; public int age; } public Person(){ } public Person(String s, int a){ name = s; age = a; } public String getname(){ return name; } @ 객체의선언 public static void main(string

More information

윤성우의 열혈 TCP/IP 소켓 프로그래밍

윤성우의 열혈 TCP/IP 소켓 프로그래밍 C 프로그래밍프로젝트 Chap 22. 구조체와사용자정의자료형 1 2013.10.10. 오병우 컴퓨터공학과 구조체의정의 (Structure) 구조체 하나이상의기본자료형을기반으로사용자정의자료형 (User Defined Data Type) 을만들수있는문법요소 배열 vs. 구조체 배열 : 한가지자료형의집합 구조체 : 여러가지자료형의집합 사용자정의자료형 struct

More information

Slide 1

Slide 1 SeoulTech 2011-2 nd 프로그래밍입문 (2) Chapter 6. 구조체와클래스 박종혁교수 (http://www.parkjonghyuk.net) Tel: 970-6702 Email: jhpark1@snut.ac.kr Learning Objectives 구조체 구조체형 함수매개변수로서의구조체 구조체초기화 클래스 정의, 멤버함수 public 과 private

More information

Microsoft PowerPoint - 8ÀÏ°_Æ÷ÀÎÅÍ.ppt

Microsoft PowerPoint - 8ÀÏ°_Æ÷ÀÎÅÍ.ppt 포인터 1 포인터란? 포인터 메모리의주소를가지고있는변수 메모리주소 100번지 101번지 102번지 103번지 int theage (4 byte) 변수의크기에따라 주로 byte 단위 주소연산자 : & 변수의주소를반환 메모리 2 #include list 8.1 int main() using namespace std; unsigned short

More information

Microsoft PowerPoint - Chap12-OOP.ppt

Microsoft PowerPoint - Chap12-OOP.ppt 객체지향프로그래밍 (Object Oriented Programming) 12 장강사 강대기 차례 (Agenda) 멤버에대한동적메모리할당 암시적 / 명시적복사생성자 암시적 / 명시적오버로딩대입연산자 생성자에 new 사용하기 static 클래스멤버 객체에위치지정 new 사용하기 객체를지시하는포인터 StringBad 클래스 멤버에포인터사용 str static 멤버

More information

Microsoft PowerPoint - chap06-5 [호환 모드]

Microsoft PowerPoint - chap06-5 [호환 모드] 2011-1 학기프로그래밍입문 (1) chapter 06-5 참고자료 변수의영역과데이터의전달 박종혁 Tel: 970-6702 Email: jhpark1@seoultech.ac.kr h k 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- ehanbit.net 자동변수 지금까지하나의함수안에서선언한변수는자동변수이다. 사용범위는하나의함수내부이다. 생존기간은함수가호출되어실행되는동안이다.

More information

슬라이드 1

슬라이드 1 -Part3- 제 4 장동적메모리할당과가변인 자 학습목차 4.1 동적메모리할당 4.1 동적메모리할당 4.1 동적메모리할당 배울내용 1 프로세스의메모리공간 2 동적메모리할당의필요성 4.1 동적메모리할당 (1/6) 프로세스의메모리구조 코드영역 : 프로그램실행코드, 함수들이저장되는영역 스택영역 : 매개변수, 지역변수, 중괄호 ( 블록 ) 내부에정의된변수들이저장되는영역

More information

Slide 1

Slide 1 SeoulTech 2011-2 nd 프로그래밍입문 (2) Chapter 14. 상속 박종혁교수 (http://www.parkjonghyuk.net) Tel: 970-6702 Email: jhpark1@snut.ac.kr Learning Objectives 상속의기본 파생클래스와생성자 protected: 제한자 멤버함수의재정의 상속되지않는함수들 상속을이용한프로그래밍

More information

Microsoft PowerPoint - Chapter 4-rev

Microsoft PowerPoint - Chapter 4-rev 4. 클래스의완성 정보은닉 ( 자료은폐 ) 과캡슐화 생성자 소멸자 클래스와배열 자기참조 (this 포인터 ) friend 선언 Jong Hyuk Park 정보은닉과캡슐화 Jong Hyuk Park 3 장의내용정리 클래스에대한기본 (7 장까지이어진다 ) 무엇인가를구현하기에는아직도무리! 클래스의등장배경 현실세계를모델링 데이터추상화 클래스화 객체화 접근제어 : public,

More information

프입2-강의노트-C++기초

프입2-강의노트-C++기초 Chapter 01. C 언어복습및 C++ 기초 박종혁교수 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr SeoulTech 2018-2 nd 프로그래밍입문 (2) C 언어복습 구조체, 포인터, 기타 01 구조체정의 02 구조체변수정의 03 구조체초기화 구조체 4 구조체의정의 학생의정보를보관하기위한구조체정의 //

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 3 장함수와문자열 1. 함수의기본적인개념을이해한다. 2. 인수와매개변수의개념을이해한다. 3. 함수의인수전달방법 2가지를이해한다 4. 중복함수를이해한다. 5. 디폴트매개변수를이해한다. 6. 문자열의구성을이해한다. 7. string 클래스의사용법을익힌다. 이번장에서만들어볼프로그램 함수란? 함수선언 함수호출 예제 #include using

More information

구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined data types) : 다양한자료형을묶어서목적에따라새로운자료형을

구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined data types) : 다양한자료형을묶어서목적에따라새로운자료형을 (structures) 구조체정의 구조체선언및초기화 구조체배열 구조체포인터 구조체배열과포인터 구조체와함수 중첩된구조체 구조체동적할당 공용체 (union) 1 구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined

More information

C프로-3장c03逞풚

C프로-3장c03逞풚 C h a p t e r 03 C++ 3 1 9 4 3 break continue 2 110 if if else if else switch 1 if if if 3 1 1 if 2 2 3 if if 1 2 111 01 #include 02 using namespace std; 03 void main( ) 04 { 05 int x; 06 07

More information

(Microsoft Word - \301\337\260\243\260\355\273\347.docx)

(Microsoft Word - \301\337\260\243\260\355\273\347.docx) 내장형시스템공학 (NH466) 중간고사 학번 : 이름 : 문제 배점 점수 1 20 2 20 3 20 4 20 5 10 6 10 7 15 8 20 9 15 합계 150 1. (20 점 ) 다음용어에대해서설명하시오. (1) 정보은닉 (Information Hiding) (2) 캡슐화 (Encapsulation) (3) 오버로딩 (Overloading) (4) 생성자

More information

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D> Power Java 제 8 장클래스와객체 I 이번장에서학습할내용 클래스와객체 객체의일생직접 메소드클래스를 필드작성해 UML 봅시다. QUIZ 1. 객체는 속성과 동작을가지고있다. 2. 자동차가객체라면클래스는 설계도이다. 먼저앞장에서학습한클래스와객체의개념을복습해봅시다. 클래스의구성 클래스 (class) 는객체의설계도라할수있다. 클래스는필드와메소드로이루어진다.

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스, 객체, 메소드 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 필드만있는클래스 텔레비젼 2 예제 1. 필드만있는클래스 3 예제 2. 여러개의객체생성하기 4 5 예제 3. 메소드가추가된클래스 public class Television { int channel; // 채널번호 int volume; // 볼륨 boolean

More information

Blog

Blog Objective C http://ivis.cwnu.ac.kr/tc/dongupak twitter : @dongupak 2010. 10. 9.. Blog WJApps Blog Introduction ? OS X -. - X Code IB, Performance Tool, Simulator : Objective C API : Cocoa Touch API API.

More information

Microsoft PowerPoint - Chapter 10.ppt

Microsoft PowerPoint - Chapter 10.ppt 10. 연산자오버로딩 연산자오버로딩소개 이항연산자오버로딩 단항연산자의오버로딩 cout, cin, endl 구현 배열인덱스연산자오버로딩 대입연산자오버로딩 Jong Hyuk Park 연산자오버로딩소개 Jong Hyuk Park 연산자오버로딩 (operator overloading) C++ 에서는기존의 C 언어에서제공하고있는연산자에대하여그의미를다시부여하는것을 "

More information

1. 상속의기본개념 다음과같은문제를위한클래스설계 자동차 속성 : 색상, 배기량, 현재속도 메서드 : 가속하라, 멈춰라, 시동을켜라 트럭 속성 : 색상, 배기량, 현재속도, 최대중량 메서드 : 가속하라, 멈춰라, 시동을켜라 택시 속성 : 색상, 배기량, 현재속도, 요금,

1. 상속의기본개념 다음과같은문제를위한클래스설계 자동차 속성 : 색상, 배기량, 현재속도 메서드 : 가속하라, 멈춰라, 시동을켜라 트럭 속성 : 색상, 배기량, 현재속도, 최대중량 메서드 : 가속하라, 멈춰라, 시동을켜라 택시 속성 : 색상, 배기량, 현재속도, 요금, 8 장상속 상속의기본개념상속관련문제제기 base 클래스의접근제어와 protected 멤버상속관계에서의생성자와소멸자함수재정의 (function overriding) 디폴트액세스지정자와구조체 derived 클래스로부터의상속다중상속 virtual base 클래스 derived 클래스의디폴트복사생성자와디폴트대입연산자 private 생성자의사용 C++ 프로그래밍입문

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 System Software Experiment 1 Lecture 5 - Array Spring 2019 Hwansoo Han (hhan@skku.edu) Advanced Research on Compilers and Systems, ARCS LAB Sungkyunkwan University http://arcs.skku.edu/ 1 배열 (Array) 동일한타입의데이터가여러개저장되어있는저장장소

More information

JAVA PROGRAMMING 실습 08.다형성

JAVA PROGRAMMING 실습 08.다형성 2015 학년도 2 학기 1. 추상메소드 선언은되어있으나코드구현되어있지않은메소드 abstract 키워드사용 메소드타입, 이름, 매개변수리스트만선언 public abstract String getname(); public abstract void setname(string s); 2. 추상클래스 abstract 키워드로선언한클래스 종류 추상메소드를포함하는클래스

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 5 강. 배열, 포인터, 참조목차 배열 포인터 C++ 메모리구조 주소연산자 포인터 포인터연산 배열과포인터 메모리동적할당 문자열 참조 1 /20 5 강. 배열, 포인터, 참조배열 배열 같은타입의변수여러개를하나의변수명으로처리 int Ary[10]; 총 10 개의변수 : Ary[0]~Ary[9]

More information

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt 변수와상수 1 변수란무엇인가? 변수 : 정보 (data) 를저장하는컴퓨터내의특정위치 ( 임시저장공간 ) 메모리, register 메모리주소 101 번지 102 번지 변수의크기에따라 주로 byte 단위 메모리 2 기본적인변수형및변수의크기 변수의크기 해당컴퓨터에서는항상일정 컴퓨터마다다를수있음 short

More information

Slide 1

Slide 1 SeoulTech 2011-2 nd 프로그래밍입문 (2) Chapter 11. 분리컴파일과 네임스페이스 박종혁교수 (http://www.parkjonghyuk.net) Tel: 970-6702 Email: jhpark1@snut.ac.kr 분리컴파일 프로그램부분 분리된파일에저장 분리되어컴파일 프로그램이실행되기전에상호간에링크됨 클래스정의 사용프로그램에서분리됨

More information

080629_CFP °ø°³¿ë.hwp

080629_CFP °ø°³¿ë.hwp int deleteq(int *front, rear) int item; if ( ( 가 ) ) retuen queue_empty; ( ( 나 ) ) ; return queue[*front]; 주어진문제의해에접근한결과, 즉근사해를출력하거나혹은일정확률이상의정확한해를구할수있는알고리즘으로, 이알고리즘은주어진문제에대한근사해로만족할수있거나, 간혹틀린해를출력하는경우를허용할수있는경우활용할수있다.

More information

(Microsoft PowerPoint - 11\300\345.ppt [\310\243\310\257 \270\360\265\345])

(Microsoft PowerPoint - 11\300\345.ppt [\310\243\310\257 \270\360\265\345]) 입출력 C++ 의효율적인입출력방법을배워보자. 이장에서다룰내용 1 cin 과 cout 을이용한입출력 2 입출력연산자중복 3 조작자생성 4 파일입출력 01_cin 과 cout 을이용한입출력 포맷입출력 C++ 의표준입출력은 cin, cout 을사용한다. C 의 printf 는함수이므로매번여러인자를입력해줘야하지만, cin/cout 에서는형식을한번만정의하면계속사용할수있다.

More information

Microsoft PowerPoint - ch07 - 포인터 pm0415

Microsoft PowerPoint - ch07 - 포인터 pm0415 2015-1 프로그래밍언어 7. 포인터 (Pointer), 동적메모리할당 2015 년 4 월 4 일 교수김영탁 영남대학교공과대학정보통신공학과 (Tel : +82-53-810-2497; Fax : +82-53-810-4742 http://antl.yu.ac.kr/; E-mail : ytkim@yu.ac.kr) Outline 포인터 (pointer) 란? 간접참조연산자

More information

chap10.PDF

chap10.PDF 10 C++ Hello!! C C C++ C++ C++ 2 C++ 1980 Bell Bjarne Stroustrup C++ C C++ C, C++ C C 3 C C++ (prototype) (type checking) C C++ : C++ 4 C C++ (prototype) (type checking) [ 10-1] #include extern

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 Power Java 제 7 장클래스와객체 이번장에서학습할내용 객체지향이란? 객체 메시지 클래스 객체지향의장점 String 클래스 객체지향개념을완벽하게이해해야만객체지향설계의이점을활용할수있다. 실제세계는객체로이루어진다. 객체지향이란? 실제세계를모델링하여소프트웨어를개발하는방법 절차지향과객체지향 절차지향프로그래밍 (procedural programming): 문제를해결하는절차를중요하게생각하는방법

More information

Microsoft PowerPoint - 6주차.pptx

Microsoft PowerPoint - 6주차.pptx 1 6 주차 클래스상속 유전적상속과객체지향상속 2 그래요우리를꼭닮았어요 아빠의유산이다. 나를꼭닮았군 유산상속 유전적상속 : 객체지향상속 생물 동물 식물 상속받음 어류사람나무풀 유전적상속과관계된생물분류 C++ 에서의상속 (Inheritance) 3 C++ 에서의상속이란? 클래스사이에서상속관계정의 객체사이에는상속관계없음 기본클래스의속성과기능을파생클래스에물려주는것

More information

Microsoft PowerPoint - chap10-함수의활용.pptx

Microsoft PowerPoint - chap10-함수의활용.pptx #include int main(void) { int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; } 1 학습목표 중 값에 의한 전달 방법과

More information

KNK_C_05_Pointers_Arrays_structures_summary_v02

KNK_C_05_Pointers_Arrays_structures_summary_v02 Pointers and Arrays Structures adopted from KNK C Programming : A Modern Approach 요약 2 Pointers and Arrays 3 배열의주소 #include int main(){ int c[] = {1, 2, 3, 4}; printf("c\t%p\n", c); printf("&c\t%p\n",

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Lab 4 ADT Design 클래스로정의됨. 모든객체들은힙영역에할당됨. 캡슐화 (Encapsulation) : Data representation + Operation 정보은닉 (Information Hiding) : Opertion부분은가려져있고, 사용자가 operation으로만사용가능해야함. 클래스정의의형태 public class Person { private

More information

JAVA PROGRAMMING 실습 02. 표준 입출력

JAVA PROGRAMMING 실습 02. 표준 입출력 # 왜생겼나요..? : 절차지향언어가가진단점을보완하고다음의목적을달성하기위해..! 1. 소프트웨어생산성향상 객체지향소프트웨어를새로만드는경우이미만든개체지향소프트웨어를상속받거나객체를 가져다재사용할수있어부분수정을통해소프트웨어를다시만드는부담줄임. 2. 실세계에대한쉬운모델링 실세계의일은절차나과정보다는일과관련된많은물체들의상호작용으로묘사. 캡슐화 메소드와데이터를클래스내에선언하고구현

More information

JVM 메모리구조

JVM 메모리구조 조명이정도면괜찮조! 주제 JVM 메모리구조 설미라자료조사, 자료작성, PPT 작성, 보고서작성. 발표. 조장. 최지성자료조사, 자료작성, PPT 작성, 보고서작성. 발표. 조원 이용열자료조사, 자료작성, PPT 작성, 보고서작성. 이윤경 자료조사, 자료작성, PPT작성, 보고서작성. 이수은 자료조사, 자료작성, PPT작성, 보고서작성. 발표일 2013. 05.

More information

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx #include int main(void) { int num; printf( Please enter an integer "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; } 1 학습목표 을 작성하면서 C 프로그램의

More information

Microsoft PowerPoint - 05장(함수) [호환 모드]

Microsoft PowerPoint - 05장(함수) [호환 모드] 이장에서다룰내용 1 함수의기본 2 함수의입출력방법 함수 함수는입력을넣으면출력이나오는마술상자다. 3 4 재귀함수 Inline 함수 01_ 함수의기본 01_ 함수의기본 함수란 함수를사용할때의장점 반복적으로실행해야할내용을함수로만들어필요할때마다호출해사용할수있다. 프로그램이모듈화 ( 블록화 ) 되므로읽기쉽고, 디버그와편집이쉽다. 프로그램의기능과구조을한눈에알아보기쉽다.

More information

gnu-lee-oop-kor-lec06-3-chap7

gnu-lee-oop-kor-lec06-3-chap7 어서와 Java 는처음이지! 제 7 장상속 Super 키워드 상속과생성자 상속과다형성 서브클래스의객체가생성될때, 서브클래스의생성자만호출될까? 아니면수퍼클래스의생성자도호출되는가? class Base{ public Base(String msg) { System.out.println("Base() 생성자 "); ; class Derived extends Base

More information

Microsoft PowerPoint - CSharp-10-예외처리

Microsoft PowerPoint - CSharp-10-예외처리 10 장. 예외처리 예외처리개념 예외처리구문 사용자정의예외클래스와예외전파 순천향대학교컴퓨터학부이상정 1 예외처리개념 순천향대학교컴퓨터학부이상정 2 예외처리 오류 컴파일타임오류 (Compile-Time Error) 구문오류이기때문에컴파일러의구문오류메시지에의해쉽게교정 런타임오류 (Run-Time Error) 디버깅의절차를거치지않으면잡기어려운심각한오류 시스템에심각한문제를줄수도있다.

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 Power Java 제 9 장생성자와접근제어 이번장에서학습할내용 생성자 정적변수 정적메소드 접근제어 this 클래스간의관계 객체가생성될때초기화를담당하는생성자에대하여살펴봅니다. 생성자 생성자 (contructor): 객체가생성될때에필드에게초기값을제공하고필요한초기화절차를실행하는메소드 생성자의예 class Car { private String color; // 색상

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 6 강. 함수와배열, 포인터, 참조목차 함수와포인터 주소값의매개변수전달 주소의반환 함수와배열 배열의매개변수전달 함수와참조 참조에의한매개변수전달 참조의반환 프로그래밍연습 1 /15 6 강. 함수와배열, 포인터, 참조함수와포인터 C++ 매개변수전달방법 값에의한전달 : 변수값,

More information

Microsoft PowerPoint 장강의노트.ppt

Microsoft PowerPoint 장강의노트.ppt 클래스와객체 클래스와객체 객체 : 우리주변의어떤대상의모델 - 예 : 사람, 차, TV, 개 객체 = 상태 (state) + 행동 (behavior) - 예 : 개의상태 - 종자, 이름, 색개의행동 - 짖다, 가져오다 상태는변수로행동은메소드로나타냄 객체는클래스에의해정의된다. 클래스는객체가생성되는틀혹은청사진이다. 2 예 : 클래스와객체 질문 : 클래스와객체의다른예는?

More information

The C++ Programming Language 4 장타입과선언 4.11 연습문제 Hello,world! 프로그램을실행시킨다. 프로그램이컴파일되지않으면 B3.1 을참고하자. #include<iostream> //#include 문, 헤더파일, 전처리지시

The C++ Programming Language 4 장타입과선언 4.11 연습문제 Hello,world! 프로그램을실행시킨다. 프로그램이컴파일되지않으면 B3.1 을참고하자. #include<iostream> //#include 문, 헤더파일, 전처리지시 The C++ Programming Language 4 장타입과선언 4.11 연습문제 4.11.1 Hello,world! 프로그램을실행시킨다. 프로그램이컴파일되지않으면 B3.1 을참고하자. #include //#include 문, 헤더파일, 전처리지시자로호칭 using namespace std; //using 키워드를사용하여 std 네임스페이스를사용선언

More information

class Sale void makelineitem(productspecification* spec, int qty) SalesLineItem* sl = new SalesLineItem(spec, qty); ; 2. 아래의액티비티다이어그램을보고 Java 또는 C ++,

class Sale void makelineitem(productspecification* spec, int qty) SalesLineItem* sl = new SalesLineItem(spec, qty); ; 2. 아래의액티비티다이어그램을보고 Java 또는 C ++, Level 1은객관식사지선다형으로출제예정 1. 다음은 POST(Post of Sales Terminal) 시스템의한콜레보레이션다이어그램이다. POST 객체의 enteritem(upc, qty) 와 Sale 객체의 makellineitem(spec,qty) 를 Java 또는 C ++, C # 언어로구현하시오. 각메소드구현과관련하여각객체내에필요한선언이있으면선언하시오.

More information

Microsoft PowerPoint - chap03-변수와데이터형.pptx

Microsoft PowerPoint - chap03-변수와데이터형.pptx #include int main(void) { int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num %d\n", num); return 0; } 1 학습목표 의 개념에 대해 알아본다.

More information

Programming hwp

Programming hwp struct MerchandiseTable { CatalogEntry tab[10]; void init(); char const *getname(char const *code); int getprice(char const *code); void MerchandiseTable::init() { strcpy(tab[0].code, "m01"); strcpy(tab[0].name,

More information

기초컴퓨터프로그래밍

기초컴퓨터프로그래밍 구조체 #include int main() { } printf("structure\n"); printf("instructor: Keon Myung Lee\n"); return 0; 내용 구조체 (struct) Typedef 공용체 (union) 열거형 (enum) 구조체 구조체 (structure) 어떤대상을표현하는서로연관된항목 ( 변수 )

More information

Microsoft PowerPoint - chap11-포인터의활용.pptx

Microsoft PowerPoint - chap11-포인터의활용.pptx #include int main(void) int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; 1 학습목표 포인터를 사용하는 다양한 방법에

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스, 객체, 메소드 손시운 ssw5176@kangwon.ac.kr 실제세계는객체로이루어진다. 2 객체와메시지 3 객체지향이란? 실제세계를모델링하여소프트웨어를개발하는방법 4 객체 5 객체란? 객체 (Object) 는상태와동작을가지고있다. 객체의상태 (state) 는객체의특징값 ( 속성 ) 이다. 객체의동작 (behavior) 또는행동은객체가취할수있는동작

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 4 강. 함수와라이브러리함수목차 함수오버로딩 디폴트매개변수 라이브러리함수 clock 함수 난수발생 비버퍼형문자입력 커서이동 프로그래밍문제 1 /21 4 강. 함수와라이브러리함수함수오버로딩 2 /21 함수오버로딩 동일한이름의함수를여러개만들수있음 함수프로파일이달라야함 함수프로파일

More information

The C++ Programming Language 5 장포인터, 배열, 구조체 5.9 연습문제 다음의선언문을순서대로작성해보자. 문자에대한포인터, 10개정수의배열, 10개정수의배열의참조자, 문자열의배열에대한포인터, 문자에대한포인터에대한포인터, 상수정수, 상수

The C++ Programming Language 5 장포인터, 배열, 구조체 5.9 연습문제 다음의선언문을순서대로작성해보자. 문자에대한포인터, 10개정수의배열, 10개정수의배열의참조자, 문자열의배열에대한포인터, 문자에대한포인터에대한포인터, 상수정수, 상수 The C++ Programming Language 5 장포인터, 배열, 구조체 5.9 연습문제 5.9.1 다음의선언문을순서대로작성해보자. 문자에대한포인터, 10개정수의배열, 10개정수의배열의참조자, 문자열의배열에대한포인터, 문자에대한포인터에대한포인터, 상수정수, 상수정수에대한포인터, 정수에대한상수포인터. 그리고각각의객체를초기화하자. Ex 문자에대한포인터 char

More information

Microsoft PowerPoint - 03_(C_Programming)_(Korean)_Pointers

Microsoft PowerPoint - 03_(C_Programming)_(Korean)_Pointers C Programming 포인터 (Pointers) Seo, Doo-Ok Clickseo.com clickseo@gmail.com 목 차 포인터의이해 다양한포인터 2 포인터의이해 포인터의이해 포인터변수선언및초기화 포인터연산 다양한포인터 3 주소연산자 ( & ) 포인터의이해 (1/4) 변수와배열원소에만적용한다. 산술식이나상수에는주소연산자를사용할수없다. 레지스터변수또한주소연산자를사용할수없다.

More information

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public Chapter 9 Lab 문제정답 1. public class Circle private double radius; static final double PI=3.141592; // PI 이름으로 3.141592 로초기화된정적상수 (1) public Circle(double r) radius = r; (2) public double getradius() return

More information

Microsoft PowerPoint - 5주_강의노트

Microsoft PowerPoint - 5주_강의노트 C++ 프로그래밍 강의노트 #5: 5 장클래스특징 I 5.1 복사생성자 (copy constructor) 5.2 객체포인터와객체배열 5.3 this 포인터 5.4 friend 함수 5.5 실습문제 2007. 4. 4 담당교수 : 조재수 E-mail: jaesoo27@kut.ac.kr 1 학습내용 복사생성자 (copy constructor) 객체포인터와객체배열

More information

JAVA PROGRAMMING 실습 05. 객체의 활용

JAVA PROGRAMMING 실습 05. 객체의 활용 2015 학년도 2 학기 public class Person{ public String name; public int age; public Person(){ public Person(String s, int a){ name = s; age = a; public String getname(){ return name; @ 객체의선언 public static void

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 객체지향프로그래밍 (OOP: object-oriented programming) 은우리가살고있는실제세계가객체 (object) 들로구성되어있는것과비슷하게, 소프트웨어도객체로구성하는방법이다. 객체는상태와동작을가지고있다. 객체의상태 (state) 는객체의속성이다. 객체의동작 (behavior) 은객체가취할수있는동작 ( 기능 ) 이다. 객체에대한설계도를클래스 (class)

More information

1. 표준입출력 C++ : C의모든라이브러리를포함 printf, scanf 함수사용가능예 : int, double, 문자열값을입력받고출력하기 #include <cstdio> int ivar; double dvar; char str[20]; printf("int, dou

1. 표준입출력 C++ : C의모든라이브러리를포함 printf, scanf 함수사용가능예 : int, double, 문자열값을입력받고출력하기 #include <cstdio> int ivar; double dvar; char str[20]; printf(int, dou 2 장더나은 C 로서의 C++ (1) 표준입출력네임스페이스 ( 고전 C++ 와표준 C++) 함수오버로딩디폴트매개변수 new와 delete bool 자료형 C++ is not C C++ 프로그래밍입문 1. 표준입출력 C++ : C의모든라이브러리를포함 printf, scanf 함수사용가능예 : int, double, 문자열값을입력받고출력하기 #include

More information

PowerPoint Template

PowerPoint Template 9. 객체지향프로그래밍 대구가톨릭대학교 IT 공학부 소프트웨어공학연구실 목차 2 9.1 개요 9.2 객체지향프로그래밍언어 9.3 추상자료형 9.4 상속 9.5 동적바인딩 9.1 객체지향의개념 (1) 3 객체지향의등장배경 소프트웨어와하드웨어의발전불균형 소프트웨어모듈의재사용과독립성을강조 객체 (object) 란? 우리가다루는모든사물을일컫는말 예 ) 하나의점, 사각형,

More information

목차 포인터의개요 배열과포인터 포인터의구조 실무응용예제 C 2

목차 포인터의개요 배열과포인터 포인터의구조 실무응용예제 C 2 제 8 장. 포인터 목차 포인터의개요 배열과포인터 포인터의구조 실무응용예제 C 2 포인터의개요 포인터란? 주소를변수로다루기위한주소변수 메모리의기억공간을변수로써사용하는것 포인터변수란데이터변수가저장되는주소의값을 변수로취급하기위한변수 C 3 포인터의개요 포인터변수및초기화 * 변수데이터의데이터형과같은데이터형을포인터 변수의데이터형으로선언 일반변수와포인터변수를구별하기위해

More information

Slide 1

Slide 1 SeoulTech 2011-2 nd 프로그래밍입문 (2) Chapter 16. 템플릿 박종혁교수 (http://www.parkjonghyuk.net) Tel: 970-6702 Email: jhpark1@snut.ac.kr Learning Objectives 함수템플릿 구문, 정의 컴파일합병 클래스템플릿 문법 예 : 배열템플릿클래스 템플릿및상속 예 : 부분적으로채워진배열템플릿클래스

More information

10장. 구조체

10장. 구조체 2019-1 st 프로그래밍입문 (1) 10 장. 구조체 박종혁교수 서울과학기술대학교컴퓨터공학과 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr 목차 구조체의기본 구조체의개념 구조체의정의 구조체변수의선언및초기화 구조체변수의사용 구조체변수간의초기화와대입 구조체변수의비교 typedef 구조체의활용 구조체배열 구조체포인터

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 13 장파일처리 1. 스트림의개념을이해한다. 2. 객체지향적인방법을사용하여파일입출력을할수있다. 3. 텍스트파일과이진파일의차이점을이해한다. 4. 순차파일과임의접근파일의차이점을이해한다. 이번장에서만들어볼프로그램 스트림 (stream) 스트림 (stream) 은 순서가있는데이터의연속적인흐름 이다. 스트림은입출력을물의흐름처럼간주하는것이다. 입출력관련클래스들 파일쓰기

More information

Microsoft PowerPoint - 2강

Microsoft PowerPoint - 2강 컴퓨터과학과 김희천교수 학습개요 Java 언어문법의기본사항, 자료형, 변수와상수선언및사용법, 각종연산자사용법, if/switch 등과같은제어문사용법등에대해설명한다. 또한 C++ 언어와선언 / 사용방법이다른 Java의배열선언및사용법에대해서설명한다. Java 언어의효과적인활용을위해서는기본문법을이해하는것이중요하다. 객체지향의기본개념에대해알아보고 Java에서어떻게객체지향적요소를적용하고있는지살펴본다.

More information