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++/Source/Problem9.cpp
|
||||
//ProjectEuler/ProjectEulerCPP/Source/Problem9.cpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 07-14-19
|
||||
//Modified: 07-09-20
|
||||
//There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product of abc.
|
||||
//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
|
||||
@@ -30,9 +30,11 @@
|
||||
#include "../Headers/Problem9.hpp"
|
||||
|
||||
|
||||
//Constructor
|
||||
Problem9::Problem9() : Problem("There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product of abc."), a(1), b(0), c(0), found(false){
|
||||
}
|
||||
|
||||
//Solve the problem
|
||||
void Problem9::solve(){
|
||||
//If the problem has already been solved do nothing and end the function
|
||||
if(solved){
|
||||
@@ -68,6 +70,16 @@ void Problem9::solve(){
|
||||
solved = true;
|
||||
}
|
||||
|
||||
//Reset the problem so it can be run again
|
||||
void Problem9::reset(){
|
||||
Problem::reset();
|
||||
a = 1;
|
||||
b = 0;
|
||||
c = 0;
|
||||
found = false;
|
||||
}
|
||||
|
||||
//Return a string with the solution to the problem
|
||||
std::string Problem9::getString() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -85,6 +97,7 @@ std::string Problem9::getString() const{
|
||||
return results.str();
|
||||
}
|
||||
|
||||
//Returns the length of the first side
|
||||
int Problem9::getSideA() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -93,6 +106,7 @@ int Problem9::getSideA() const{
|
||||
return a;
|
||||
}
|
||||
|
||||
//Returns the length of the second side
|
||||
int Problem9::getSideB() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -101,6 +115,7 @@ int Problem9::getSideB() const{
|
||||
return b;
|
||||
}
|
||||
|
||||
//Returns the length of the hyp
|
||||
int Problem9::getSideC() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -109,6 +124,7 @@ int Problem9::getSideC() const{
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
//Returns the product of the 3 sides
|
||||
int Problem9::getProduct() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -116,11 +132,3 @@ int Problem9::getProduct() const{
|
||||
}
|
||||
return a * b * (int)c;
|
||||
}
|
||||
|
||||
void Problem9::reset(){
|
||||
Problem::reset();
|
||||
a = 1;
|
||||
b = 0;
|
||||
c = 0;
|
||||
found = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user