From f94af69b62058b241e569b973a136afb4d331d46 Mon Sep 17 00:00:00 2001 From: Chanin Timbal Date: Sat, 27 Apr 2024 14:05:17 -0700 Subject: Homework 2 first commit --- CST 126/Homework 1/main.cpp | 49 ++++++- CST 126/Homework 2/Homework2/Base64Converter.hpp | 10 ++ CST 126/Homework 2/Homework2/FindingPi.exe | Bin 0 -> 3496762 bytes CST 126/Homework 2/Homework2/Homework2.sln | 31 +++++ CST 126/Homework 2/Homework2/Homework2.vcxproj | 145 +++++++++++++++++++++ .../Homework 2/Homework2/Homework2.vcxproj.filters | 40 ++++++ CST 126/Homework 2/Homework2/destination_file.txt | 0 CST 126/Homework 2/Homework2/helpers.hpp | 88 +++++++++++++ CST 126/Homework 2/Homework2/program.cpp | 70 ++++++++++ 9 files changed, 430 insertions(+), 3 deletions(-) create mode 100644 CST 126/Homework 2/Homework2/Base64Converter.hpp create mode 100644 CST 126/Homework 2/Homework2/FindingPi.exe create mode 100644 CST 126/Homework 2/Homework2/Homework2.sln create mode 100644 CST 126/Homework 2/Homework2/Homework2.vcxproj create mode 100644 CST 126/Homework 2/Homework2/Homework2.vcxproj.filters create mode 100644 CST 126/Homework 2/Homework2/destination_file.txt create mode 100644 CST 126/Homework 2/Homework2/helpers.hpp create mode 100644 CST 126/Homework 2/Homework2/program.cpp diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp index 8d10dad..a82ca3b 100644 --- a/CST 126/Homework 1/main.cpp +++ b/CST 126/Homework 1/main.cpp @@ -11,6 +11,7 @@ using std::cout; using std::cin; //Protoypes +void display_options(); float convert(float input, float output, float amount); void run_conversion(char again); void currency_menu(); @@ -18,15 +19,57 @@ void currency_menu(); //Main to run the program int main() { - char again = 'Y'; + int option = 0; - cout << "Welcome to my currency conversion tool!\n"; + cout << "Welcome! Please choose an option: \n"; + display_options(); + cin >> option; + cin.ignore(100, '\n'); - run_conversion(again); + while (option != 0) + { + if (option == 1) + { + char again = 'Y'; + run_conversion(again); + cin >> again; + cin.ignore(100,'\n'); + } + + else if (option == 2) + { + + } + + else if (option == 3) + { + + } + else + { + cout << "That is not one of the options!"; + display_options(); + cin >> option; + cin.ignore(100, '\n'); + } + + display_options(); + cin >> option; + cin.ignore(100, '\n'); + } return 0; } +//menu options +void display_options() +{ + cout << "1. Currency Converter\n"; + cout << "2. Guessing Game\n"; + cout << "3. Temperature Logger\n"; + cout << "0. Quit\n"; +} + //Conversion Calculator float convert(float input, float output, float amount) { diff --git a/CST 126/Homework 2/Homework2/Base64Converter.hpp b/CST 126/Homework 2/Homework2/Base64Converter.hpp new file mode 100644 index 0000000..704079b --- /dev/null +++ b/CST 126/Homework 2/Homework2/Base64Converter.hpp @@ -0,0 +1,10 @@ +#ifndef BASE64_CONVERTER_HPP +#define BASE64_CONVERTER_HPP + + + + +//encode +//decode + +#endif \ No newline at end of file diff --git a/CST 126/Homework 2/Homework2/FindingPi.exe b/CST 126/Homework 2/Homework2/FindingPi.exe new file mode 100644 index 0000000..4b128d3 Binary files /dev/null and b/CST 126/Homework 2/Homework2/FindingPi.exe differ diff --git a/CST 126/Homework 2/Homework2/Homework2.sln b/CST 126/Homework 2/Homework2/Homework2.sln new file mode 100644 index 0000000..487680b --- /dev/null +++ b/CST 126/Homework 2/Homework2/Homework2.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34723.18 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Homework2", "Homework2.vcxproj", "{D98B5865-9F6A-4BB6-8443-3C88F9825603}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D98B5865-9F6A-4BB6-8443-3C88F9825603}.Debug|x64.ActiveCfg = Debug|x64 + {D98B5865-9F6A-4BB6-8443-3C88F9825603}.Debug|x64.Build.0 = Debug|x64 + {D98B5865-9F6A-4BB6-8443-3C88F9825603}.Debug|x86.ActiveCfg = Debug|Win32 + {D98B5865-9F6A-4BB6-8443-3C88F9825603}.Debug|x86.Build.0 = Debug|Win32 + {D98B5865-9F6A-4BB6-8443-3C88F9825603}.Release|x64.ActiveCfg = Release|x64 + {D98B5865-9F6A-4BB6-8443-3C88F9825603}.Release|x64.Build.0 = Release|x64 + {D98B5865-9F6A-4BB6-8443-3C88F9825603}.Release|x86.ActiveCfg = Release|Win32 + {D98B5865-9F6A-4BB6-8443-3C88F9825603}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1A5DF82F-23DD-44E7-A5EB-9BCB8146727A} + EndGlobalSection +EndGlobal diff --git a/CST 126/Homework 2/Homework2/Homework2.vcxproj b/CST 126/Homework 2/Homework2/Homework2.vcxproj new file mode 100644 index 0000000..6ecd492 --- /dev/null +++ b/CST 126/Homework 2/Homework2/Homework2.vcxproj @@ -0,0 +1,145 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {d98b5865-9f6a-4bb6-8443-3c88f9825603} + Homework2 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CST 126/Homework 2/Homework2/Homework2.vcxproj.filters b/CST 126/Homework 2/Homework2/Homework2.vcxproj.filters new file mode 100644 index 0000000..f608380 --- /dev/null +++ b/CST 126/Homework 2/Homework2/Homework2.vcxproj.filters @@ -0,0 +1,40 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Source Files + + + + + Source Files + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/CST 126/Homework 2/Homework2/destination_file.txt b/CST 126/Homework 2/Homework2/destination_file.txt new file mode 100644 index 0000000..e69de29 diff --git a/CST 126/Homework 2/Homework2/helpers.hpp b/CST 126/Homework 2/Homework2/helpers.hpp new file mode 100644 index 0000000..0aa6251 --- /dev/null +++ b/CST 126/Homework 2/Homework2/helpers.hpp @@ -0,0 +1,88 @@ +#ifndef HELPERS_HPP +#define HELPERS_HPP + + +//file reading things +inline char* ReadTextFromFile(const char* fileName, char* buffer) +{ + return buffer; +} + +inline char* ReadFileAsBinary(const char* fileName, char* buffer) +{ + try + { + //open the fstream in input mode, with binary mode + std::fstream file(fileName, std::ios::in | std::ios::binary); + + if (!file.is.open()) + { + std::cerr << "Could not open file for binary input: " << fileName; + return buffer; + } + + file.seekg(0, std::ios::end); + + std::streamsize size = file.tellg(); + + file.seekg(0, std::ios::beg); + + delete[] buffer; + + buffer = nullptr; + + //size the buffer with a new + buffer = new char[size]; + + file.read(buffer, size); + + file.close(); + + return buffer; + } + catch (const std::exception& ex) + { + std::cerr << "Exception during binary file input: " << fileName << "was not successfully streamed to binary"; + ex.what() + return buffer; + } +} + +//file writing things +inline bool WriteTextToFile(const char* fileName, const char* fileContents) +{ + std::ostream file(fileName); + + if (!file.is_open()) + { + std::cerr << "Could not open file: " << fileName; + return false; + } + + file << fileContents; + + file.close(); + + return false; +} + +inline bool WriteFileFromBinary(const char* fileName, const char* buffer) +{ + return false; +} + + + + + + + + + + + + + + + +#endif \ No newline at end of file diff --git a/CST 126/Homework 2/Homework2/program.cpp b/CST 126/Homework 2/Homework2/program.cpp new file mode 100644 index 0000000..158a2be --- /dev/null +++ b/CST 126/Homework 2/Homework2/program.cpp @@ -0,0 +1,70 @@ +//Chanin Timbal +//Homework 2 +//27 April 2024 + +#include + +#include "helpers.hpp" +#include "Base64Converter.hpp" + +constexpr short ARG_COUNT = 4; + +bool Worker(); +bool Worker(char** argv); + + + +int main(const int argc, char* argv[]) +{ + if (argc == ARG_COUNT) + { + //run the command line version + Worker(argv); + } + return Worker(); +} + +bool Worker() +{ +} + +bool Worker(char** argv) +{ + const char* arg1 = argv[1]; //-e -d + const char* arg2 = argv[2]; //source file name + const char* arg3 = argv[3]; //destination file name + + const char option = arg1[1]; //e or d + + switch (option) + { + case 'e': + //file reading binary + char* buffer = new char[1]; + + buffer = ReadFileAsBinary(arg2, buffer); + //endcoding work + + bool success = WriteTextToFile(arg3, buffer); + + delete[] buffer; + + return success; + case 'd': + //file reading text + //decoding work + //file writing binary + return true; + default: + std::cerr << "Invalid command option\n" << + "Valid commands:\n" << + "\t-e source_file.exe destination_file.exe" << + "\t\tEncodes file in source into text in destination txt file." << + "\t-d source_file.txt destination file.exe" << + "\t\tDecodes text in source file into the destination file.\n\n"; + return false; + } + + + return false; +} \ No newline at end of file -- cgit v1.2.3