~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;
}


상욱형이 짜주신 계산기 메인은 짧은데 클래스 길이가;;;
MFCStudy2006/Class로 계산기 짜기 <- 이런 이름이 더 좋을듯 싶네요^^ - 아영
----
MFC Study 2006
Retrieved from http://wiki.zeropage.org/wiki.php/Class로 계산기 짜기
last modified 2021-02-07 05:22:53