diff options
| author | rPatrickWarner <[email protected]> | 2024-04-20 09:26:25 -0700 |
|---|---|---|
| committer | rPatrickWarner <[email protected]> | 2024-04-20 09:26:25 -0700 |
| commit | c3acaa3a78b075dc1a26dc207eba749efeb80c26 (patch) | |
| tree | 28407f0e62e1ed9526e24bc12f7495e46d2bf670 | |
| parent | unit test (diff) | |
| download | homework-1-reecepwarner-c3acaa3a78b075dc1a26dc207eba749efeb80c26.tar.xz homework-1-reecepwarner-c3acaa3a78b075dc1a26dc207eba749efeb80c26.zip | |
Big changes to TempLog
| -rw-r--r-- | CST 126/Homework 1/GuessingHelper.hpp | 4 | ||||
| -rw-r--r-- | CST 126/Homework 1/Helper.hpp | 21 | ||||
| -rw-r--r-- | CST 126/Homework 1/TempLogHelper.hpp | 70 | ||||
| -rw-r--r-- | CST 126/Homework 1/main.cpp | 4 | ||||
| -rw-r--r-- | CST 126/UnitTest1/UnitTest1.cpp | 5 |
5 files changed, 90 insertions, 14 deletions
diff --git a/CST 126/Homework 1/GuessingHelper.hpp b/CST 126/Homework 1/GuessingHelper.hpp index 067668d..6dd35c3 100644 --- a/CST 126/Homework 1/GuessingHelper.hpp +++ b/CST 126/Homework 1/GuessingHelper.hpp @@ -25,12 +25,11 @@ void GuessingGame() do { - UserGuess = InputSelectionInt("Guess a number between 1 and 10,000 :"); system("cls"); if (UserGuess == GoldenSnitch) { - std::cout << "\033[32mHooray! YOU WON!!!!$$$$\033[0m" << std::endl; + std::cout << "\033[32mHooray! YOU WON!!!!$$$$\033[0m" << "It took you #" << NumberOfGuesses << " Tries!!!" << std::endl; return; } if (UserGuess < GoldenSnitch) @@ -46,6 +45,7 @@ void GuessingGame() { std::cout << "I'm sorry to inform you of your loss, but there's always another day!" << std::endl; } + std::cout << "Try #" << NumberOfGuesses << std::endl; } while (NumberOfGuesses != 20); } diff --git a/CST 126/Homework 1/Helper.hpp b/CST 126/Homework 1/Helper.hpp index a83a072..fc86421 100644 --- a/CST 126/Homework 1/Helper.hpp +++ b/CST 126/Homework 1/Helper.hpp @@ -6,6 +6,7 @@ using std::streamsize; constexpr size_t MAX_STREAM_SIZE = numeric_limits<streamsize>::max(); double InputDouble(const char* Prompt); +float InputFloat(const char* Prompt); int InputSelectionInt(const char* Prompt); void Prompts(const char* Prompt); @@ -35,6 +36,26 @@ double InputDouble(const char* Prompt) } return Value; } +float InputFloat(const char* Prompt) +{ + std::cout << Prompt << std::endl; + + std::cout.flush(); + + float Value = 0; + std::cin >> Value; + + while (!std::cin) + { + std::cout << Prompt << std::endl; + std::cin.clear(); + + std::cin.ignore(MAX_STREAM_SIZE, '\n'); + std::cin >> Value; + + } + return Value; +} int InputSelectionInt(const char* Prompt) { diff --git a/CST 126/Homework 1/TempLogHelper.hpp b/CST 126/Homework 1/TempLogHelper.hpp index c34be41..3e53dea 100644 --- a/CST 126/Homework 1/TempLogHelper.hpp +++ b/CST 126/Homework 1/TempLogHelper.hpp @@ -1,21 +1,77 @@ #ifndef TEMP_LOG_HELPER_HPP #define TEMP_LOG_HELPER_HPP #include "MenuHelper.hpp" -struct Week { - float DayHigh, DayLow; + +struct Temperature { + float High; + float Low; }; +inline void GreatHighGreatLow(Temperature* WeekLog) +{ + float GreatestLow = 0.0; + float GreatestHigh = 0.0; + for (auto i = 0u; i < 7; i++) + { + if (WeekLog[i].High > GreatestHigh) + { + GreatestHigh = WeekLog[i].High; + } + } + std::cout << "Your weekly high was " << GreatestHigh << std::endl; +} -int add(int uno, int dos, int tres); -int add(int uno, int dos, int tres, int quat); +inline void TemperatureAverage(Temperature* WeekLog) +{ + float AverageTemp = 0.0; + float Sum = 0.0; -int add(int uno, int dos, int tres) + for (auto i = 0u; i < 7; i++) + { + Sum += (WeekLog[i].High + WeekLog[i].Low); + } + AverageTemp = Sum / 14; + +} +inline void TemperatureDifference(Temperature* WeekLog) { - int result = uno + dos + tres; + float HighLowDifference = 0.0; + + float HighLowStorage[7]{}; - return result; + for (auto i = 0u; i < 7; i++) + { + HighLowDifference = WeekLog[i].High - WeekLog[i].Low; + HighLowStorage[i] = HighLowDifference; + } + + float GreatestDifference = 0.0; + for (auto j = 0u; j < 7; j++) + { + if (HighLowStorage[j] > GreatestDifference) + { + GreatestDifference = HighLowStorage[j]; + } + } + std::cout << "The largest temperature differential was " << GreatestDifference << " degrees Farenheit!" << std::endl; +} + +inline Temperature* TempInput(const char* Prompt1, const char* Prompt2) +{ + Temperature WeekTemp[7]; + for (auto i = 0u; i <7; i++) + { + WeekTemp[i].High = InputFloat(Prompt1); + WeekTemp[i].Low = InputFloat(Prompt2); + system("cls"); + } + GreatHighGreatLow(WeekTemp); + return WeekTemp; } + + + #endif
\ No newline at end of file diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp index cb22063..7a400ca 100644 --- a/CST 126/Homework 1/main.cpp +++ b/CST 126/Homework 1/main.cpp @@ -11,7 +11,7 @@ int main() { //UserMenu(); - - + TempInput("What was the high?", "What was the low?"); + //TemperatureArithmetic(TempInput("What was the high?", "What was the low?")); return 0; }
\ No newline at end of file diff --git a/CST 126/UnitTest1/UnitTest1.cpp b/CST 126/UnitTest1/UnitTest1.cpp index a022236..9ee1ea5 100644 --- a/CST 126/UnitTest1/UnitTest1.cpp +++ b/CST 126/UnitTest1/UnitTest1.cpp @@ -11,10 +11,9 @@ namespace UnitTest1 { public: - TEST_METHOD(Addition_Function_Correctly) + TEST_METHOD(testmethods) { - int result = add(15, 15, 15); - Assert::AreEqual(45, result); + } }; } |