// ============================================================================
//  p1c04_08_01  —  4.8.1 多态基本概念
//  来源：川大 C++/LinuxC wiki「02.Qt方向」
//  说明：本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用
//        // --- 原文片段 [pageId:blockIdx] --- 标注出处。
//        已做最小修正（笔误/平台移植），详见 docs/ERRATA.md。
// ============================================================================

#include <iostream>
using namespace std;

// --- 原文片段 [58954469:0]  4.8.1 多态基本概念 ---
//计算器
class Caculator{
public:
	void setA_1(int a){
		this->mA = a;
	}
	void setB(int b){
		this->mB = b;
	}
	void setOperator(string oper){
		this->mOperator = oper;
	}
	int getResult_2(){
		
		if (this->mOperator == "+"){
			return mA + mB;
		}
		else if (this->mOperator == "-"){
			return mA - mB;
		}
		else if (this->mOperator == "*"){
			return mA * mB;
		}
		else if (this->mOperator == "/"){
			return mA / mB;
		}
	}
private:
	int mA;
	int mB;
	string mOperator;
};

//这种程序不利于扩展，维护困难，如果修改功能或者扩展功能需要在源代码基础上修改
//面向对象程序设计一个基本原则:开闭原则(对修改关闭，对扩展开放)

//抽象基类
class AbstractCaculator{
public:
	void setA_1(int a){
		this->mA = a;
	}
	virtual void setB(int b){
		this->mB = b;
	}
	virtual int getResult_2() = 0;
protected:
	int mA;
	int mB;
	string mOperator;
};

//加法计算器
class PlusCaculator : public AbstractCaculator{
public:
	virtual int getResult_2(){
		return mA + mB;
	}
};

//减法计算器
class MinusCaculator : public AbstractCaculator{
public:
	virtual int getResult_2(){
		return mA - mB;
	}
};

//乘法计算器
class MultipliesCaculator : public AbstractCaculator{
public:
	virtual int getResult_2(){
		return mA * mB;
	}
};

void DoBussiness(AbstractCaculator* caculator){
	int a = 10;
	int b = 20;
	caculator->setA_1(a);
	caculator->setB(b);
	cout << "计算结果：" << caculator->getResult_2() << endl;
	delete caculator;
}

// --- main ---
int main() {
    return 0;
}
