Updated how results are retrieved

This commit is contained in:
2020-07-20 00:53:08 -04:00
parent 22871b71e9
commit 2616dabe6d
67 changed files with 132 additions and 434 deletions

View File

@@ -66,6 +66,15 @@ void Problem9::solve(){
//Stop the timer
timer.stop();
//Save the results
if(found){
result << "The Pythagorean triplet is " << a << ' ' << b << ' ' << (int)c
<< "\nThe numbers' product is " << a * b * (int)c;
}
else{
result << "The number was not found!";
}
//Throw a flag to show the problem is solved
solved = true;
}
@@ -79,24 +88,6 @@ void Problem9::reset(){
found = false;
}
//Return a string with the solution to the problem
std::string Problem9::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
if(found){
results << "The Pythagorean triplet is " << a << ' ' << b << ' ' << (int)c
<< "\nThe numbers' product is " << a * b * (int)c;
}
else{
results << "The number was not found!";
}
return results.str();
}
//Returns the length of the first side
int Problem9::getSideA() const{
//If the problem hasn't been solved throw an exception