aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWesleyR <[email protected]>2024-04-21 21:38:58 -0700
committerWesleyR <[email protected]>2024-04-21 21:38:58 -0700
commit33c72afebeafd9f672f19502f99ffb91caf5f695 (patch)
tree1c0a25ee87ddc504a4020df4458206110eb7ad9e
parentupdates (diff)
downloadhomework-1-wesleyr23-33c72afebeafd9f672f19502f99ffb91caf5f695.tar.xz
homework-1-wesleyr23-33c72afebeafd9f672f19502f99ffb91caf5f695.zip
Submission
-rw-r--r--CST 126/Homework 1/Homework 1.vcxproj4
-rw-r--r--CST 126/Homework 1/Homework 1.vcxproj.filters12
-rw-r--r--CST 126/Homework 1/clear.hpp8
-rw-r--r--CST 126/Homework 1/currency.hpp24
-rw-r--r--CST 126/Homework 1/getrandom.hpp33
-rw-r--r--CST 126/Homework 1/guessinggame.hpp91
-rw-r--r--CST 126/Homework 1/main.cpp1
-rw-r--r--CST 126/Homework 1/menu.hpp14
-rw-r--r--CST 126/Homework 1/temperature.hpp146
9 files changed, 309 insertions, 24 deletions
diff --git a/CST 126/Homework 1/Homework 1.vcxproj b/CST 126/Homework 1/Homework 1.vcxproj
index a55989a..b116d25 100644
--- a/CST 126/Homework 1/Homework 1.vcxproj
+++ b/CST 126/Homework 1/Homework 1.vcxproj
@@ -132,8 +132,10 @@
<ItemGroup>
<ClInclude Include="clear.hpp" />
<ClInclude Include="currency.hpp" />
- <ClInclude Include="menu.h" />
+ <ClInclude Include="guessinggame.hpp" />
<ClInclude Include="menu.hpp" />
+ <ClInclude Include="getrandom.hpp" />
+ <ClInclude Include="temperature.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/CST 126/Homework 1/Homework 1.vcxproj.filters b/CST 126/Homework 1/Homework 1.vcxproj.filters
index 2be4ebd..f463c7e 100644
--- a/CST 126/Homework 1/Homework 1.vcxproj.filters
+++ b/CST 126/Homework 1/Homework 1.vcxproj.filters
@@ -20,9 +20,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="menu.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="menu.hpp">
<Filter>Header Files</Filter>
</ClInclude>
@@ -32,5 +29,14 @@
<ClInclude Include="clear.hpp">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="guessinggame.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="getrandom.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="temperature.hpp">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/CST 126/Homework 1/clear.hpp b/CST 126/Homework 1/clear.hpp
index 7adbb79..e978d1a 100644
--- a/CST 126/Homework 1/clear.hpp
+++ b/CST 126/Homework 1/clear.hpp
@@ -6,14 +6,6 @@
using std::cout;
using std::cin;
-inline void WaitEnter()
-{
- char key;
-
- cout << "\nPress any key and enter to continue...";
- cin >> key;
-}
-
inline void ClearScreen()
{
cout << "\033[2J\033[1;1H";
diff --git a/CST 126/Homework 1/currency.hpp b/CST 126/Homework 1/currency.hpp
index 50bf14e..3523183 100644
--- a/CST 126/Homework 1/currency.hpp
+++ b/CST 126/Homework 1/currency.hpp
@@ -107,7 +107,7 @@ inline int ValidateInput(int input) {
cin >> input;
- while (input < 1 || input > 8)
+ while (input < 1 || input > 7)
{
cout << "\nInvalid Option, please pick again: ";
cin >> input;
@@ -118,8 +118,8 @@ inline int ValidateInput(int input) {
inline void Input (int &original, int &convertTo, double &value)
{
- cout << "*********************************************************************" << endl;
- cout << "1. USD\n2. CAD\n3. EUR\n4. GBP\n5. INR\n6. AUD\n7.CHF\n";
+ cout << "*********************************************************************\n";
+ cout << "1. USD\n2. CAD\n3. EUR\n4. GBP\n5. INR\n6. AUD\n7. CHF\n";
cout << "Pick the number of the input currency: ";
original = ValidateInput(original);
cout << "\nWhat is the value of this currency to two decimal places: ";
@@ -128,6 +128,19 @@ inline void Input (int &original, int &convertTo, double &value)
convertTo = ValidateInput(convertTo);
}
+inline bool ConvertMore()
+{
+ char again;
+
+ cout << "\nWould you like to convert more currency? (Y/N): ";
+ cin >> again;
+
+ if (again == 'Y')
+ return true;
+ else
+ return false;
+}
+
inline void PickCurrency() {
int original = 0;
@@ -145,9 +158,10 @@ inline void PickCurrency() {
cout << "The converted value is " << fixed << setprecision(2) << value << " in ";
CurrencyName(convertTo);
- cout << "." << endl;
+ cout << ".\n";
- WaitEnter();
+ if (ConvertMore() == true)
+ PickCurrency();
}
diff --git a/CST 126/Homework 1/getrandom.hpp b/CST 126/Homework 1/getrandom.hpp
new file mode 100644
index 0000000..8290d71
--- /dev/null
+++ b/CST 126/Homework 1/getrandom.hpp
@@ -0,0 +1,33 @@
+#ifndef GETRANDOM_H
+#define GETRANDOM_H
+
+#include <random>
+
+using std::random_device;
+using std::mt19937;
+using std::uniform_int_distribution;
+
+
+inline int GetRandom(const int upperbound, const int lowerbound)
+{
+ random_device rd; // a seed source for the random number engine
+ mt19937 gen(rd()); // mersenne_twister_engine seeded with rd()
+ uniform_int_distribution<> distrib(lowerbound, upperbound);
+
+
+ return distrib(gen);
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+#endif \ No newline at end of file
diff --git a/CST 126/Homework 1/guessinggame.hpp b/CST 126/Homework 1/guessinggame.hpp
new file mode 100644
index 0000000..3bd8a17
--- /dev/null
+++ b/CST 126/Homework 1/guessinggame.hpp
@@ -0,0 +1,91 @@
+#ifndef GUESSINGGAME_H
+#define GUESSINGGAME_H
+
+#include <iostream>
+
+#include "clear.hpp"
+#include "getrandom.hpp"
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+inline void Guess(int &input, const int count)
+{
+ if (count != 20)
+ cout << "This is guess " << count << ".\nEnter your guess: ";
+ else
+ cout << "\nLast chance! Enter your best guess: ";
+
+ cin >> input;
+
+}
+
+inline void HighLow(const int random, const int input, const int count)
+{
+
+ cout << "\n";
+
+ if (random < input)
+ cout << input << " is greater than the number.";
+ else if (random > input)
+ cout << input << " is less than the number.";
+ else
+ cout << input << " is correct!";
+
+
+}
+
+inline bool WinLoseAgain(const int random, const int input)
+{
+ char again;
+
+ if (random == input)
+ {
+ cout << "\nCongrats, you win!";
+ }
+ else
+ {
+ cout << "\nOh no! You lost! The correct guess was: " << random;
+ }
+
+
+ cout << "\nWould you like to play again? (Y/N): ";
+ cin >> again;
+
+ if (again == 'Y')
+ return true;
+ else
+ return false;
+
+}
+
+inline void GuessingGame()
+{
+
+ const int random = GetRandom(1000, 1);
+ int input = 0;
+ int count = 1;
+
+ ClearScreen();
+
+ cout << "*************************************************************\n";
+ cout << "Welcome to the guessing game!\nYou have 20 guesses to guess a number between 1-1000.\n";
+
+ while (input != random && count != 21)
+ {
+ Guess(input, count);
+ HighLow(random, input, count);
+ count++;
+ }
+
+ if (WinLoseAgain(random, input) == true)
+ GuessingGame();
+
+
+}
+
+
+
+
+#endif
diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp
index b483404..30667be 100644
--- a/CST 126/Homework 1/main.cpp
+++ b/CST 126/Homework 1/main.cpp
@@ -3,7 +3,6 @@
// Date: 4/3/24
// Assignment: Homework 1
-#include <iostream>
#include "menu.hpp"
int main() {
diff --git a/CST 126/Homework 1/menu.hpp b/CST 126/Homework 1/menu.hpp
index 51f8f0e..c97e686 100644
--- a/CST 126/Homework 1/menu.hpp
+++ b/CST 126/Homework 1/menu.hpp
@@ -1,9 +1,12 @@
#ifndef MENU_H
#define MENU_H
-#include <iostream>;
+#include <iostream>
+
#include "clear.hpp"
#include "currency.hpp"
+#include "guessinggame.hpp"
+#include "temperature.hpp"
using std::cout;
using std::cin;
@@ -13,13 +16,12 @@ inline void DisplayMenu()
{
ClearScreen();
- cout << "*******************************************************************" << endl;
+ cout << "*******************************************************************\n";
cout << "Welcome to the menu!\n";
cout << "1. Currency Converter\n";
cout << "2. Guessing Game\n";
cout << "3. Temperature Logger\n";
- cout << "5. Exit\n";
- cout << endl;
+ cout << "5. Exit\n\n";
cout << "Please pick a number for your choice: ";
}
@@ -39,11 +41,11 @@ inline void Worker() {
break;
case 2:
- //guessing game
+ GuessingGame();
break;
case 3:
- //call temp logger
+ StoreTemp();
break;
default:
diff --git a/CST 126/Homework 1/temperature.hpp b/CST 126/Homework 1/temperature.hpp
new file mode 100644
index 0000000..38e5d4f
--- /dev/null
+++ b/CST 126/Homework 1/temperature.hpp
@@ -0,0 +1,146 @@
+#ifndef TEMPERATURE_H
+#define TEMPERATURE_H
+
+#include <iostream>
+
+#include "clear.hpp"
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+
+struct temp
+{
+ float high;
+ float low;
+
+};
+
+inline void Day(int num)
+{
+ switch (num)
+ {
+ case 1:
+ cout << "Sunday";
+ break;
+ case 2:
+ cout << "Monday";
+ break;
+ case 3:
+ cout << "Tuesday";
+ break;
+ case 4:
+ cout << "Wednesday";
+ break;
+ case 5:
+ cout << "Thursday";
+ break;
+ case 6:
+ cout << "Friday";
+ break;
+ case 7:
+ cout << "Saturday";
+ break;
+ default:
+ cout << "Error";
+
+ }
+}
+
+inline void Populate(temp temperature[], int size)
+{
+
+
+ for (int i = 1; i < size; i++)
+ {
+
+ cout << "\nWhat is the high temp for ";
+ Day(i);
+ cout << "?: ";
+ cin >> temperature[i].high;
+
+ cout << "\nWhat is the low temp for ";
+ Day(i);
+ cout << "?: ";
+ cin >> temperature[i].low;
+ }
+
+}
+
+inline void AvgHiLo(const temp temperature[], const int size, float &averageHigh, float &averageLow, float &high, float &low, float &diff)
+{
+ float placeholder;
+ float count = 0;
+ high = temperature[1].high;
+ low = temperature[1].low;
+
+ for (int i = 1; i < size; i++)
+ {
+ placeholder = temperature[i].high - temperature[i].low;
+
+ if (diff < placeholder)
+ diff = placeholder;
+ if (high < temperature[i].high)
+ high = temperature[i].high;
+ if (low > temperature[i].low)
+ low = temperature[i].low;
+
+ averageHigh = averageHigh + temperature[i].high;
+ averageLow = averageLow + temperature[i].low;
+
+ count++;
+ }
+
+ averageHigh = averageHigh / count;
+ averageLow = averageLow / count;
+}
+
+inline bool MoreTemps()
+{
+ char again;
+
+ cout << "\nWould you like to log more temperatures? (Y/N): ";
+ cin >> again;
+
+ if (again == 'Y')
+ return true;
+ else
+ return false;
+}
+
+inline void StoreTemp()
+{
+ const int size = 8;
+
+ temp temperature[size];
+
+ float avgHi = 0;
+ float avgLo = 0;
+ float highest = 0;
+ float lowest = 0;
+ float diff = 0;
+
+ ClearScreen();
+
+ cout << "*************************************************************\n";
+ cout << "Welcome to the temperature logger!\nYou will be prompted to enter the high and low temp for each day of the week.\n";
+
+ Populate(temperature, size);
+ AvgHiLo(temperature, size, avgHi, avgLo, highest, lowest, diff);
+
+ ClearScreen();
+
+ cout << "The highest temp was:\n" << highest;
+ cout << "\nThe lowest temp was:\n" << lowest;
+ cout << "\nThe average high temp was:\n" << avgHi;
+ cout << "\nThe average low temp was:\n" << avgLo;
+ cout << "\nThe greatest difference in temp was:\n" << diff;
+
+ if (MoreTemps() == true)
+ StoreTemp();
+
+}
+
+
+#endif