diff options
| -rw-r--r-- | CST 126/Homework 1/Homework 1.vcxproj | 6 | ||||
| -rw-r--r-- | CST 126/Homework 1/Homework 1.vcxproj.filters | 14 | ||||
| -rw-r--r-- | CST 126/Homework 1/clear.hpp | 23 | ||||
| -rw-r--r-- | CST 126/Homework 1/currency.hpp | 183 | ||||
| -rw-r--r-- | CST 126/Homework 1/main.cpp | 5 | ||||
| -rw-r--r-- | CST 126/Homework 1/menu.hpp | 74 |
6 files changed, 303 insertions, 2 deletions
diff --git a/CST 126/Homework 1/Homework 1.vcxproj b/CST 126/Homework 1/Homework 1.vcxproj index 0a4f788..a55989a 100644 --- a/CST 126/Homework 1/Homework 1.vcxproj +++ b/CST 126/Homework 1/Homework 1.vcxproj @@ -129,6 +129,12 @@ <ItemGroup> <ClCompile Include="main.cpp" /> </ItemGroup> + <ItemGroup> + <ClInclude Include="clear.hpp" /> + <ClInclude Include="currency.hpp" /> + <ClInclude Include="menu.h" /> + <ClInclude Include="menu.hpp" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/CST 126/Homework 1/Homework 1.vcxproj.filters b/CST 126/Homework 1/Homework 1.vcxproj.filters index ce0c35c..2be4ebd 100644 --- a/CST 126/Homework 1/Homework 1.vcxproj.filters +++ b/CST 126/Homework 1/Homework 1.vcxproj.filters @@ -19,4 +19,18 @@ <Filter>Source Files</Filter> </ClCompile> </ItemGroup> + <ItemGroup> + <ClInclude Include="menu.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="menu.hpp"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="currency.hpp"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="clear.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 new file mode 100644 index 0000000..7adbb79 --- /dev/null +++ b/CST 126/Homework 1/clear.hpp @@ -0,0 +1,23 @@ +#ifndef CLEAR_H +#define CLEAR_H + +#include <iostream> + +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"; +} + + +#endif
\ No newline at end of file diff --git a/CST 126/Homework 1/currency.hpp b/CST 126/Homework 1/currency.hpp new file mode 100644 index 0000000..50bf14e --- /dev/null +++ b/CST 126/Homework 1/currency.hpp @@ -0,0 +1,183 @@ +#ifndef CURRENCY_H +#define CURRENCY_H + +#include <iostream> +#include <iomanip> +#include "clear.hpp" + +using std::cout; +using std::cin; +using std::endl; +using std::fixed; +using std::setprecision; + +inline void ConvertOther(int convertTo, double &value) { + + switch (convertTo) + { + case 2: + value = value * 1.377; + break; + case 3: + value = value * .9398; + break; + case 4: + value = value * .8032; + break; + case 5: + value = value * 83.61; + break; + case 6: + value = value * 1.547; + break; + case 7: + value = value * .9144; + break; + default: + break; + } + +} + +inline void ConvertUSD(int original, double &value) { + + switch (original) + { + case 2: + value = value / 1.377; + break; + case 3: + value = value / .9398; + break; + case 4: + value = value / .8032; + break; + case 5: + value = value / 83.61; + break; + case 6: + value = value / 1.547; + break; + case 7: + value = value / .9144; + break; + default: + break; + } +} + +inline void CurrencyName(int convertTo) { + + switch (convertTo) + { + case 1: + cout << "USD"; + break; + case 2: + cout << "CAD"; + break; + case 3: + cout << "EUR"; + break; + case 4: + cout << "GBP"; + break; + case 5: + cout << "INR"; + break; + case 6: + cout << "AUD"; + break; + case 7: + cout << "CHF"; + break; + default: + break; + } +} + +inline void Convert(int original, int convertTo, double &value) { + + ConvertUSD(original, value); + ConvertOther(convertTo,value); + +} + +inline int ValidateInput(int input) { + + cin >> input; + + while (input < 1 || input > 8) + { + cout << "\nInvalid Option, please pick again: "; + cin >> input; + } + + return 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 << "Pick the number of the input currency: "; + original = ValidateInput(original); + cout << "\nWhat is the value of this currency to two decimal places: "; + cin >> value; + cout << "\nPick the number of the currency to convert to: "; + convertTo = ValidateInput(convertTo); +} + +inline void PickCurrency() { + + int original = 0; + double value = 0; + int convertTo = 0; + + ClearScreen(); + + Input(original, convertTo, value); + + if (original != convertTo) + Convert(original, convertTo, value); + + ClearScreen(); + + cout << "The converted value is " << fixed << setprecision(2) << value << " in "; + CurrencyName(convertTo); + cout << "." << endl; + + WaitEnter(); + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#endif
\ No newline at end of file diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp index 236cab9..b483404 100644 --- a/CST 126/Homework 1/main.cpp +++ b/CST 126/Homework 1/main.cpp @@ -1,13 +1,14 @@ // Name: Wesley Richelderfer // Class: CST 126 // Date: 4/3/24 -// Assignment: Homework +// Assignment: Homework 1 #include <iostream> +#include "menu.hpp" int main() { - std::cout << "Hello World"; + Worker(); return 0; }
\ No newline at end of file diff --git a/CST 126/Homework 1/menu.hpp b/CST 126/Homework 1/menu.hpp new file mode 100644 index 0000000..51f8f0e --- /dev/null +++ b/CST 126/Homework 1/menu.hpp @@ -0,0 +1,74 @@ +#ifndef MENU_H +#define MENU_H + +#include <iostream>; +#include "clear.hpp" +#include "currency.hpp" + +using std::cout; +using std::cin; +using std::endl; + +inline void DisplayMenu() +{ + ClearScreen(); + + cout << "*******************************************************************" << endl; + 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 << "Please pick a number for your choice: "; +} + +inline void Worker() { + + int input = 0; + + DisplayMenu(); + + cin >> input; + + while (input != 5) + { + switch (input) { + case 1: + PickCurrency(); + break; + + case 2: + //guessing game + break; + + case 3: + //call temp logger + break; + + default: + cout << "Invalid option, please pick again..\n"; + + + } + DisplayMenu(); + + cin >> input; + } + + + + + +} + + + + + + + + + + +#endif |