언어 썸네일형 리스트형 7장1번~4번 도서 관리 시스템 (연산자 중복) #include #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ class Book { string title; int price; int pages; public : Book(string title="", int price=0, int pages=0){ this->title=title; this->price=price; this->pages=pages; } void show(){ cout 더보기 책 제목 사전 순으로 비교하기 #include #include using namespace std; class Book { string name; int price; int page; public: Book(string name, int price ,int page){ this->name=name; this->price=price; this->page=page; } string getTitle(){ return name; } bool operator b.getTitle().substr(0,1) ){ return true; }else { return false; } } }; int main(){ Book a ("청춘",20000,300); string b; cout 더보기 프렌드 함수 프랜드함수: 클래스 내에 friend 키워드로 선언된 외부 함수 두 Rect 객체를 비교하는 bool equals (Rect r ,Rect s ) 를 Rect 클래스에 프랜드 함수로 작성하기 #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ class Rect{ int width; int height; public: Rect(int width, int height){ this->width=width; this->height=height; } friend bool equals(Rect r, Rect s); }; bool eq.. 더보기 외장함수 #외장함수: 외부에 있는 모듈 p파일을 호출함 import sys #sys.exit() 현재 스크립트를 종료 print("나 종료할거에요") #sys.exit() print("아직 살아있어요 ") #sys.path : 파이썬 모듈들의 위치를 배열로 가지고 있음 print(sys.path) #sys.argv : 실행파일 실행시 매개변수를 가지고 있음 #테스트 방법 :커맨드 창에서 python ex21.py param1 param2 print(sys.argv) #pickle() : 파일을 객체로 읽어오도록 해줌 # 객체로 저장하기 import pickle # file=open('pickle.txt','wb') #wb : 쓰기 모드, binary # data ={1:'python ', 2:'programmin.. 더보기 내장함수 #내장함수 #abs() : 절대값을 리턴함 print(abs(10)) print(abs(-10)) print(abs(-3.14)) #all() : 값이 모두 참이면 true 거짓이 하나라도 있으면 false # 모든 값에 대하여 and 연산한 것 # 반복 가능한 자료형에 대해서 :리스트 ,딕셔너리 array=[1.2,3] print(all(array)) array=["hong","tom",""] print(all(array)) array=[1,2,0] print(all(array)) #참인지 거짓인지 에 대한 자료형 #ex10 예제 참조 #참인 자료형 (true) 거짓인자료형 (false) #"python" ""반문자열은 false # [1,2,3] []빈 배열은 false # ()빈 튜플은 false .. 더보기 4장 예제- 면적 조건에 따른 원의 개수 구하기 #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ class Circle{ private : int radius; public: Circle(); ~Circle(); void setRadius(int r){ radius=r; } double getArea() { return 3.14*radius*radius; } }; Circle:: Circle(){ radius=1; } int main(int argc, char** argv) { int num; int radius; int count=0; cout > num; Circl.. 더보기 반복문~ 함수~ 예외처리 #예외 처리 try: 10/0 except ZeroDivisionError as e: print(e) try: file=open('없는 파일.txt' ,'r') except FileNotFoundError as e : #오류 발생 시 실행하는 블럭 print(str(e)) else: #오류가 발생안하면 실행하는 블럭 data=file.readLine() file.close try: #오류를 일부러 발생시키기 raise NotImplementedError print("실행문") except e: print("오류 발생함 ") print(e) else: print("오류 발생안함") finally: #리소스를 정리 print("오류 발생 하든 안하든 수행함 ") import ex17_imported ex17.. 더보기 6장 6번 - 정수 배열 합치기, 빼기 #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ class ArrayUtility2{ public: static int*concat(int s1[], int s2[], int size){ int *s3= new int [size]; int j=0; for(int i=0; i 더보기 이전 1 2 3 4 5 6 7 다음