C++/설명 범범조조 2016. 4. 19. 21:26
-인터 페이스#include #include using namespace std; #define interface structinterface IPlay{ virtual void Play() = 0;}; //#define interface class //class를 이용하여 인터페이스를 만듬//interface IPlay//{//public:// virtual void Play() = 0;//} class Man:public IPlay{ string name;public: Man(string name) { this->name = name; } virtual void Play() { cout
더 읽기
-하향 캐스팅#include #include using namespace std; class Musician{ string name;public: Musician(string name) { this->name = name; } virtual void Play() = 0; //순수 가상 메소드(추상 클래스)(기능 구현을위한 약속 메소드) void Introduce() { coutIntroduce(); //실행 시간에 musician이 Pianist인지 확인하여 하향 캐스팅 //만약 피아니스트가 아니면 캐스팅 실패하고 0을 반환함 //Pianist *pianist = (*Pianist)musician; //CPP에서는 강제 형변환을 사용하지 마세요 Pianist *pianist = dynamic_cast(m..
C++/설명 범범조조 2016. 4. 19. 21:25
-무효화//무효화#include #include using namespace std; class Programmer{public: void Programming() { coutProgramming(2); Programmer *pro = ehp; pro->Programming(); pro->Programming(3); delete ehp; return 0;}
C++/설명 범범조조 2016. 4. 19. 21:24
-형식의 다형성#include #include using namespace std; class Musician{ string name;public: Musician(string name) { this->name = name; } void Play() { coutPlay();} void StartConcert(Musician &musician){ musician.Play();}
-메소드의 다형성 #include #include using namespace std; class Musician{ string name;public: Musician(string name) { this->name = name; } virtual void Play() { coutIntroduce(); musician->Play();} void StartConcert(Musician &musician){ musician.Introduce(); musician.Play();}
C++/설명 범범조조 2016. 4. 19. 21:23
-다중 상속#include #include using namespace std; class Man{ string name;public: Man(string name) { this->name = name; } void View() { coutView(); delete bbps; return 0;}
C++/설명 범범조조 2016. 4. 19. 21:22
-상속 일반화 개요//상속 개요#include #include using namespace std; class Musician{ public: void Play() { cout
C++/설명 범범조조 2016. 4. 19. 21:21
-C++에서의 형변환 //static_cast#include #include using namespace std; class Man{ string name;public: Man(string name) { this->name = name; } void View()const { coutStudy(); delete man; return 0;}
C++/설명 범범조조 2016. 4. 19. 21:18
-캡슐화 실습(학생) 시나리오학생은 생성할 때 학생 이름을 전달받습니다.그리고 학생 번호는 순차적으로 부여합니다.이 외에 학생의 국어, 영어, 수학 성적을 -1로 설정 합니다. 학생을 생성한 후에는 학생의 국어, 영어, 수학 성적을 입력할 수 있습니다. 만약 학생 성적이 0에서 100을 벗어나면 -1로 설정합니다. 학생 이름과 번호, 각 과목의 성적과 총점 및 평균을 확인할 수 있습니다. 그리고 전체 학생 수를 확인할 수 있습니다. 그리고 학생 정보를 출력하는 기능을 제공합니다. //Student.h#pragma once#include #include using namespace std; enum SIndex //과목 열거형{ KOREAN, ENGLISH, MATH, MAX_SUBJECT}; class ..
C++/설명 범범조조 2016. 4. 19. 21:16
-캡슐화 실습(학생 성적) //Student.h#pragma once#include #include using namespace std; class Student{ static int last_num; //학생 번호 정적으로 선언 int number; //학생 번호 string name;//학생 이름 int kor; int eng; int math; static const int Def_Kor; //국어점수 디폴트 값 static const int Def_Eng; static const int Def_Math; int sum; double average;public: static int GetStuCount();//정적 메서드 Student(string name); void SetKor(int kor);..
C++/설명 범범조조 2016. 4. 19. 21:14
-캡슐화 실습(복소수)//Complex.h#pragma once#include #include using namespace std; class Complex{ double image; double real;public: Complex(double image = 0, double real = 0); double GetImage(); double GetReal(); void SetImage(double image); void SetReal(double real); const void View();}; //Complex.cpp#include "Complex.h" Complex::Complex(double real , double image ){ SetReal(real); SetImage(image);}doub..
C++/설명 범범조조 2016. 4. 19. 21:12
-복사 생성자//복사 생성자가 필요할 때(개체 내부에 동적으로 생성한 다른 개체를 가질 때)#include using namespace std; class DArray{ int *base; //저장소의 위치 int bcapacity; //저장소의 크기 int usage; //보관 개수public: DArray(int _bcapa) //생성자 { base = new int[_bcapa];//버퍼 동적 할당 bcapacity = _bcapa; usage =0; } DArray(const DArray &src)//복사 생성자(깊은 복사) { base = new int[src.bcapacity]; bcapacity = src.bcapacity; for(usage = 0; usage < src.usage; usa..