~cpp #include <iostream> using namespace std; class Memory { private: int firstNumber; int secondNumber; int resultNumber; char sign; public: void setFirstNumber(int firstNumber){ this->firstNumber = firstNumber;} void setSecondNumber(int secondNumber){ this->secondNumber = secondNumber;} void setResultNumber(int resultNumber){ this->resultNumber = resultNumber;} void setSign(char sign){ this->sign = sign;} int getFirstNumber(){ return firstNumber;} int getSecondNumber(){ return secondNumber;} int getResultNumber(){ return resultNumber;} char getSign(){ return sign;} }; class NumberInputer { public: void pushButton(Memory * memory) { inputFirstNumber(memory); inputSecondNumber(memory); inputSign(memory); } void inputFirstNumber(Memory * memory) { int firstNumber; cin >> firstNumber; memory->setFirstNumber(firstNumber); } void inputSecondNumber(Memory * memory) { int secondNumber; cin >> secondNumber; memory->setSecondNumber(secondNumber); } void inputSign(Memory * memory) { char sign; cin >> sign; switch(sign) { case '+': case '-': case '*': case '/': memory->setSign(sign); break; default: cout << "입력이 잘못되었습니다." << endl; exit(0); } } }; class ComputeDevice { public: void compute(Memory * memory) { switch(memory->getSign()) { case '+': memory->setResultNumber(memory->getFirstNumber() + memory->getSecondNumber()); break; case '-': memory->setResultNumber(memory->getFirstNumber() - memory->getSecondNumber()); break; case '*': memory->setResultNumber(memory->getFirstNumber() * memory->getSecondNumber()); break; case '/': memory->setResultNumber(memory->getFirstNumber() / memory->getSecondNumber()); break; } } }; class Lcd { public: void output(Memory * memory) { cout << memory->getResultNumber() << endl;} }; class Calculator { private: NumberInputer numberInputer; ComputeDevice computeDevice; Lcd lcd; Memory * memory; public: Calculator() { memory = new Memory; } void create() { numberInputer.pushButton(memory); computeDevice.compute(memory); lcd.output(memory); } ~Calculator() { delete memory; } }; int main() { Calculator calculator; calculator.create(); return 0; }
- 그냥 보여주기 위한 코드에요. 결코 올바른 프로그래밍은 아니라는거 명심하세요^^; - 상욱
----
MFC Study 2006