Microsoft PowerPoint - additional-11_13l.ppt [호환 모드]

Size: px
Start display at page:

Download "Microsoft PowerPoint - additional-11_13l.ppt [호환 모드]"

Transcription

1 11.string 클래스디자인로딩 표준 string 클래스 사용자정의클래스 Jong Hyuk Park

2 표준 string 클래스 Jong Hyuk Park

3 string 클래스 C++ 표준라이브러리에서정의된문자열처리클래스 #include <iostream> #include <string> using std::endl; using std::cout; using std::cin; using std::string; int main() string str1="good "; string str2="morning"; string str3=str1+str2; cout<<str1<<endl; t cout<<str2<<endl; cout<<str3<<endl; str1+=str2; if(str1==str3) //str1과 str3의내용비교. cout<<"equal!"<<endl; string str4; cout<<" 문자열입력: "; cin>>str4; cout<<" 입력한문자열 : "<<str4<<endl; return 0; Good morning Good morning equal! 문자열입력 : Hello! 입력한문자열 : Hello!

4 사용자정의 string 클래스 Jong Hyuk Park

5 string 클래스사용자구현 앞예의표준라이브러리를이용한 string 클래스의사용자구현 string 클래스사용자구현 생성자, 소멸자, 복사생성자정의 +, =, +=, ==, <<, >> 연산자오버로딩

6 사용자정의 string 클래스, 생성자, 소멸자 #include <iostream> using std::endl; using std::cout; using std::cin; using std::ostream; t using std::istream; class string int len; // null 문자를포함하는문자열의길이 char* str; public: string(const char* s=null); string(const string& s); ~string(); ; string& operator=(const string& s); string& operator+=(const string& s); bool operator==(const string& s); string ti operator+(const tstring& ti s); friend ostream& operator<<(ostream& os, const string& s); friend istream& operator>>(istream& is, string& s); // 생성자 string::string(const char* s) len=(s!=null? strlen(s)+1 : 1); str=new char[len]; if(s!=null) strcpy(str, s); // 복사생성자 string::string(const string& s) len=s.len; str=new char[len]; strcpy(str, s.str); // 소멸자 string::~string() delete []str;

7 연산자오버로딩 string& string::operator=(const string& s) delete []str; len=s.len; str=new char[len]; strcpy(str, s.str); return *this; string& string::operator+=(const string& s) len=len+s.len-1; char* tstr=new char[len]; strcpy(tstr, str); delete []str; strcat(tstr, t(tst s.str); str=tstr; return *this; bool string::operator==(const string& s) return strcmp(str, s.str)? false:true; string string::operator+(const string& s) char* tstr=new char[len+s.len-1]; strcpy(tstr, str); strcat(tstr, s.str); string temp(tstr); delete []tstr; return temp; ostream& operator<<(ostream& os, const string& s) os<<s.str; return os; istream& operator>>(istream& is, string& s) char str[100]; is>>str; s=string(str); return is;

8 실행결과 int main() string str1="good "; string str2="morning"; string str3=str1+str2; cout<<str1<<endl; cout<<str2<<endl; cout<<str3<<endl; str1+=str2; if(str1==str3) //str1 과 str3 의내용비교. cout<<"equal!"<<endl; string str4; Good morning Good morning equal! 문자열입력 : Hello! 입력한문자열 : Hello! cout<<" 문자열입력 : "; cin>>str4; cout<<" 입력한문자열 : "<<str4<<endl; return 0;

9 12. 템플릿 (Template) 함수템플릿 클래스템플릿 Jong Hyuk Park

10 함수템플릿 Jong Hyuk Park

11 함수템플릿소개 함수템플릿 한번의함수정의로서로다른자료형에대해적용하는함수 예 int abs(int n) return n < 0? -n :n; double abs(double n) 함수 return n < 0? -n : n; // 정수형인수의 abs() 함수 // double 형인수의 abs() 함수의인수와반환형의자료형만이다르고함수내부의프로그램코드는모두같음 템플릿함수를사용하여함수정의는한번만하고필요시자료형에따라각각적용 11

12 함수템플릿정의 함수템플릿은 template 키워드, typename( 또는 class) 템플릿자료형인수들를선언 템플릿의자료형이되어템플릿함수의가인수나반환형을위한자료형으로사용 template <typename Type1 [, typename Type 2 ]> 반환형함수명 ( 가인수리스트 ) 함수호출시에사용되는실인수, 반환형의자료형을컴파일러가템플릿함수의자료형인수에대입하여특정함수를생성하고호출 12

13 함수템플릿사용예 template <class T> T abs(t n) // T 형가인수, 반환형을갖는템플릿함수 abs() 정의 return n < 0? n : n; main() int i = abs(123); // int abs(int n) 을생성하고호출 double d = abs( ); // double abs(double n) 을생성하고호출 => 함수호출시에사용된실인수, 반환형의자료형에따라두개의 abs() 함수를생성하고호출 int abs(int n) // int i = abs(123); 호출시생성 return n < 0? n : n; double abs(double n) // double d = abs( ); 호출시생성 return n < 0? n : n; 13

14 템플릿자료형인수사용예 템플릿함수의정의시사용되는템플릿의자료형인수는함수의가인수로최소한한번이상사용되어야함 template <typenamet> T func1(t *a); // 올바름 template <typename T> T func2(t a, T b); // 올바름 template <typename T, typename T> T func2(t a, T b); // 에러, T가중복선언 template <typename T, typename U> Tf func2(t a, Ub) b); // 올바름 template <typename T, typename U, typename V> U func2(t a, V b); // 에러, U가가인수로사용되지않음 14

15 함수템플릿사용예 1 #include <iostream> using std::endl; using std::cout; template <typename Type> Type min(type a, Type b) // 템플릿함수 min() 정의 return a < b? a : b; int main() // int min(int,int) 템플릿함수생성, 호출 cout << min(88,24) 882 << endl; // double min(double,double) 템플릿함수생성및호출 cout << min(1.234,7.56) << endl; return 0; min(88,24) 의호출시에템플릿의자료형인수 Type 이 int 로치환된 int min(int, int) 인함수가 생성되고, min(1.234, 7.56) 의호출시에는 double min(double, double) 인함수가생성 15

16 함수템플릿사용예 2 #include <iostream> using std::endl; using std::cout; template <typename T> // 함수템플릿정의 void ShowData(T a, T b) cout<<a<<endl; cout<<b<<endl; int main(void) ShowData(1, 2); ShowData(3, 2.5); //! error #include <iostream> using std::endl; using std::cout; template <typename T1, typename T2> // 함수템플릿정의 void ShowData(T1 a, T2 b) cout<<a<<endl; cout<<b<<endl; int main(void) ShowData(1, 2); ShowData(3, 2.5); return 0; return 0; 16

17 함수템플릿의특수화 #include <iostream> using std::endl; using std::cout; template <typename T> // 함수템플릿정의 int SizeOf(T a) return sizeof(a); int main(void) int i=10; double e=7.7; char* str="good morning!"; cout<<sizeof(i)<<endl; cout<<sizeof(e)<<endl; cout<<sizeof(str)<<endl; return 0; #include <iostream> using std::endl; using std::cout; template <typename T> // 함수템플릿정의 int SizeOf(T a) return sizeof(a); template<> // 함수템플릿정의 int SizeOf(char* a) return strlen(a); int main(void) int i=10; double e=7.7; 7; char* str="good morning!"; cout<<sizeof(i)<<endl; cout<<sizeof(e)<<endl; cout<<sizeof(str)<<endl; return 0; 17

18 클래스템플릿 Jong Hyuk Park

19 클래스템플릿 클래스템플릿 한번의클래스정의로서로다른자료형에대해적용하는클래스 class Counter int value; class Counter double value; public: Counter(int n) value = n; public: Counter(double n) value = n; Counter() value = 0; Counter() value = 0; int val() return value; double val() return value; void operator ++() ++value; void operator --() --value; void operator ++() ++value; void operator --() --value; ; ; 19

20 클래스템플릿정의및생성 template <typename Type1 [, typename Type 2 ]> class 클래스명 클래스명 < 자료형 [, 자료형, ]> 객체명 ; template <typename T> class Counter T value; public: Counter(T n) value = n; Counter() value = 0; T val() return value; void operator ++() ++value; void operator --() --value; Counter <int> oi; Counter <double> od; 20

21 클래스템플릿사용예 1 #include <iostream> using std::endl; using std::cout; template <typename T> class Counter T value; public: Counter(T n) value = n; Counter() value = 0; T val() return value; void operator ++() ++value; void operator --() --value; ; int main(void) Counter <int> icnt; Counter <double> dcnt(3.14); Counter <char> ccnt('c'); ++icnt; --dcnt; ++ccnt; cout << "++icnt : " << icnt.val() << endl; cout << "--dcnt : " << dcnt.val() << endl; cout << "++ccnt : " << ccnt.val() << endl; #include <iostream> using std::endl; using std::cout; template <typename T> class Counter T value; public: Counter(T n); Counter() value = 0; T val(); void operator ++(); ++value; void operator --() --value; ; template <typename T> Counter<T>::Counter(T C n) value = n; template <typename T> T Counter<T>::val() return value; int main(void) Counter <int> icnt; Counter <double> dcnt(3.14); Counter <char> ccnt('c'); 21 return 0; ++icnt; --dcnt; ++ccnt; cout << "++icnt : " << icnt.val() << endl; cout << "--dcnt : " << dcnt.val() << endl; cout << "++ccnt : " << ccnt.val() << endl; return 0;

22 클래스템플릿사용예 2 #include <iostream> using std::endl; using std::cout; template <typename S, typename L> class Size int s; int l; public: Size() s = sizeof(s); l = sizeof(l); void print() cout << s << ',' << l << endl; ; int main(void) Size <char, long int> a; Size <float, double> b; cout << "char,long int: "; a.print(); cout << "float,double : "; b.print(); 22 return 0;

23 클래스템플릿의상속 클래스템플릿도일반클래스와같이상속 베이스클래스인클래스템플릿을일반클래스가파생클래스가되어상속받는경우 베이스클래스인클래스템플릿으로부터생성된클래스를상속 클래스템플릿을생성하지않고전체를상속받으면에러 클래스템플릿인베이스클래스로부터클래스템플릿인파생클래스가상속받는경우 template <typename T> class Base ; class Derive : public Base<int> template <typename T> class Base ; template <typename U> class Derive : public Base<U> 23

24 클래스템플릿의상속예 #include <iostream> using std::endl; using std::cout; template <typename T> class Area // 베이스클래스템플릿 T side1, side2; public: Area(T s1, T s2) // 생성자 side1 = s1; side2 = s2; void getside(t &s1, T &s2) s1 = side1; s2 = side2; ; template <typename U> class Rectangle : public Area<U> // 파생클래스템플릿 public: Rectangle(U s1, U s2) : Area<U>(s1,s2) // 생성자 /* no operation */ U getarea(void) U s1, s2; int main(void) Rectangle <int> ir(3,14); Rectangle <double> dr(2.5, 7.3); cout << "int area : " << ir.getarea() << endl; cout << "double area : " << dr.getarea() << endl; return 0; int area : 42 double area : 클래스템플릿인파생클래스 Rectangle 이또다른 클래스템플릿인베이스클래스 Area 로부터상속받 는예이다. Rectangle 파생클래스템플릿는 Area 베이스클래스템플릿전체를상속받는다. 24 ; getside(s1,s2); return s1 * s2;

25 13. 예외처리 기존의예외처리방식 C++ 예외처리 Jong Hyuk Park

26 예외처리소개 예외처리 (exception handling) 프로그램의비정상적인상황발생시처리하는과정 대개의경우예외처리하지않는경우실행에러발생 26

27 예외처리없는코드예 #include <iostream> using std::endl; using std::cout; using std::cin; int main(void) int a, b; 실행결과 1 두개의숫자입력 : 5 2 a/b의몫 : 2 a/b 의나머지 : 1 cout<<" 두개의숫자입력 : "; cin>>a>>b; cout<<"a/b 의몫 : "<<a/b<<endl; cout<<"a/b 의나머지 : "<<a%b<<endl; return 0; 실행결과 2 두개의숫자입력 : 5 0 <-!!! 실행에러발생 27

28 전통적스타일예외처리코드예 #include <iostream> using std::endl; using std::cout; using std::cin; int main(void) int a, b; cout<<" 두개의숫자입력 : "; cin>>a>>b; if(b==0) cout<<" 입력오류! 다시실행하세요."<<endl; else cout<<"a/b 의몫 : "<<a/b<<endl; cout<<"a/b 의나머지 : "<<a%b<<endl; 실행결과 1 두개의숫자입력 : 5 2 a/b의몫 : 2 a/b 의나머지 : 1 실행결과 2 두개의숫자입력 : 5 0 입력오류! 다시실행하세요. return 0; 28

29 C++ 예외처리 Jong Hyuk Park

30 C++ 예외처리 (1) try & catch try /* 예외발생예상지역 */ catch( 처리되어야할예외의종류 ) throw /* 예외를처리하는코드가존재할위치 */ throw ex; // ex 를가리켜보통은그냥 예외 라고표현을한다. // 예외상황발생통보시사용 30

31 C++ 예외처리 (2) 31

32 C++ 예외처리코드예 1 #include <iostream> using std::endl; using std::cout; using std::cin; int main(void) int a, b; 실행결과 1 두개의숫자입력 :52 a/b의몫 : 2 a/b의나머지 : 1 실행결과 2 두개의숫자입력 :50 0 입력. 입력오류! 다시실행하세요. cout<<" 두개의숫자입력 : "; cin>>a>>b; try if(b==0) throw b; cout<<"a/b의몫 : "<<a/b<<endl; cout<<"a/b의나머지 : "<<a%b<<endl; catch(int exception) cout<<exception<<" 입력."<<endl; cout<<" 입력오류! 다시실행하세요."<<endl; return 0; 32

33 C++ 예외처리코드예 2 #include <iostream> using std::endl; using std::cout; using std::cin; 두개의숫자입력 : 입력. 입력오류! 다시실행하세요. int divide(int a, int b); // a/b 의몫만반환 int main(void) int a, b; cout<<" 두개의숫자입력 : "; cin>>a>>b; try cout<<"a/b의몫 : "<<divide(a, b)<<endl; catch(int exception) return 0; cout<<exception<<" 입력."<<endl; cout<<" 입력오류! 다시실행하세요."<<endl; int divide(int a, int b) if(b==0) throw b; return a/b; 33

34 스택풀기 (Stack Unwinding) 34

35 C++ 예외처리코드예 예외가처리되지않으면 stdlib.h에선언되어있는 abort 함수의호출에의해프로그램종료 전달되는예외명시 그이외의예외가전달되면 abort 함수의호출 int fct(double d) throw (int, double, char *)

36 36 C++ 예외처리코드예 3 #include <iostream> using std::endl; using std::cout; using std::cin; int divide(int a, int b); // a/b의몫만반환 int main(void) int a, b; cout<<" 두개의숫자입력 : "; cin>>a>>b; try cout<<"a/b의몫 : "<<divide(a, b)<<endl; catch(char exception) cout<<exception<<" 입력."<<endl; cout<<" 입력오류! 다시실행하세요."<<endl; return 0; int divide(int a, int b) if(b==0) throw b; //!! 에러, int 형 b 전달 return a/b;

37 C++ 예외처리코드예 4 #include <iostream> using std::endl; using std::cout; using std::cin; int main(void) int num; cout<<"input number: "; cin>>num; try if(num>0) throw 10; // int형예외전달. else throw 'm'; // char 형예외전달. catch(int exp) cout<<"int형예외발생 "<<endl; catch(char exp) cout<<"char형예외발생 "<<endl; return 0; 실행결과 1 input number: 10 int형예외발생실행결과 2 input number: -10 char형예외발생 37

38 #include <iostream> using std::endl; using std::cout; using std::cin; 예외처리클래스예 char* account=" "; // 계좌번호 int sid=1122; // 비밀번호 int balance=1000; // 잔액. class AccountExpt char acc[10]; int sid; public: AccountExpt(char* str, int id) strcpy(acc, str); sid=id; int main(void) char acc[10]; int id; int money; try cout<<" 계좌번호입력 : "; cin>>acc; cout<<" 비밀번호 4 자리입력 : "; cin>>id; if(strcmp(account, acc) sid!=id) throw AccountExpt(acc, id); cout<<" 출금액입력 : "; cin>>money; if(balance<money) throw money; void What() balance-=money; cout<<" 계좌번호 : "<<acc<<endl; cout<<" 잔액 : "<<balance<<endl; cout<<" 비밀번호 : "<<sid<<endl; catch(int money) ; cout<<" 부족금액: "<<money-balance<<endl; catch(accountexpt& expt) cout<<" 다음입력을다시한번확인하세요 "<<endl; expt.what(); return 0; 38

39 Jong Hyuk Park

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

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

3장. Hello World

3장. Hello World Chapter 11. 예외처리와템플릿 박종혁교수 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr SeoulTech 2016-2 nd 프로그래밍입문 (1) 11-1. 예외처리 3 예외처리 (Exception Handling) 예외란? 우리가당연하다고가정한상황이거짓이되는경우 대표적경우 컴퓨터에사용가능한메모리가부족한경우

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

Microsoft PowerPoint - 09-C++-7-Template.pptx

Microsoft PowerPoint - 09-C++-7-Template.pptx 예제로배우는 C++ 객체지향프로그래밍 1 템플릿 (template) 이란? 한번의정의로모든자료형에대한처리를하도록고안 처리내용은같으나자료형이다를경우각자료형에대한함수를별도작성해야함 이때템플릿으로함수나클래스를통합정의 각자료형을일반화하여하나의모델로모든자료형을처리 예제로배우는 C++ 객체지향프로그래밍 2 템플릿함수 예제로배우는 C++ 객체지향프로그래밍 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

윤성우의 열혈 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 - additional08.ppt [호환 모드]

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

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

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

PowerPoint Template

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

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

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 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 - C++ 5 .pptx

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

More information

Microsoft PowerPoint - CSharp-10-예외처리

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

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++ Programming

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

More information

쉽게 풀어쓴 C 프로그래밍

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

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 16. 템플릿 박종혁교수 (http://www.parkjonghyuk.net) Tel: 970-6702 Email: jhpark1@snut.ac.kr Learning Objectives 함수템플릿 구문, 정의 컴파일합병 클래스템플릿 문법 예 : 배열템플릿클래스 템플릿및상속 예 : 부분적으로채워진배열템플릿클래스

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

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

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 - Chap12-OOP.ppt

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

More information

설계란 무엇인가?

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

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

PowerPoint Template

PowerPoint Template 10. 예외처리 대구가톨릭대학교 IT 공학부 소프트웨어공학연구실 목차 2 10.1 개요 10.2 C++ 의예외처리 10.3 Java 의예외처리 10.4 Ada 의예외처리 10.1 예외처리의개요 (1) 3 예외 (exception) 오버플로나언더플로, 0 으로나누기, 배열첨자범위이탈오류와같이프로그램실행중에비정상적으로발생하는사건 예외처리 (exception handling)

More information

080629_CFP °ø°³¿ë.hwp

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

More information

슬라이드 1

슬라이드 1 UNIT 16 예외처리 로봇 SW 교육원 3 기 최상훈 학습목표 2 예외처리구문 try-catch-finally 문을사용핛수있다. 프로그램오류 3 프로그램오류의종류 컴파일에러 (compile-time error) : 컴파일실행시발생 럮타임에러 (runtime error) : 프로그램실행시발생 에러 (error) 프로그램코드에의해서해결될수없는심각핚오류 ex)

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

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 - additional03.ppt [호환 모드]

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

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 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

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

슬라이드 1

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

More information

쉽게 풀어쓴 C 프로그래밍

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

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 프로그래밍

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

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

슬라이드 1

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

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

윤성우의 열혈 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

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

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345]) 예외와예외클래스 예외처리 514760-1 2016 년가을학기 12/08/2016 박경신 오류의종류 에러 (Error) 하드웨어의잘못된동작또는고장으로인한오류 에러가발생되면 JVM실행에문제가있으므로프로그램종료 정상실행상태로돌아갈수없음 예외 (Exception) 사용자의잘못된조작또는개발자의잘못된코딩으로인한오류 예외가발생되면프로그램종료 예외처리 추가하면정상실행상태로돌아갈수있음

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 15 강. 표준입출력목차 C++ 입출력클래스 입출력형식설정방법 setf, unsetf 멤버함수에의한입출력형식설정 setf 이외의멤버함에의한입출력형식설정 입출력조작자에의한입출력형식설정 문자및문자열입출력멤버함수 문자단위입출력 줄단위입력 입출력스트림상태 string 클래스 complex

More information

<432B2BC7C1B7CEB1D7B7A1B9D628BABBB9AE5FC3D6C1BE295B315D2E687770>

<432B2BC7C1B7CEB1D7B7A1B9D628BABBB9AE5FC3D6C1BE295B315D2E687770> 저 자 약 력이상정순천향대학교컴퓨터학부교수, sjlee@sch.ac.kr 조영일수원대학교컴퓨터학과교수, yicho@suwon.ac.kr 김은성순천향대학교전기전자공학과교수, eskim@sch.ac.kr 박종득공주대학교컴퓨터공학부교수, pjd@kongju.ac.kr C++ 언어는 C 에 C 언어의증가연산자 ++ 를덧붙인 C++ 라는이름이의미하는바와같이 C 언어의문법을대부분그대로사용하면서객체지향프로그래밍기법을추가한

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

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

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

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Chapter 10 포인터 01 포인터의기본 02 인자전달방법 03 포인터와배열 04 포인터와문자열 변수의주소를저장하는포인터에대해알아본다. 함수의인자를값과주소로전달하는방법을알아본다. 포인터와배열의관계를알아본다. 포인터와문자열의관계를알아본다. 1.1 포인터선언 포인터선언방법 자료형 * 변수명 ; int * ptr; * 연산자가하나이면 1 차원포인터 1 차원포인터는일반변수의주소를값으로가짐

More information

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

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

More information

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

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

More information

설계란 무엇인가?

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

More information

Visual C++ & OOP Fundamentals ( 2005/1/31~2005/2/4)

Visual C++ & OOP Fundamentals ( 2005/1/31~2005/2/4) 제 2 장. C 보다나은 C++ I 학습목표 C++ 의개선된데이터형기능인엄격한형검사, bool 형, 레퍼런스형에대해알아본다. C++ 의개선된함수기능인인라인함수, 디폴트인자, 함수오버로딩, 함수템플릿에대해알아본다. 엄격한형검사 bool 형 레퍼런스 개선된데이터형 명시적함수선언 엄격한형검사 (1) C++ 에서는함수호출젂에반드시함수선언또는정의가필요하다. void

More information

02장.배열과 클래스

02장.배열과 클래스 ---------------- DATA STRUCTURES USING C ---------------- CHAPTER 배열과구조체 1/20 많은자료의처리? 배열 (array), 구조체 (struct) 성적처리프로그램에서 45 명의성적을저장하는방법 주소록프로그램에서친구들의다양한정보 ( 이름, 전화번호, 주소, 이메일등 ) 를통합하여저장하는방법 홍길동 이름 :

More information

1. 기본형의형변환복습 C/C++ 형변환의종류 자동형변환 ( 묵시적형변환 ) 강제형변환 ( 명시적형변환 ) 기본형의자동형변환의예 1. 배열 to 포인터변환 배열명은해당배열의첫번째원소의 주소로변환됨 int ary[10]; int *pary = ary; 2. 함수 to 포

1. 기본형의형변환복습 C/C++ 형변환의종류 자동형변환 ( 묵시적형변환 ) 강제형변환 ( 명시적형변환 ) 기본형의자동형변환의예 1. 배열 to 포인터변환 배열명은해당배열의첫번째원소의 주소로변환됨 int ary[10]; int *pary = ary; 2. 함수 to 포 9 장상속과다형성 기본형의형변환복습서로다른클래스객체들사이의대입상속관계인객체와포인터의관계가상함수가상함수의동작원리추상클래스와순수가상함수 virtual 소멸자클래스멤버변수로서의클래스객체다중파일프로그래밍 C++ 프로그래밍입문 1. 기본형의형변환복습 C/C++ 형변환의종류 자동형변환 ( 묵시적형변환 ) 강제형변환 ( 명시적형변환 ) 기본형의자동형변환의예 1. 배열 to

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

02 C h a p t e r Java

02 C h a p t e r Java 02 C h a p t e r Java Bioinformatics in J a va,, 2 1,,,, C++, Python, (Java),,, (http://wwwbiojavaorg),, 13, 3D GUI,,, (Java programming language) (Sun Microsystems) 1995 1990 (green project) TV 22 CHAPTER

More information

3. 1 포인터란 3. 2 포인터변수의선언과사용 3. 3 다차원포인터변수의선언과사용 3. 4 주소의가감산 3. 5 함수포인터

3. 1 포인터란 3. 2 포인터변수의선언과사용 3. 3 다차원포인터변수의선언과사용 3. 4 주소의가감산 3. 5 함수포인터 - Part2-3 3. 1 포인터란 3. 2 포인터변수의선언과사용 3. 3 다차원포인터변수의선언과사용 3. 4 주소의가감산 3. 5 함수포인터 3.1 포인터란 ü ü ü. ü. ü. ü ( ) ? 3.1 ü. ü C ( ).? ü ü PART2-4 ü ( ) PART3-4 3.2 포인터변수의선언과사용 3.2 포인터 변수의 선언과 사용 (1/8) 포인터 변수의

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++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 4 강. 함수와라이브러리함수목차 함수오버로딩 디폴트매개변수 라이브러리함수 clock 함수 난수발생 비버퍼형문자입력 커서이동 프로그래밍문제 1 /21 4 강. 함수와라이브러리함수함수오버로딩 2 /21 함수오버로딩 동일한이름의함수를여러개만들수있음 함수프로파일이달라야함 함수프로파일

More information

int main(void) int a; int b; a=3; b=a+5; printf("a : %d \n", a); printf("b : %d \n", b); a b 3 a a+5 b &a(12ff60) &b(12ff54) 3 a 8 b printf(" a : %x \

int main(void) int a; int b; a=3; b=a+5; printf(a : %d \n, a); printf(b : %d \n, b); a b 3 a a+5 b &a(12ff60) &b(12ff54) 3 a 8 b printf( a : %x \ ? 1 int main(void) int a; int b; a=3; b=a+5; printf("a : %d \n", a); printf("b : %d \n", b); a b 3 a a+5 b &a(12ff60) &b(12ff54) 3 a 8 b printf(" a : %x \n", &a); printf(" b : %x \n", &b); * : 12ff60,

More information

JAVA PROGRAMMING 실습 09. 예외처리

JAVA PROGRAMMING 실습 09. 예외처리 2015 학년도 2 학기 예외? 프로그램실행중에발생하는예기치않은사건 예외가발생하는경우 정수를 0으로나누는경우 배열의크기보다큰인덱스로배열의원소를접근하는경우 파일의마지막부분에서데이터를읽으려고하는경우 예외처리 프로그램에문제를발생시키지않고프로그램을실행할수있게적절한조치를취하는것 자바는예외처리기를이용하여예외처리를할수있는기법제공 자바는예외를객체로취급!! 나뉨수를입력하시오

More information

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074>

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074> Chap #2 펌웨어작성을위한 C 언어 I http://www.smartdisplay.co.kr 강의계획 Chap1. 강의계획및디지털논리이론 Chap2. 펌웨어작성을위한 C 언어 I Chap3. 펌웨어작성을위한 C 언어 II Chap4. AT89S52 메모리구조 Chap5. SD-52 보드구성과코드메모리프로그래밍방법 Chap6. 어드레스디코딩 ( 매핑 ) 과어셈블리어코딩방법

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

[ 마이크로프로세서 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

JAVA PROGRAMMING 실습 08.다형성

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

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

PowerPoint Presentation

PowerPoint Presentation Package Class 3 Heeseung Jo 목차 section 1 패키지개요와패키지의사용 section 2 java.lang 패키지의개요 section 3 Object 클래스 section 4 포장 (Wrapper) 클래스 section 5 문자열의개요 section 6 String 클래스 section 7 StringBuffer 클래스 section

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 2... ( ). ( ). @ vs. logic data method variable behavior attribute method field Flow (Type), ( ) member @ () : C program Method A ( ) Method B ( ) Method C () program : Java, C++, C# data @ Program

More information

C 언어 프로그래밊 과제 풀이

C 언어 프로그래밊 과제 풀이 과제풀이 (1) 홀수 / 짝수판정 (1) /* 20094123 홍길동 20100324 */ /* even_or_odd.c */ /* 정수를입력받아홀수인지짝수인지판정하는프로그램 */ int number; printf(" 정수를입력하시오 => "); scanf("%d", &number); 확인 주석문 가필요한이유 printf 와 scanf 쌍

More information

BACK TO THE BASIC C++ 버그 헌팅: 버그를 예방하는 11가지 코딩 습관

BACK TO THE BASIC C++ 버그 헌팅: 버그를 예방하는 11가지 코딩 습관 Hanbit ebook Realtime 30 C++ 버그 헌팅 버그를 예방하는 11가지 코딩 습관 Safe C++ 블라디미르 쿠스퀴니르 지음 / 정원천 옮김 이 도서는 O REILLY의 Safe C++의 번역서입니다. BACK TO THE BASIC C++ 버그 헌팅 버그를 예방하는 11가지 코딩 습관 BACK TO THE BASIC C++ 버그 헌팅 버그를

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

C++ Programming

C++ Programming C++ Programming C 언어에서 C++ 언어로의전환 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 C++ 언어개요 C 언어기반의 C++ 2 C++ 언어개요 C++ 언어개요 C++ 언어의역사및특징 통합개발환경 C 언어기반의 C++ 3 C++ 언어의역사 C++ 언어의역사및특징 1979 년,

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 예외처리 배효철 th1g@nate.com 1 목차 예외와예외클래스 실행예외 예외처리코드 예외종류에따른처리코드 자동리소스닫기 예외처리떠넘기기 사용자정의예외와예외발생 예외와예외클래스 구문오류 예외와예외클래스 구문오류가없는데실행시오류가발생하는경우 예외와예외클래스 import java.util.scanner; public class ExceptionExample1

More information

12 장파일입출력 파일입출력의기초파일열기, 사용하기, 닫기파일입출력모드문자단위파일입출력텍스트파일과이진파일 read, write 함수에의한이진파일입출력임의접근입출력스트림상태입출력연산자오버로딩과파일입출력 C++ 프로그래밍입문

12 장파일입출력 파일입출력의기초파일열기, 사용하기, 닫기파일입출력모드문자단위파일입출력텍스트파일과이진파일 read, write 함수에의한이진파일입출력임의접근입출력스트림상태입출력연산자오버로딩과파일입출력 C++ 프로그래밍입문 12 장파일입출력 파일입출력의기초파일열기, 사용하기, 닫기파일입출력모드문자단위파일입출력텍스트파일과이진파일 read, write 함수에의한이진파일입출력임의접근입출력스트림상태입출력연산자오버로딩과파일입출력 C++ 프로그래밍입문 1. 파일입출력의기초 파일입출력방법 표준입출력객체인 cin, cout에해당하는파일입출력스트림객체만만들수있다면기본적인사용방법은표준입출력과동일파일입출력스트림객체의생성

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 3 if, if else, if else if, switch case for, while, do while break, continue : System.in, args, JOptionPane for (,, ) @ vs. logic data method variable Data Data Flow (Type), ( ) @ Member field

More information

쉽게 풀어쓴 C 프로그래밍

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

More information

1.2 자료형 (data type) 프로그램에서다루는값의형태로변수나함수를정의할때주로사용하며, 컴퓨터는선언된 자료형만큼의메모리를확보하여프로그래머에게제공한다 정수 (integer) 1) int(4 bytes) 연산범위 : (-2 31 ) ~ (2 31 /2)-

1.2 자료형 (data type) 프로그램에서다루는값의형태로변수나함수를정의할때주로사용하며, 컴퓨터는선언된 자료형만큼의메모리를확보하여프로그래머에게제공한다 정수 (integer) 1) int(4 bytes) 연산범위 : (-2 31 ) ~ (2 31 /2)- 1.2 자료형 (data type) 프로그램에서다루는값의형태로변수나함수를정의할때주로사용하며, 컴퓨터는선언된 자료형만큼의메모리를확보하여프로그래머에게제공한다. 1.2.1 정수 (integer) 1) int(4 bytes) 연산범위 : (-2 31 ) ~ (2 31 /2)-1 연산범위이유 : 00000000 00000000 00000000 00000000의 32

More information

OCW_C언어 기초

OCW_C언어 기초 초보프로그래머를위한 C 언어기초 4 장 : 연산자 2012 년 이은주 학습목표 수식의개념과연산자및피연산자에대한학습 C 의알아보기 연산자의우선순위와결합방향에대하여알아보기 2 목차 연산자의기본개념 수식 연산자와피연산자 산술연산자 / 증감연산자 관계연산자 / 논리연산자 비트연산자 / 대입연산자연산자의우선순위와결합방향 조건연산자 / 형변환연산자 연산자의우선순위 연산자의결합방향

More information

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CC0E7B0EDB0FCB8AE5C53746F636B5F4D616E D656E74732E637070>

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CC0E7B0EDB0FCB8AE5C53746F636B5F4D616E D656E74732E637070> 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include "QuickSort.h" 7 using namespace std; 8 9 10 Node* Queue[100]; // 추가입력된데이터를저장하기위한 Queue

More information

11장 포인터

11장 포인터 누구나즐기는 C 언어콘서트 제 9 장포인터 이번장에서학습할내용 포인터이란? 변수의주소 포인터의선언 간접참조연산자 포인터연산 포인터와배열 포인터와함수 이번장에서는포인터의기초적인지식을학습한다. 포인터란? 포인터 (pointer): 주소를가지고있는변수 메모리의구조 변수는메모리에저장된다. 메모리는바이트단위로액세스된다. 첫번째바이트의주소는 0, 두번째바이트는 1, 변수와메모리

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 - 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

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 자바-기본문법(Ch2).pptx

Microsoft PowerPoint 자바-기본문법(Ch2).pptx 자바기본문법 1. 기본사항 2. 자료형 3. 변수와상수 4. 연산자 1 주석 (Comments) 이해를돕기위한설명문 종류 // /* */ /** */ 활용예 javadoc HelloApplication.java 2 주석 (Comments) /* File name: HelloApplication.java Created by: Jung Created on: March

More information

03장.스택.key

03장.스택.key ---------------- DATA STRUCTURES USING C ---------------- 03CHAPTER 1 ? (stack): (LIFO:Last-In First-Out) 2 : top : ( index -1 ),,, 3 : ( ) ( ) -> ->. ->.... 4 Stack ADT : (LIFO) : init():. is_empty():

More information

Cluster management software

Cluster management software 자바네트워크프로그래밍 (OCJP 국제공인자격취득중심 ) 충북대학교 최민 기본예제 예외클래스를정의하고사용하는예제 class NewException extends Exception { public class ExceptionTest { static void methoda() throws NewException { System.out.println("NewException

More information

PowerPoint Presentation

PowerPoint Presentation Package Class 1 Heeseung Jo 목차 section 1 패키지개요와패키지의사용 section 2 java.lang 패키지의개요 section 3 Object 클래스 section 4 포장 (Wrapper) 클래스 section 5 문자열의개요 section 6 String 클래스 section 7 StringBuffer 클래스 section

More information

예외 예외정의예외발생예외처리예외전파 단정 단정의선언 단정조건검사옵션 2

예외 예외정의예외발생예외처리예외전파 단정 단정의선언 단정조건검사옵션 2 예외 예외정의예외발생예외처리예외전파 단정 단정의선언 단정조건검사옵션 kkman@sangji.ac.kr 2 예외 (exception) 실행시간에발생하는에러 (run-time error) 프로그램의비정상적인종료잘못된실행결과 예외처리 (exception handling) 기대되지않은상황에대해예외를발생야기된예외를적절히처리 (exception handler) kkman@sangji.ac.kr

More information

<4D F736F F F696E74202D20B8AEB4AABDBA20BFC0B7F920C3B3B8AEC7CFB1E22E BC8A3C8AF20B8F0B5E55D>

<4D F736F F F696E74202D20B8AEB4AABDBA20BFC0B7F920C3B3B8AEC7CFB1E22E BC8A3C8AF20B8F0B5E55D> 리눅스 오류처리하기 2007. 11. 28 안효창 라이브러리함수의오류번호얻기 errno 변수기능오류번호를저장한다. 기본형 extern int errno; 헤더파일 라이브러리함수호출에실패했을때함수예 정수값을반환하는함수 -1 반환 open 함수 포인터를반환하는함수 NULL 반환 fopen 함수 2 유닉스 / 리눅스 라이브러리함수의오류번호얻기 19-1

More information

C 프로그래밍 언어 입문 C 프로그래밍 언어 입문 김명호저 숭실대학교 출판국 머리말..... C, C++, Java, Fortran, Python, Ruby,.. C. C 1972. 40 C.. C. 1999 C99. C99. C. C. C., kmh ssu.ac.kr.. ,. 2013 12 Contents 1장 프로그래밍 시작 1.1 C 10 1.2 12

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 SIGPL Summer Workshop 2017 C++ 메타프로그래밍과 constexpr 김경진 Astersoft Microsoft MVP(Visual C++) Agenda 메타프로그래밍 템플릿메타프로그래밍 constexpr 메타프로그래밍 meta- < 초월한 > < ~ 의범주를넘어서는 > 메타프로그래밍 metaphysics 일반적물리학범주를넘어서는학문 형이상학

More information

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

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

More information

C++ Programming

C++ Programming C++ Programming C++ 스타일의입출력 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 C 스타일의입출력 C++ 스타일의입출력 2 C 스타일의입출력 #include C 스타일의입출력 int main() { int a, b, c; printf(" 세개의정수입력 : "); scanf("%d

More information

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

프입2-강의노트-const-friend-static Chapter 05. const, friend, static 박종혁교수 UCS Lab Tel: 970-6702 Email: jhpark1@seoultech.ac.kr SeoulTech 2018-2 nd 프로그래밍입문 (2) Chapter 05-1. const 멤버변수, 함수, 객체 const 멤버변수 멤버변수에 const 를붙이는경우 class Car public:

More information

C++-¿Ïº®Çؼ³10Àå

C++-¿Ïº®Çؼ³10Àå C C++. (preprocessor directives), C C++ C/C++... C++, C. C++ C. C C++. C,, C++, C++., C++.,.. #define #elif #else #error #if #itdef #ifndef #include #line #pragma #undef #.,.,. #include #include

More information

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074>

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

More information