本文整理汇总了C++中Operation::GetResult方法的典型用法代码示例。如果您正苦于以下问题:C++ Operation::GetResult方法的具体用法?C++ Operation::GetResult怎么用?C++ Operation::GetResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Operation
的用法示例。
在下文中一共展示了Operation::GetResult方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
Operation* pOper = OperationFactory::createOperate("/");
pOper->SetNumberA(3);
//pOper->SetNumberB(9.8);
double ret;
ret = pOper->GetResult();
cout << "Result: " << ret << endl;
delete pOper;
return 0;
}
示例2: Calculate
//将参数中的两个数字和一个运算符进行运算,返回结果
double Calculator::Calculate(double numA, double numB, OperationFactory::OPERATION op)
{
Operation* pOper = m_opFac.CreateOperation(op, numA, numB);
//考虑除数为0的情况
if ( (op == OperationFactory::OPER_DIV) &&
(numB <= 0.000001 && numB >= -0.000001) )
{
m_strErrorInfo = "除数不能为0!";
return 0.0;
}
double rtval = pOper->GetResult();
delete pOper;
pOper = NULL;
return rtval;
}
示例3: main
int main(int argc, char* argv[])
{
Operation oper;
int numA = 0;
int numB = 0;
int res = 0;
numA = atoi(argv[1]);
numB = atoi(argv[3]);
if (0 != CreateOperation(&oper, argv[2][0]))
{
printf("创建运算失败.\n");
return -1;
}
res = oper.GetResult(numA, numB);
printf("result is %d.\n", res);
return 0;
}
示例4: main
int main(int argc, char* argv[])
{
int a = 0;
int b = 0;
char op = 0;
std::string line;
std::getline(std::cin, line);
std::string op1, op2, op3;
int max_ops = 3;
bool b_reading_val = false;
for (size_t i = 0; i != line.size(); i++) {
char c = line[i];
if (c == '\t')
return 0;
else if (my_is_digit(c)) {
b_reading_val = true;
if (max_ops == 3) {
op1 += c;
} else if (max_ops == 2) {
return 0;
} else if (max_ops == 1) {
op3 += c;
} else if (max_ops == 0) {
return 0;
}
} else if (my_is_operand(c)) {
if (b_reading_val) {
b_reading_val = false;
max_ops--;
}
if (max_ops != 2) {
return 0;
}
op2 = c;
max_ops--;
} else {
if (b_reading_val) {
b_reading_val = false;
max_ops--;
}
}
}
//line >> a >> op >> b;
/*int ret = sscanf(line.c_str(), "%d %c %d", &a, &op, &b);
if (ret == 0 || ret == EOF) {
return 0;
}*/
a = atoi(op1.c_str());
op = op2.c_str()[0];
b = atoi(op3.c_str());
if (!is_valid_value(a) || !is_valid_value(b)) {
//std::cout << "You must input 2 positive integers." << std::endl;
} else {
Operation *operation = OperationFactory::CreateOperation(op);
if (operation) {
operation->m_number1 = a;
operation->m_number2 = b;
long long result = operation->GetResult();
std::cout << result << std::endl;
delete operation;
} else {
//std::cout << "Illegal expression." << std::endl;
}
}
//getchar();
return 0;
}