1 Star 0 Fork 1

llongger/Code_C++

forked from GodOuO/Code_C++ 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
39.Calculator_normal.cpp 1022 Bytes
一键复制 编辑 原始数据 按行查看 历史
GodOuO 提交于 2023-03-15 04:07 . Train
#include<iostream>
#include<string>
using namespace std;
//普通案例,设计实现两个操作数进行运算的计算机类
class Calculator
{
private:
int m_Num1;
int m_Num2;
public:
void setNum(int num1,int num2);
int getNum1();
int getNum2();
int getResult(string oper);
};
void Calculator::setNum(int num1,int num2){
m_Num1 = num1;
m_Num2 = num2;
}
int Calculator::getNum1(){
return m_Num1;
}
int Calculator::getNum2(){
return m_Num2;
}
int Calculator::getResult(string oper){
if("+" == oper)
return m_Num1+m_Num2;
else if("-" == oper)
return m_Num1-m_Num2;
else if("*" == oper)
return m_Num1*m_Num2;
else
return 0;
}
void test01(){
Calculator c;
c.setNum(10,10);
cout<<c.getNum1()<<" + "<<c.getNum2()<<" = "<<c.getResult("+")<<endl;
cout<<c.getNum1()<<" - "<<c.getNum2()<<" = "<<c.getResult("-")<<endl;
cout<<c.getNum1()<<" * "<<c.getNum2()<<" = "<<c.getResult("*")<<endl;
}
int main(){
test01();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/llongger/codeCpp.git
[email protected]:llongger/codeCpp.git
llongger
codeCpp
Code_C++
master

搜索帮助