Files
ProjectEulerCPP/Headers/Problem.hpp

70 lines
1.9 KiB
C++

//ProjectEuler/ProjectEulerCPP/Headers/Problem.hpp
//Matthew Ellison
// Created: 07-04-19
//Modified: 07-09-20
//This is an abstract base class to allow polymorphism for the individual problems
/*
Copyright (C) 2020 Matthew Ellison
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PROBLEM_HPP
#define PROBLEM_HPP
#include <string>
#include "Stopwatch.hpp"
class Problem{
protected:
const std::string description; //Holds the description of the problem
mee::Stopwatch timer; //Used to determine your algorithm's run time
bool solved; //Holds true after the problem has been solved
class unsolved{}; //An exception class thrown if you try to access something before it has been solved
public:
//Constructors
Problem() : solved(false){
}
Problem(std::string description) : description(description), solved(false){
}
//Destructor
virtual ~Problem(){
}
//Gets
virtual std::string getDescription() const{
return description;
}
virtual std::string getTime(){
return timer.getStr();
}
virtual mee::Stopwatch getTimer(){
return timer;
}
//Reset the problem so it can be run again
virtual void reset(){
timer.reset();
solved = false;
}
//Pure virtual functions
virtual void solve() = 0; //Solve the problem
virtual std::string getString() const = 0; //Return a string with the solution to the problem
};
#endif //PROBLEM_HPP