본문 바로가기
반응형

전체 글186

16_클래스기본구조 // 맴버함수의 외부 정의 #include using namespace std; class Member { private: string name; string number; public: Member() { name = ""; number = ""; } Member(string _name, string _number) { name = _name; number = _number; } public: string getName() { return name; } string getNumber() { return number; } void setName(string value) { name = value; } void setNumber(string value) { number = value; } public: v.. 2018. 4. 30.
자판기프로그램(mini) //소스.cpp #include using namespace std; #include "DrinkmachineControl.h" int MenuPrint(); int main() { DrinkmachineControl *c = new DrinkmachineControl; int idx; while (true) { system("cls"); c->Print(); idx = MenuPrint(); switch (idx) { case 1: c->InputMoney(); break; case 2: c->SelectProduct(); break; case 3: c->OutputMoney(); break; case 4: return 0; } system("pause"); } delete c; return 0; } .. 2018. 4. 30.
15_생성자오버로딩 #include using namespace std; /* 생성자 목적 : 개체 초기화(맴버 변수 초기화) 성질 : 개체 생성시 자동으로 호출된다. 개체 생성 단계 1) 메모리 생성 2) 생성자 호출 */ class Account { private: string name; int id; int balance; public: //생성자 : 함수의 일종(반환이 없다.) Account() { cout 2018. 4. 30.
14_생성자 #include using namespace std; /* 생성자 목적 : 개체 초기화(맴버 변수 초기화) 성질 : 개체 생성시 자동으로 호출된다. 개체 생성 단계 1) 메모리 생성 2) 생성자 호출 */ class Account { private: string name; int id; int balance; public: //생성자 : 함수의 일종(반환이 없다.) Account() { cout 2018. 4. 30.
13_데이터은닉 #include using namespace std; //캡슐화와 데이터 은닉 //데이터 은닉이 왜 필요할까? // 객체의 불안정성 방지 class Stu { private: int iq; // iq ( 100 ~ 150 ) public: void Init(int value) { iq = value; } void Study(int tcnt) { iq += tcnt; Print(); } void Game(int tcnt) { iq -= tcnt; Print(); } private: void Print() { cout 2018. 4. 29.
12_클래스 #include using namespace std; /* 접근지정자 private : 은닉, 외부에서 접근 불가 public : 공용, 누구나 접근 가능 데이터 은닉..... 맴버 변수는 가능한 숨겨야 한다. */ class Account { private: string name; //STL에서 지원하는 문자열 int acc_id; int balance; public: Account(string Aname, int Aacc_id, int Abalance) { name = Aname; acc_id = Aacc_id; Abalance = balance; } public: void AddMoney(int money) { balance = balance + money; } void MinMoney(int mo.. 2018. 4. 29.
11_C++구조체 #include using namespace std; /* 계좌 만들기(데이터, 함수) 개체명 : Account 데이터 : 이름,계좌ID,잔액 함수 : 입금, 출금, 데이터출력 */ struct Account { string name; //STL에서 지원하는 문자열 int acc_id; int balance; void AddMoney(int money) { balance = balance + money; } void MinMoney(int money) { balance -= money; } void Print() { cout 2018. 4. 29.
10_날짜활용실습(3단계) #include using namespace std; /* 1. 날짜를 관리하는 프로그램 오늘날짜, 내일날짜...(일반변수) */ //step1) void today(int *y, int *m, int *d) { *y = 2016; *m = 7; *d = 13; } void print(int y, int m, int d) { cout 2018. 4. 29.
09_기본값 #include using namespace std; /* 기본값 : 매개변수가 전달인자가 없을경우 처리하는 값 */ /* void foo(int n1 =1, int n2 = 2){} //3 //void foo(char ch) {} //4 int main() { foo(); //n1 =1, n2 = 2 foo(10); //n1 =10, n2 = 2 foo(10, 20); //n1 =10, n2 = 20 return 0; } */ //기본값은 반드시 매개변수 뒤에서부터... void foo(int n = 10, int n1) {} void main() { foo(20, 30); //? } 2018. 4. 29.
반응형