完善下面的代码,使程序能够正常运行。要求 BaseCalculator 类中提供 getResult() 函数(无需实现),在 AddCalculator 类中实现两个成员相加(m_A + m_B),在 SubCalculator 类中实现两个成员相减(m_A - m_B)
输入描述:
无
输出描述:
程序已经给定输出
加载中...
#include
using namespace std; class BaseCalculator { public: int m_A; int m_B; // write your code here...... }; // 加法计算器类 class AddCalculator : public BaseCalculator { // write your code here...... }; // 减法计算器类 class SubCalculator : public BaseCalculator { // write your code here...... }; int main() { BaseCalculator* cal = new AddCalculator; cal->m_A = 10; cal->m_B = 20; cout << cal->getResult() << endl; delete cal; cal = new SubCalculator; cal->m_A = 20; cal->m_B = 10; cout << cal->getResult() << endl; delete cal; return 0; }