From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- .../Steps Count- Input and Output Files.docx | Bin 0 -> 19553 bytes C++/stepsCount/inputData.txt | 1 + C++/stepsCount/stepCount.cpp | 94 +++++++++++++++++++++ C++/stepsCount/stepsFormated.txt | 9 ++ 4 files changed, 104 insertions(+) create mode 100644 C++/stepsCount/Steps Count- Input and Output Files.docx create mode 100644 C++/stepsCount/inputData.txt create mode 100644 C++/stepsCount/stepCount.cpp create mode 100644 C++/stepsCount/stepsFormated.txt (limited to 'C++/stepsCount') diff --git a/C++/stepsCount/Steps Count- Input and Output Files.docx b/C++/stepsCount/Steps Count- Input and Output Files.docx new file mode 100644 index 0000000..06bc353 Binary files /dev/null and b/C++/stepsCount/Steps Count- Input and Output Files.docx differ 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 +#include +#include +#include +#include +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 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 . + */ + 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 -- cgit v1.2.3