mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-06 17:13:59 -05:00
Updated comments and made sure style was consistent
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/C++/Headers/Problem26.cpp
|
||||
//ProjectEuler/ProjectEulerCPP/Source/Problem26.cpp
|
||||
//Matthew Ellison
|
||||
// Created: 07-28-19
|
||||
//Modified: 07-28-19
|
||||
//Modified: 07-09-20
|
||||
//Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
||||
//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
|
||||
@@ -29,13 +29,16 @@
|
||||
#include "../Headers/Problem26.hpp"
|
||||
|
||||
|
||||
//Holds the highest denominator we will check
|
||||
unsigned int Problem26::TOP_NUMBER = 999;
|
||||
|
||||
//Constructor
|
||||
Problem26::Problem26() : Problem("Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part."), longestCycle(0), longestNumber(1){
|
||||
longestCycle = 0;
|
||||
longestNumber = 0;
|
||||
}
|
||||
|
||||
//Solve the problem
|
||||
void Problem26::solve(){
|
||||
//If the problem has already been solved do nothing and end the function
|
||||
if(solved){
|
||||
@@ -90,6 +93,14 @@ void Problem26::solve(){
|
||||
solved = true;
|
||||
}
|
||||
|
||||
//Reset the problem so it can be run again
|
||||
void Problem26::reset(){
|
||||
Problem::reset();
|
||||
longestCycle = 0;
|
||||
longestNumber = 1;
|
||||
}
|
||||
|
||||
//Return a string with the solution to the problem
|
||||
std::string Problem26::getString() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -103,6 +114,7 @@ std::string Problem26::getString() const{
|
||||
return results.str();
|
||||
}
|
||||
|
||||
//Returns the length of the longest cycle
|
||||
unsigned int Problem26::getLongestCycle() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -111,6 +123,7 @@ unsigned int Problem26::getLongestCycle() const{
|
||||
return longestCycle;
|
||||
}
|
||||
|
||||
//Returns the denominator that starts the longest cycle
|
||||
unsigned int Problem26::getLongestNumber() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -118,9 +131,3 @@ unsigned int Problem26::getLongestNumber() const{
|
||||
}
|
||||
return longestNumber;
|
||||
}
|
||||
|
||||
void Problem26::reset(){
|
||||
Problem::reset();
|
||||
longestCycle = 0;
|
||||
longestNumber = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user