Search
Duplicate
🔢

8장. 수업 코드

생성일
2022/05/02 05:55
태그
C++

8장. 수업 코드

예제 8-3 생성자 매개 변수 전달

TV, WideTV, SmartTV

TV.h

// #ifndef __TV_H #define __TV_H #include <iostream> using namespace std; class TV { int size; public: TV() { size = 20; } TV(int size) { this->size = size; cout << "TV 생성자" << endl;} ~TV() { cout << "TV 소멸자" << endl; } int getSize() { return size; } }; #endif
C++
복사

WideTV.h

#ifndef __WIDETV_H #define __WIDETV_H #include "TV.h" class WideTV : public TV{ bool videoIn; public: WideTV(int size, bool videoIn) : TV(size) { this->videoIn = videoIn; cout << "WideTV 생성자" << endl; } ~WideTV() { cout << "WideTV 소멸자" << endl; } bool getVideoIn() { return videoIn; } }; #endif
C++
복사

SmartTV.h

#ifndef __SMARTTV_H #define __SMARTTV_H #include "WideTV.h" #include <string> using namespace std; class SmartTV : public WideTV { string ipAddr; public: SmartTV(string ipAddr, int size) : WideTV(size, true) { this->ipAddr = ipAddr; cout << "SmartTV 생성자" << endl; } ~SmartTV() { cout << "SmartTV 소멸자" << endl; } string getIpAddr() { return ipAddr; } }; #endif
C++
복사

MyStack.cpp

#include "MyStack.h" #include <iostream> using namespace std; MyStack::MyStack(int capacity) : BaseArray(capacity) { top = 0; } void MyStack::push(int n) { // 스택 다 찼나? if (top == getCapacity()) { cout << "Stack Full!!" << endl; return; } put(top, n); // top에다가 n값을 넣어라 //top++; } int MyStack::capacity() { return getCapacity(); } int MyStack::length() { return top; } int MyStack::pop() { // 스택 비어있는지? if (top == 0) { cout << "Stack Empty!!" << endl; return -1; } //top--; return get(--top); }
C++
복사