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/Problem1.cpp
//ProjectEuler/ProjectEulerCPP/Source/Problem1.cpp
//Matthew Ellison
// Created: 07-10-19
//Modified: 07-10-19
//Modified: 07-09-20
//What is the sum of all the multiples of 3 or 5 that are less than 1000
//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,15 @@
#include "../Headers/Problem1.hpp"
uint64_t Problem1::MAX_NUMBER = 1000;
//The highest number to be tested
uint64_t Problem1::MAX_NUMBER = 999;
//Constructor
Problem1::Problem1() : Problem("What is the sum of all the multiples of 3 or 5 that are less than 1000?"), fullSum(0){
}
//Operational functions
//Solve the problem
void Problem1::solve(){
//If the problem has already been solved do nothing and end the function
if(solved){
@@ -45,8 +49,8 @@ void Problem1::solve(){
timer.start();
//Step through every number < 1000 and see if either 3 or 5 divide it evenly
for(uint64_t cnt = 1;cnt < MAX_NUMBER;++cnt){
//If either divides it then add it to the vector
for(uint64_t cnt = 1;cnt <= MAX_NUMBER;++cnt){
//If either 3 or 5 divides it evenly then add it to the vector
if((cnt % 3) == 0){
numbers.push_back(cnt);
}
@@ -67,25 +71,31 @@ void Problem1::solve(){
solved = true;
}
std::string Problem1::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 numbers < 1000 that are divisible by 3 or 5 is " << fullSum;
return results.str();
}
uint64_t Problem1::getSum() const{
if(!solved){
throw unsolved();
}
return fullSum;
}
//Reset the problem so it can be run again
void Problem1::reset(){
Problem::reset();
fullSum = 0;
numbers.clear();
}
//Gets
//Return a string with the solution to the problem
std::string Problem1::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw unsolved();
}
//Create a string with the results and return it
std::stringstream results;
results << "The sum of all the numbers < " << MAX_NUMBER + 1 << " that are divisible by 3 or 5 is " << fullSum;
return results.str();
}
uint64_t Problem1::getSum() const{
//If the prblem hasn't been solved throw an exception
if(!solved){
throw unsolved();
}
return fullSum;
}