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,14 +1,14 @@
//ProjectEuler/C++/Source/Problem16.cpp
//ProjectEuler/ProjectEulerCPP/Source/Problem16.cpp
//Matthew Ellison
// Created: 09-28-18
//Modified: 07-14-19
//Modified: 07-09-20
//What is the sum of the digits of the number 2^1000?
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
//This file contains a header from the gmp library. The library is used for large integers.
//You can find more information about them at https://gmplib.org/
//When compiling this file you need to have the gmp library installed as well as linking the libraries to your executable using the -lgmpxx and -lgmp flags
/*
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
@@ -35,9 +35,11 @@
int Problem16::NUM_TO_POWER = 2; //The number that is going to be raised to a power
int Problem16::POWER = 1000; //The power that the number is going to be raised to
//Constructor
Problem16::Problem16() : Problem("What is the sum of the digits of the number 2^1000?"), num(0), sumOfElements(0){
}
//Solve the problem
void Problem16::solve(){
//If the problem has already been solved do nothing and end the function
if(solved){
@@ -67,6 +69,15 @@ void Problem16::solve(){
solved = true;
}
//Reset the problem so it can be run again
void Problem16::reset(){
Problem::reset();
num = 0;
sumOfElements = 0;
}
//Return a string with the solution to the problem
std::string Problem16::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -79,6 +90,7 @@ std::string Problem16::getString() const{
return results.str();
}
//Returns the number that was calculated
mpz_class Problem16::getNumber() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -87,6 +99,7 @@ mpz_class Problem16::getNumber() const{
return num;
}
//Return the sum of the digits of the number
int Problem16::getSum() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -94,9 +107,3 @@ int Problem16::getSum() const{
}
return sumOfElements;
}
void Problem16::reset(){
Problem::reset();
num = 0;
sumOfElements = 0;
}