diff options
author | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
---|---|---|
committer | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
commit | 9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch) | |
tree | eb1efc1d028b949dd83bb710c68be8eff58f26e7 /C++/stepsCount | |
download | school-code-master.tar.gz school-code-master.tar.bz2 school-code-master.zip |
Diffstat (limited to 'C++/stepsCount')
-rw-r--r-- | C++/stepsCount/Steps Count- Input and Output Files.docx | bin | 0 -> 19553 bytes | |||
-rw-r--r-- | C++/stepsCount/inputData.txt | 1 | ||||
-rw-r--r-- | C++/stepsCount/stepCount.cpp | 94 | ||||
-rw-r--r-- | C++/stepsCount/stepsFormated.txt | 9 |
4 files changed, 104 insertions, 0 deletions
diff --git a/C++/stepsCount/Steps Count- Input and Output Files.docx b/C++/stepsCount/Steps Count- Input and Output Files.docx Binary files differnew file mode 100644 index 0000000..06bc353 --- /dev/null +++ b/C++/stepsCount/Steps Count- Input and Output Files.docx diff --git a/C++/stepsCount/inputData.txt b/C++/stepsCount/inputData.txt new file mode 100644 index 0000000..c2c3a43 --- /dev/null +++ b/C++/stepsCount/inputData.txt @@ -0,0 +1 @@ +Sunday 2200 Monday 3060 Tuesday 5840 Wednesday 3230 Thursday 4584 Friday 3400 Saturday 1870 diff --git a/C++/stepsCount/stepCount.cpp b/C++/stepsCount/stepCount.cpp new file mode 100644 index 0000000..0a89f98 --- /dev/null +++ b/C++/stepsCount/stepCount.cpp @@ -0,0 +1,94 @@ +// Name: msglm +// Date: Feb-14-2021 +// Program Name: Step Count +// Description: Takes in the amount of steps you took through a week and averages them together + + +#include <iostream> +#include <string> +#include <fstream> +#include <iomanip> +#include <vector> +using namespace std; + +// Named constants + +int main() { + + //Variable declaration + ifstream inputData; + ofstream stepsFormatted; + string tempDay = "-1"; + int tempSteps = -1; + int epoch; + int averageSteps; + int totalSteps; + vector<int> stepPendingAverage; //Vector was chosen for its ease of being able to append + + //Program title and description for the user + cout << "Title: Step Count" << endl << "Description: Takes in the amount of steps you took through a week and averages them together" << endl; + + // User input + // Dealing with input/output files + inputData.open("inputData.txt"); + stepsFormatted.open("stepsFormated.txt"); + + //Create and set up file's formatting + columns + stepsFormatted << fixed << showpoint << setprecision(2); + stepsFormatted << setw(17) << left << "Day " << setw(8) << "Steps" << endl; + //Reading from the file + + //This will loop over so long as the file is not empty + while( !inputData.eof() ) { + + //Test to see if tempDay and tempSteps is assigned to valid input + if (tempDay != "-1" && tempSteps != -1) { + //if tempDay and tempSteps is valid, then write to the file what is desired + stepsFormatted << setw(17) << left << tempDay << setw(8) << tempSteps << endl; + //invalidate the input so it may be wrote over again + tempDay = -1; + tempSteps = -1; + //TODO find a better way to do this; there may be a time where -1 is valid input. + } + + //If the input is a day, write the day name to tempDay + if (epoch % 2 == 0) { + inputData >> tempDay; + } else { + //Otherwise, is a number of steps and write that number to tempSteps + inputData >> tempSteps; + //also append number of steps to the temporary pending steps array + stepPendingAverage.push_back(tempSteps); + + } + //Increase the epoch by 1, showing that a pair of day and steps has been read + epoch++; + } + + // Calculations + + // Obtaining total number of steps + for(int iteration=0; iteration < stepPendingAverage.size(); iteration++) { + totalSteps = totalSteps + stepPendingAverage[iteration]; + //Obtain Average + averageSteps = totalSteps/stepPendingAverage.size(); + } + //Writing average to file + stepsFormatted << setw(17) << left << "Average" << setw(8) << averageSteps << "steps per day" << endl; + + //Close files + inputData.close(); + stepsFormatted.close(); + + // Output to the screen + cout << "Please Check stepsFormatted.txt file" << endl; + + return 0; +} + +/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + diff --git a/C++/stepsCount/stepsFormated.txt b/C++/stepsCount/stepsFormated.txt new file mode 100644 index 0000000..e808fec --- /dev/null +++ b/C++/stepsCount/stepsFormated.txt @@ -0,0 +1,9 @@ +Day Steps +Sunday 2200 +Monday 3060 +Tuesday 5840 +Wednesday 3230 +Thursday 4584 +Friday 3400 +Saturday 1870 +Average 3454 steps per day |