summaryrefslogtreecommitdiffstats
path: root/C++/Sales Array Program
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
committermsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
commit9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch)
treeeb1efc1d028b949dd83bb710c68be8eff58f26e7 /C++/Sales Array Program
downloadschool-code-master.tar.gz
school-code-master.tar.bz2
school-code-master.zip
Inital CommitHEADmaster
Diffstat (limited to 'C++/Sales Array Program')
-rw-r--r--C++/Sales Array Program/.~lock.Ch 8 Sales Array Program.docx#1
-rw-r--r--C++/Sales Array Program/Ch 8 Sales Array Program.docxbin0 -> 52253 bytes
-rw-r--r--C++/Sales Array Program/SalesArrayProgram.cpp94
-rw-r--r--C++/Sales Array Program/daily_sales.txt7
4 files changed, 102 insertions, 0 deletions
diff --git a/C++/Sales Array Program/.~lock.Ch 8 Sales Array Program.docx# b/C++/Sales Array Program/.~lock.Ch 8 Sales Array Program.docx#
new file mode 100644
index 0000000..73e693a
--- /dev/null
+++ b/C++/Sales Array Program/.~lock.Ch 8 Sales Array Program.docx#
@@ -0,0 +1 @@
+,msglm,msglm-desktop,21.04.2022 00:33,file:///home/msglm/.config/libreoffice/4; \ No newline at end of file
diff --git a/C++/Sales Array Program/Ch 8 Sales Array Program.docx b/C++/Sales Array Program/Ch 8 Sales Array Program.docx
new file mode 100644
index 0000000..bb0f1ca
--- /dev/null
+++ b/C++/Sales Array Program/Ch 8 Sales Array Program.docx
Binary files differ
diff --git a/C++/Sales Array Program/SalesArrayProgram.cpp b/C++/Sales Array Program/SalesArrayProgram.cpp
new file mode 100644
index 0000000..6cd5e766
--- /dev/null
+++ b/C++/Sales Array Program/SalesArrayProgram.cpp
@@ -0,0 +1,94 @@
+// Name: msglm
+// Date:
+// Program Name:
+// Description:
+
+
+#include <iostream>
+#include <string>
+#include <iomanip>
+#include <fstream>
+using namespace std;
+
+// Named constants
+const int ARRAY_SIZE = 7;
+
+//Func Decl
+void printDailySales(double array[]);
+double findTotal(double array[]);
+double findMax(double array[]);
+double findMin(double array[]);
+
+int main() {
+
+ //Variable declaration
+ ifstream salesFile;
+ double readSales[ARRAY_SIZE];
+
+ //Open file
+ salesFile.open("daily_sales.txt");
+
+ //Program title and description for the user
+ cout << "Title: 7-day sales calculator" << endl << "Description: Takes in a file with the total income for a day segregated by a newline character. Output is a breakdown of each day's sales, the total for the week, the worst day, and the best day." << endl;
+
+ //Reading input
+ for (int pos = 0; pos < ARRAY_SIZE; pos++) {
+ salesFile >> readSales[pos];
+ }
+
+ //Output
+ printDailySales(readSales);
+ cout << "Total: $" << findTotal(readSales) << endl;
+ cout << "Max: $" << findMax(readSales) << endl;
+ cout << "Min: $" << findMin(readSales) << endl;
+ return 0;
+}
+
+//Prints the daily sales
+void printDailySales(double array[]) {
+ cout << "Daily Sales Earned: \n";
+ for (int pos = 0; pos < ARRAY_SIZE; pos++) {
+ cout << "Day #" << pos+1 << ": $" << array[pos] << endl;
+ }
+}
+
+//Adds up total and returns it as a sum
+double findTotal(double array[]){
+ double sum = 0;
+ for (int pos = 0; pos < ARRAY_SIZE; pos++) {
+ sum = sum + array[pos];
+ }
+ return sum;
+}
+
+//Just a classic "find maximum" sorting algorithm
+double findMax(double array[]){
+ double max = array[0];
+ for (int pos = 1; pos < ARRAY_SIZE; pos++) {
+ if (max < array[pos]) {
+ max = array[pos];
+ }
+ }
+ return max;
+}
+
+//classic find minimum sorting algorithm
+double findMin(double array[]){
+ double min = array[0];
+ for (int pos = 1; pos < ARRAY_SIZE; pos++) {
+ if (min > array[pos]) {
+ min = array[pos];
+ }
+ }
+ return min;
+}
+
+
+
+
+ /*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++/Sales Array Program/daily_sales.txt b/C++/Sales Array Program/daily_sales.txt
new file mode 100644
index 0000000..9631979
--- /dev/null
+++ b/C++/Sales Array Program/daily_sales.txt
@@ -0,0 +1,7 @@
+352.12
+654.84
+123.45
+654.87
+548.26
+532.56
+456.13