본문 바로가기

언어

5장 예제- 복사 생성자 오빠 동생 복사 -깊은 복사 #include #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ class Person{ private : char *name; int id; public: Person(int id, char*name); Person(Person& person); // 복사 생성자 ~Person(); void changeName(char*name); void show() {cout id=person.id; int len=strlen(person.name); this->name=new char[len+1]; strcpy(this->name.. 더보기
5장 예제- 복사 생성자 오빠 동생 복사 - 얕은 복사 #include #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ class Person{ private : char *name; int id; public: Person(int id, char*name); ~Person(); void changeName(char*name); void show() {cout strlen(this->name)) { return; } strcpy(this->name, name); } int main(){ Person brother(1,"돌딸기"); Person sister(brother); c.. 더보기
5장 7번 - 덧셈 계산기 만들기 #include using namespace std; class Accumulator { int value; public : Accumulator(int value){ this->value = value; } Accumulator& add(int n){ value += n; return *this; } int get(){ return value; } }; int main() { Accumulator acc(10); acc.add(5).add(6).add(7); cout 더보기
5장 5번 - 스택에 데이터 삽입,삭제 #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ class MyIntStack{ int *p; int max=10; int top=0; int size; public: MyIntStack(){ p=new int[max]; } ~MyIntStack(){ delete[] p; } bool push(int n); bool pop(int &n); }; bool MyIntStack:: push(int n){ if(top==max){ return false; } else{ p[top]=n; top++; return true; } }.. 더보기
자판기 프로그램 만들기 ! coffee=3 cola=2 juice=1 coffeeMoney=1000 colaMoney=800 juiceMoney=700 while True: menu=input("메뉴를 입력하세요: ") moneyString=input("금액을 입력하세요: ") money=int(moneyString) if menu=="커피": print(menu) if money 더보기
5장 4번- Ogdol -> Okdol 단어 알파벳 바꾸기 #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ char& find(char a[], char c, bool& success); char& find(char a[], char c, bool& success){ for(int i=0; i 더보기
5장 2번- 더 큰 수 비교하기 (참조 매개변수) #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ bool bigger(int a, int b, int& big); bool bigger(int a, int b, int& big){ big=a; if(a 더보기
5장 1번 - 참조 매개변수 이용해서 swap #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ void swap(int &n,int &m){ int temp; temp=n; n=m; m=temp; }; int main(int argc, char** argv) { int a =1; int b= 10; cout 더보기