Updated comments and made sure style was consistent

This commit is contained in:
2020-07-10 13:36:16 -04:00
parent 7257a118d4
commit c72754dcf8
65 changed files with 1160 additions and 747 deletions

View File

@@ -1,11 +1,11 @@
//ProjectEuler/C++/Source/Problem10.cpp
//ProjectEuler/ProjectEulerCPP/Source/Problem10.cpp
//Matthew Ellison
// Created: 09-28-18
//Modified: 07-14-19
//Modified: 07-09-20
//Find the sum of all the primes below two million
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
/*
Copyright (C) 2019 Matthew Ellison
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
@@ -31,11 +31,13 @@
#include "../Headers/Problem10.hpp"
uint64_t Problem10::GOAL_NUMBER = 2000000;
uint64_t Problem10::GOAL_NUMBER = 2000000 - 1; //2,000,000 - 1 because is needs to be < instead of <=
//Constructor
Problem10::Problem10() : Problem("Find the sum of all the primes below two million"), sum(0){
}
//Solve
void Problem10::solve(){
//If the problem has already been solved do nothing and end the function
if(solved){
@@ -44,8 +46,8 @@ void Problem10::solve(){
//Start the timer
timer.start();
//Get the sum of all prime numbers < GOAL_NUMBER
sum = mee::getSum(mee::getPrimes(GOAL_NUMBER - 1)); //Subtract 1 because it is supposed to be < 2000000
//Get the sum of all prime numbers <= GOAL_NUMBER
sum = mee::getSum(mee::getPrimes(GOAL_NUMBER));
//Stop the timer
timer.stop();
@@ -54,16 +56,24 @@ void Problem10::solve(){
solved = true;
}
//Reset the rpoblem so it can be run agian
void Problem10::reset(){
Problem::reset();
sum = 0;
}
//Return a string with the solution to the problem
std::string Problem10::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw unsolved();
}
std::stringstream results;
results << "The sum of all the primes less than " << GOAL_NUMBER << " is " << sum;
results << "The sum of all the primes less than " << GOAL_NUMBER + 1 << " is " << sum;
return results.str();
}
//Returns the sum that was requested
uint64_t Problem10::getSum() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -71,8 +81,3 @@ uint64_t Problem10::getSum() const{
}
return sum;
}
void Problem10::reset(){
Problem::reset();
sum = 0;
}