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/Problem6.cpp
//ProjectEuler/ProjectEulerCPP/Source/Problem6.cpp
//Matthew Ellison
// Created: 09-28-18
//Modified: 07-14-19
//Modified: 07-09-20
//Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
//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,12 +31,14 @@
#include "../Headers/Problem6.hpp"
int Problem6::START_NUM = 1;
int Problem6::END_NUM = 100;
int Problem6::START_NUM = 1; //The first number to check
int Problem6::END_NUM = 100; //The last number to check
//Constructor
Problem6::Problem6() : Problem("Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum."), sumOfSquares(0), squareOfSum(0){
}
//Solve the problem
void Problem6::solve(){
//If the problem has already been solved do nothing and end the function
if(solved){
@@ -60,6 +62,13 @@ void Problem6::solve(){
solved = true;
}
//Reset the problem so it can be run again
void Problem6::reset(){
Problem::reset();
sumOfSquares = squareOfSum = 0;
}
//Return a string with the solution to the problem
std::string Problem6::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -70,6 +79,7 @@ std::string Problem6::getString() const{
return results.str();
}
//Returns the sum of all the squares
uint64_t Problem6::getSumOfSquares() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -78,6 +88,7 @@ uint64_t Problem6::getSumOfSquares() const{
return sumOfSquares;
}
//Returns the square of all of the sums
uint64_t Problem6::getSquareOfSum() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -86,6 +97,7 @@ uint64_t Problem6::getSquareOfSum() const{
return squareOfSum;
}
//Returns the requested difference
uint64_t Problem6::getDifference() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -93,8 +105,3 @@ uint64_t Problem6::getDifference() const{
}
return abs(sumOfSquares - squareOfSum);
}
void Problem6::reset(){
Problem::reset();
sumOfSquares = squareOfSum = 0;
}