From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- .../.~lock.Ch 8 Sales Array Program.docx# | 1 + .../Ch 8 Sales Array Program.docx | Bin 0 -> 52253 bytes C++/Sales Array Program/SalesArrayProgram.cpp | 94 +++++++++++++++++++++ C++/Sales Array Program/daily_sales.txt | 7 ++ 4 files changed, 102 insertions(+) create mode 100644 C++/Sales Array Program/.~lock.Ch 8 Sales Array Program.docx# create mode 100644 C++/Sales Array Program/Ch 8 Sales Array Program.docx create mode 100644 C++/Sales Array Program/SalesArrayProgram.cpp create mode 100644 C++/Sales Array Program/daily_sales.txt (limited to 'C++/Sales Array Program') 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 Binary files /dev/null and b/C++/Sales Array Program/Ch 8 Sales Array Program.docx 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 +#include +#include +#include +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 . + */ + 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 -- cgit v1.2.3