diff --git a/ProblemSelection.hpp b/ProblemSelection.hpp index 616345d..855dd8a 100644 --- a/ProblemSelection.hpp +++ b/ProblemSelection.hpp @@ -5,9 +5,43 @@ //This is a header file with a few functions to help select and run problems +#ifndef PROBLEMSELECTION_HPP +#define PROBLEMSELECTION_HPP + #include -#include "Problems.hpp" #include "Algorithms.hpp" +#include "Headers/Problem1.hpp" +#include "Headers/Problem2.hpp" +#include "Headers/Problem3.hpp" +#include "Headers/Problem4.hpp" +#include "Headers/Problem5.hpp" +#include "Headers/Problem6.hpp" +#include "Headers/Problem7.hpp" +#include "Headers/Problem8.hpp" +#include "Headers/Problem9.hpp" +#include "Headers/Problem10.hpp" +#include "Headers/Problem11.hpp" +#include "Headers/Problem12.hpp" +#include "Headers/Problem13.hpp" +#include "Headers/Problem14.hpp" +#include "Headers/Problem15.hpp" +#include "Headers/Problem16.hpp" +#include "Headers/Problem17.hpp" +#include "Headers/Problem18.hpp" +#include "Headers/Problem19.hpp" +#include "Headers/Problem20.hpp" +#include "Headers/Problem21.hpp" +#include "Headers/Problem22.hpp" +#include "Headers/Problem23.hpp" +#include "Headers/Problem24.hpp" +#include "Headers/Problem25.hpp" +#include "Headers/Problem26.hpp" +#include "Headers/Problem27.hpp" +#include "Headers/Problem28.hpp" +#include "Headers/Problem29.hpp" +#include "Headers/Problem30.hpp" +#include "Headers/Problem31.hpp" +#include "Headers/Problem67.hpp" //Setup the problem numbers @@ -92,4 +126,6 @@ void listProblems(){ std::cout << ", " << PROBLEM_NUMBERS[problemNumber]; } std::cout << std::endl; -} \ No newline at end of file +} + +#endif //PROBLEMSELECTION_HPP diff --git a/Problems.hpp b/Problems.hpp deleted file mode 100644 index 3b0effc..0000000 --- a/Problems.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "Headers/Problem1.hpp" -#include "Headers/Problem2.hpp" -#include "Headers/Problem3.hpp" -#include "Headers/Problem4.hpp" -#include "Headers/Problem5.hpp" -#include "Headers/Problem6.hpp" -#include "Headers/Problem7.hpp" -#include "Headers/Problem8.hpp" -#include "Headers/Problem9.hpp" -#include "Headers/Problem10.hpp" -#include "Headers/Problem11.hpp" -#include "Headers/Problem12.hpp" -#include "Headers/Problem13.hpp" -#include "Headers/Problem14.hpp" -#include "Headers/Problem15.hpp" -#include "Headers/Problem16.hpp" -#include "Headers/Problem17.hpp" -#include "Headers/Problem18.hpp" -#include "Headers/Problem19.hpp" -#include "Headers/Problem20.hpp" -#include "Headers/Problem21.hpp" -#include "Headers/Problem22.hpp" -#include "Headers/Problem23.hpp" -#include "Headers/Problem24.hpp" -#include "Headers/Problem25.hpp" -#include "Headers/Problem26.hpp" -#include "Headers/Problem27.hpp" -#include "Headers/Problem28.hpp" -#include "Headers/Problem29.hpp" -#include "Headers/Problem30.hpp" -#include "Headers/Problem31.hpp" -#include "Headers/Problem67.hpp" diff --git a/benchmark.cpp b/benchmark.hpp similarity index 82% rename from benchmark.cpp rename to benchmark.hpp index ca08e3e..bca1366 100644 --- a/benchmark.cpp +++ b/benchmark.hpp @@ -1,65 +1,66 @@ -//ProjectEulerCPP/benchmark.cpp +//ProjectEulerCPP/benchmark.hpp //Mattrixwv // Created: 07-08-20 //Modified: 07-08-20 //This is a program that runs a problem several times to get the average time it takes to run +#ifndef BENCHMARK_HPP +#define BENCHMARK_HPP + #include #include #include "ProblemSelection.hpp" -void printMenu(); //Prints the menu to the screen -int getMenuSelection(); //Returns a valid menu option -bool isValidMenu(int selection); //Determines if a value is a valid menu option. Helper for getMenuSelection +void printBenchmarkMenu(); //Prints the menu to the screen +int getBenchmarkMenuSelection(); //Returns a valid menu option +bool isValidBenchmarkMenu(int selection); //Determines if a value is a valid menu option. Helper for getBenchmarkMenuSelection void runSpecific(); //Determines which problem user wants to run and runs it void runAllShort(); //Runs all problems except a few that are specified because of run length void runAll(); //Runs all problems unsigned int getNumberOfTimesToRun(); //Asks how many times a problem is supposed to run and returns the value -enum MENU_OPTIONS {RUN_SPECIFIC = 1, RUN_ALL_SHORT, RUN_ALL, EXIT, SIZE}; +enum BENCHMARK_OPTIONS {RUN_SPECIFIC = 1, RUN_ALL_SHORT, RUN_ALL, BENCHMARK_EXIT, BENCHMARK_SIZE}; std::vector tooLong = {15}; -int main(){ +void benchmarkMenu(){ int selection = 0; - do{ - printMenu(); - selection = getMenuSelection(); - switch(selection){ - case RUN_SPECIFIC: runSpecific(); break; - case RUN_ALL_SHORT: runAllShort(); break; - case RUN_ALL: runAll(); break; - case EXIT: break; - } - }while(selection != EXIT); - return 0; + printBenchmarkMenu(); + selection = getBenchmarkMenuSelection(); + + switch(selection){ + case BENCHMARK_OPTIONS::RUN_SPECIFIC: runSpecific(); break; + case BENCHMARK_OPTIONS::RUN_ALL_SHORT: runAllShort(); break; + case BENCHMARK_OPTIONS::RUN_ALL: runAll(); break; + case BENCHMARK_OPTIONS::BENCHMARK_EXIT: break; + } } -void printMenu(){ +void printBenchmarkMenu(){ std::cout << "1. Run a specific problem\n" << "2. Run all problems that have a reasonably short run time\n" << "3. Run all problems\n" << "4. Exit the program" << std::endl; } -int getMenuSelection(){ +int getBenchmarkMenuSelection(){ int selection = 0; std::cin >> selection; - while(std::cin.fail() || !isValidMenu(selection)){ + while(std::cin.fail() || !isValidBenchmarkMenu(selection)){ std::cout << "That is an invalid option!\nPress Enter to continue" << std::endl; std::cin.clear(); std::cin.get(); - printMenu(); + printBenchmarkMenu(); std::cin >> selection; } return selection; } -bool isValidMenu(int selection){ - if((selection > 0) && (selection < MENU_OPTIONS::SIZE)){ +bool isValidBenchmarkMenu(int selection){ + if((selection > 0) && (selection < BENCHMARK_OPTIONS::BENCHMARK_SIZE)){ return true; } else{ @@ -168,3 +169,5 @@ unsigned int getNumberOfTimesToRun(){ } return numOfTimesToRun; } + +#endif //BENCHMARK_HPP diff --git a/main.cpp b/main.cpp index 838530b..cc5967d 100644 --- a/main.cpp +++ b/main.cpp @@ -8,9 +8,9 @@ #include #include +#include "benchmark.hpp" #include "Algorithms.hpp" #include "Headers/Problem.hpp" -#include "Problems.hpp" #include "ProblemSelection.hpp" @@ -27,7 +27,7 @@ unsigned int getProblemNumber(); //A helper function to error check the problem void listProblems(); //Lists the problem numbers that you can choose //Setup the menu options -enum MenuOptions {SOLVE = 1, DESCRIPTION, LIST, EXIT, SIZE}; +enum MenuOptions {SOLVE = 1, DESCRIPTION, LIST, BENCHMARK, EXIT, SIZE}; int main(){ int selection = 0; //Holds the menu selection of the user @@ -37,10 +37,11 @@ int main(){ selection = getMenuSelection(); switch(selection){ - case SOLVE : solveMenu(); break; - case DESCRIPTION : descriptionMenu(); break; - case LIST : listProblems(); break; - case EXIT : break; + case MenuOptions::SOLVE : solveMenu(); break; + case MenuOptions::DESCRIPTION : descriptionMenu(); break; + case MenuOptions::LIST : listProblems(); break; + case MenuOptions::BENCHMARK : benchmarkMenu(); break; + case MenuOptions::EXIT : break; } }while(selection != EXIT); @@ -51,7 +52,8 @@ void printMenu(){ std::cout << "1. Solve a problem\n" << "2. Print a problem description\n" << "3. List valid problem numbers\n" - << "4. Exit" << std::endl; + << "4. Benchmark\n" + << "5. Exit" << std::endl; } int getMenuSelection(){ diff --git a/makefile b/makefile index 1712615..d0e2ba8 100644 --- a/makefile +++ b/makefile @@ -11,12 +11,10 @@ LIBS = $(patsubst %, -lProblem%,$(PROBLEM_NUMBERS)) #Linux makes all: libsMulti ProjectEuler libs: directory $(patsubst %, $(LIBDIR)/libProblem%.so,$(PROBLEM_NUMBERS)) -benchmark: libsMulti ProjectEulerBenchmark #Windows makes windows: allWindows allWindows: libsWindowsMulti ProjectEuler moveBin libsWindows: directory $(patsubst %, $(LIBDIR)/libProblem%.a,$(PROBLEM_NUMBERS)) -windowsBenchmark: libsWindowsMulti ProjectEulerBenchmark moveBin #Non-build jobs directory: @@ -40,8 +38,6 @@ libsWindowsMulti: #Building the executable ProjectEuler: main.cpp $(CXX) $(EXEFLAGS) -o $@.exe $< -L $(LIBDIR) $(LIBS) $(LINKEDLIBS) -ProjectEulerBenchmark: benchmark.cpp - $(CXX) $(EXEFLAGS) -o ProjectEuler.exe $< -L $(LIBDIR) $(LIBS) $(LINKEDLIBS) #Clean up/Remove all files and folders created