69 lines
1.7 KiB
C++
69 lines
1.7 KiB
C++
#include <iostream>
|
|
#include "basecalc.h"
|
|
#include "special_calculator.h"
|
|
#include <memory>
|
|
#include "input_resolver.h"
|
|
|
|
int main()
|
|
{
|
|
std::unique_ptr<BaseCalculator> calc = std::make_unique<SpecialCalculator>();
|
|
|
|
std::cout << "Initializing calculator";
|
|
|
|
while (true)
|
|
{
|
|
std::cout << "What's your next input? (+,-,*,/,%,$,q,p)" << std::endl;
|
|
auto command = resolveCommand();
|
|
|
|
if (command.shouldTerminate())
|
|
{
|
|
break;
|
|
}
|
|
|
|
switch(command.getNextChar())
|
|
{
|
|
case '+':
|
|
{
|
|
calc->calculate({OpType::Addition, static_cast<int>(*calc), command.getNextArg()});
|
|
}
|
|
break;
|
|
|
|
case '-':
|
|
{
|
|
calc->calculate({OpType::Subtraction, static_cast<int>(*calc), command.getNextArg()});
|
|
}
|
|
break;
|
|
|
|
case '*':
|
|
{
|
|
calc->calculate({OpType::Multiplication, static_cast<int>(*calc), command.getNextArg()});
|
|
}
|
|
break;
|
|
|
|
case '/':
|
|
{
|
|
calc->calculate({OpType::Division, static_cast<int>(*calc), command.getNextArg()});
|
|
}
|
|
break;
|
|
|
|
case '%':
|
|
{
|
|
calc->calculate({OpType::Modulo, static_cast<int>(*calc), command.getNextArg()});
|
|
}
|
|
break;
|
|
|
|
case '$':
|
|
{
|
|
calc->calculate({OpType::Special, static_cast<int>(*calc)});
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
if(command.shouldPrint())
|
|
std::cout << "Intermediary result: " << static_cast<int>(*calc) << std::endl;
|
|
}
|
|
|
|
std::cout << "Final output: " << static_cast<int>(*calc) << std::endl;
|
|
return 0;
|
|
} |