diff options
| -rw-r--r-- | CST 126/CST_126.sln | 10 | ||||
| -rw-r--r-- | CST 126/Homework 1/CST126_Structures.hpp | 67 | ||||
| -rw-r--r-- | CST 126/Homework 1/Homework 1.vcxproj | 4 | ||||
| -rw-r--r-- | CST 126/Homework 1/Homework 1.vcxproj.filters | 6 | ||||
| -rw-r--r-- | CST 126/Homework 1/helpers.hpp | 145 | ||||
| -rw-r--r-- | CST 126/Homework 1/main.cpp | 84 | ||||
| -rw-r--r-- | CST 126/Homework 1/menu.hpp | 27 | ||||
| -rw-r--r-- | CST 126/Homework 1/new_text.txt | 1 | ||||
| -rw-r--r-- | CST 126/Homework2/Base64Converter.hpp | 12 | ||||
| -rw-r--r-- | CST 126/Homework2/Homework2.cpp | 35 | ||||
| -rw-r--r-- | CST 126/Homework2/Homework2.vcxproj | 141 | ||||
| -rw-r--r-- | CST 126/Homework2/Homework2.vcxproj.filters | 27 |
12 files changed, 495 insertions, 64 deletions
diff --git a/CST 126/CST_126.sln b/CST 126/CST_126.sln index 5a023a6..f1e5ab9 100644 --- a/CST 126/CST_126.sln +++ b/CST 126/CST_126.sln @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Homework 1", "Homework 1\Ho EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Unit_Tests", "Unit_Tests\Unit_Tests.vcxproj", "{068234CA-94BA-4478-96CD-ED417EEC37F7}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Homework2", "Homework2\Homework2.vcxproj", "{FDE89174-89AD-4D1E-BB6F-2568A99A6B22}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -31,6 +33,14 @@ Global {068234CA-94BA-4478-96CD-ED417EEC37F7}.Release|x64.Build.0 = Release|x64 {068234CA-94BA-4478-96CD-ED417EEC37F7}.Release|x86.ActiveCfg = Release|Win32 {068234CA-94BA-4478-96CD-ED417EEC37F7}.Release|x86.Build.0 = Release|Win32 + {FDE89174-89AD-4D1E-BB6F-2568A99A6B22}.Debug|x64.ActiveCfg = Debug|x64 + {FDE89174-89AD-4D1E-BB6F-2568A99A6B22}.Debug|x64.Build.0 = Debug|x64 + {FDE89174-89AD-4D1E-BB6F-2568A99A6B22}.Debug|x86.ActiveCfg = Debug|Win32 + {FDE89174-89AD-4D1E-BB6F-2568A99A6B22}.Debug|x86.Build.0 = Debug|Win32 + {FDE89174-89AD-4D1E-BB6F-2568A99A6B22}.Release|x64.ActiveCfg = Release|x64 + {FDE89174-89AD-4D1E-BB6F-2568A99A6B22}.Release|x64.Build.0 = Release|x64 + {FDE89174-89AD-4D1E-BB6F-2568A99A6B22}.Release|x86.ActiveCfg = Release|Win32 + {FDE89174-89AD-4D1E-BB6F-2568A99A6B22}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CST 126/Homework 1/CST126_Structures.hpp b/CST 126/Homework 1/CST126_Structures.hpp new file mode 100644 index 0000000..5a57b88 --- /dev/null +++ b/CST 126/Homework 1/CST126_Structures.hpp @@ -0,0 +1,67 @@ +#ifndef CST126_STRUCTURES_HPP +#define CST126_STRUCTURES_HPP + +#include <cstdint> +#include <ios> + +typedef unsigned long long uLLong; + +typedef unsigned char BYTE; + +constexpr size_t MAX_STREAM_SIZE = std::numeric_limits<std::streamsize>::max(); + +constexpr uLLong MAX_CHAR = 101; + +union FloatIntUnion +{ + float intFloat; + uint32_t uInt; +}; + +enum TemperatureType +{ + Fahrenheit, + Celsius +}; + +struct DailyTemperature +{ + float highTemp{}; + float lowTemp{}; + TemperatureType tempType{}; +}; + +enum DayOfTheWeek +{ + Sunday = 0, + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday = 6 +}; + +enum Month +{ + January = 1, + February, + March, + April, + May, + June, + July, + August, + September, + October, + November, + December +}; + +struct Date +{ + Month month; + uint8_t day; + uint16_t year; +}; +#endif diff --git a/CST 126/Homework 1/Homework 1.vcxproj b/CST 126/Homework 1/Homework 1.vcxproj index 553addf..3bd210f 100644 --- a/CST 126/Homework 1/Homework 1.vcxproj +++ b/CST 126/Homework 1/Homework 1.vcxproj @@ -136,6 +136,10 @@ <ClInclude Include="GuessingGame.hpp" /> <ClInclude Include="helpers.hpp" /> <ClInclude Include="menu.hpp" /> + <ClInclude Include="CST126_Structures.hpp" /> + </ItemGroup> + <ItemGroup> + <Text Include="new_text.txt" /> </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 a2e2650..b4b385f 100644 --- a/CST 126/Homework 1/Homework 1.vcxproj.filters +++ b/CST 126/Homework 1/Homework 1.vcxproj.filters @@ -29,5 +29,11 @@ <ClInclude Include="GuessingGame.hpp"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="CST126_Structures.hpp"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <Text Include="new_text.txt" /> </ItemGroup> </Project>
\ No newline at end of file diff --git a/CST 126/Homework 1/helpers.hpp b/CST 126/Homework 1/helpers.hpp index f34a66d..d2d52d2 100644 --- a/CST 126/Homework 1/helpers.hpp +++ b/CST 126/Homework 1/helpers.hpp @@ -2,9 +2,13 @@ #define HELPERS_HPP #include <random> +#include <string> +#include <iostream> +#include <fstream> -typedef unsigned long long uLong; -typedef unsigned char BYTE; +using std::cin; +using std::cout; +using std::endl; inline int Random(const int& lowest, const int& highest) { @@ -26,6 +30,7 @@ inline void GenerateRandomNumbers(int arrayToFill[], const int& size) arrayToFill[i] = random_number; } } + inline int add(int num, char myChar) { return num + myChar; @@ -35,11 +40,147 @@ inline int add(int num, int num2, int num3) { return num + num2 + num3; } + inline int add(int num, int num2, int num3, int num4) { return num + num2 + num3 + num4; } +inline int ReadInt(const char* prompt) +{ + using std::cin; + using std::cout; + using std::endl; + + int intVal; + + cout << endl << prompt; + + cin >> intVal; + + while (!cin) + { + cin.clear(); + + cin.ignore(MAX_STREAM_SIZE, '\n'); + + cout << "Invalid integer. Please try again: "; + + cout.flush(); + + cin >> intVal; + } + + cin.ignore(MAX_STREAM_SIZE, '\n'); + + return intVal; +} + +// Improved function for reading strings with user input +inline char* PromptInputNewCharArray(const char* prompt, long long maxLen) +{ + char* inputStr = nullptr; + + try + { + inputStr = new char[maxLen]; + } + catch (const std::exception& ex) + { + delete[] inputStr; + inputStr = nullptr; + std::cerr << "Unable to allocate new char array: " << ex.what(); + return inputStr; + } + + cout << endl << prompt; + + // Ensure the prompt is displayed immediately + cout.flush(); + + cin.get(inputStr, maxLen, '\n'); + + while (!cin) { + + // Clear error flag + cin.clear(); + + // Ignore all characters until a newline + cin.ignore(MAX_STREAM_SIZE, '\n'); + + cout << endl << prompt; + + // Flush again to ensure prompt is visible + cout.flush(); + + cin.get(inputStr, maxLen, '\n'); + } + // Discard any characters remaining in the buffer, including the newline + cin.ignore(MAX_STREAM_SIZE, '\n'); + + return inputStr; +} + +inline std::string PromptInputString(const char* prompt) +{ + std::string line; + + cout << endl << prompt; + + // Ensure the prompt is displayed immediately + cout.flush(); + + std::getline(cin, line); + while (!cin) { + + // Flush again to ensure prompt is visible + cout.flush(); + + // Clear error flag + cin.clear(); + + cout << endl << prompt; + + std::getline(cin, line); + } + return line; +} + +inline bool ReadFromFileToConsole(const char* fileName) +{ + std::ifstream file(fileName); + + if (!file.is_open()) + { + std::cerr << "Could not open file: " << fileName; + return false; + } + std::string line; + while (getline(file, line)) + { + std::cout << line << std::endl; + //does something with the reading of file + } + file.close(); + + return true; +} + +inline bool WriteToFile(const char* fileName, const char* fileContents) +{ + std::ofstream file(fileName); + + if (!file.is_open()) + { + std::cerr << "Could not open file: " << fileName; + return false; + } + file << fileContents; + + file.close(); + + return true; +} #endif diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp index e223d37..57c1541 100644 --- a/CST 126/Homework 1/main.cpp +++ b/CST 126/Homework 1/main.cpp @@ -8,56 +8,68 @@ #include "menu.hpp" #include <bitset> +#include "CST126_Structures.hpp" + using std::cout; using std::endl; -struct DailyTemperature +uLLong MAX_LENGTH = 101; + +struct Array { - int highTemp{}; - int lowTemp{}; + Array() + { + + } }; -enum DayOfTheWeek +void CharArrays() { - Sunday = 0, - Monday, - Tuesday, - Wednesday, - Thursday, - Friday, - Saturday = 6 -}; + char* inputChar = PromptInputNewCharArray("Input a string: ", MAX_LENGTH); + cout << inputChar; + delete[] inputChar; +} -enum Month +void Strings() { - January = 1, - February, - March, - April, - May, - June, - July, - August, - September, - October, - November, - December -}; + std::string myString = "Hello", mySecondString = " World"; + std::string thirdString = myString + mySecondString; + cout << thirdString; + + myString = PromptInputString("Input a new string: "); + cout << myString; +} -struct Date +void WriteToFileExample() { - Month month; - uint8_t day; - uint16_t year; -}; + char* outputToFile = PromptInputNewCharArray("Input to file:", MAX_LENGTH); -union FloatIntUnion + if (WriteToFile("new_text.txt", outputToFile)) + { + cout << "Write to file successful"; + } +} + +void ReadFromFileExample() { - float intFloat; - uint32_t uInt; -}; + if(ReadFromFileToConsole("new_text.txt")) + { + cout << "File read successfully" << endl; + } +} -int main() { +int main(int argc, char* argv[]) { + + int a = 5, b = 10; + bool condition = (a + b) < 15 && b > a; + + // Print the number of command line arguments + cout << "Number of arguments: " << argc << endl; + + // Loop through each argument + for (int i = 0; i < argc; ++i) { + cout << "Argument " << i << ": " << argv[i] << endl; + } return 0; } diff --git a/CST 126/Homework 1/menu.hpp b/CST 126/Homework 1/menu.hpp index 849f21a..c384927 100644 --- a/CST 126/Homework 1/menu.hpp +++ b/CST 126/Homework 1/menu.hpp @@ -8,7 +8,7 @@ using std::cout; using std::cin; using std::endl; -inline void DisplayMenu() { +inline void DisplayMenuHomework1Menu() { cout << "***************************************************************" << endl; cout << "Welcome to the menu!\n"; cout << "1. Currency Converter\n"; @@ -19,34 +19,9 @@ inline void DisplayMenu() { cout << "Please pick a number for your choice: "; } -inline void Worker() { - int input = 0; - DisplayMenu(); - cin >> input; - while (input != 5) - { - switch (input) { - case 1: - //Call Currency Function - break; - case 2: - //Call Guessing Game Function - OutputRandomNumber(); - break; - case 3: - //Call Temperature Logger - break; - default: - cout << "\nInvalid option, please pick again..\n"; - } - DisplayMenu(); - - cin >> input; - } -} #endif
\ No newline at end of file diff --git a/CST 126/Homework 1/new_text.txt b/CST 126/Homework 1/new_text.txt new file mode 100644 index 0000000..699b086 --- /dev/null +++ b/CST 126/Homework 1/new_text.txt @@ -0,0 +1 @@ +This will be the new content.
\ No newline at end of file diff --git a/CST 126/Homework2/Base64Converter.hpp b/CST 126/Homework2/Base64Converter.hpp new file mode 100644 index 0000000..20a1a27 --- /dev/null +++ b/CST 126/Homework2/Base64Converter.hpp @@ -0,0 +1,12 @@ +#ifndef BASE64_CONVERTER_HPP +#define BASE64_CONVERTER_HPP + + + + + + + + + +#endif diff --git a/CST 126/Homework2/Homework2.cpp b/CST 126/Homework2/Homework2.cpp new file mode 100644 index 0000000..7090ffb --- /dev/null +++ b/CST 126/Homework2/Homework2.cpp @@ -0,0 +1,35 @@ +// Name: Arthur Spears +// Class: CST 126 +// Date: 4/24/24 +// Assignment: Homework 2 + +#include "helpers.hpp" +#include <iostream> + + +bool Worker(char** argv); +bool Worker(); + +int main(int argc, char* argv[]) +{ + constexpr short argumentCount = 4; + bool success = false; + + if(argc == argumentCount) + { + return Worker(argv); + } + return Worker(); +} + +bool Worker(char** argv) +{ + //parse arguments + //run encode/decode functions +} + +bool Worker() +{ + //display menu loop + //run encode/decode functions +}
\ No newline at end of file diff --git a/CST 126/Homework2/Homework2.vcxproj b/CST 126/Homework2/Homework2.vcxproj new file mode 100644 index 0000000..c3fc7e0 --- /dev/null +++ b/CST 126/Homework2/Homework2.vcxproj @@ -0,0 +1,141 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>17.0</VCProjectVersion> + <Keyword>Win32Proj</Keyword> + <ProjectGuid>{fde89174-89ad-4d1e-bb6f-2568a99a6b22}</ProjectGuid> + <RootNamespace>Homework2</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <IncludePath>../Homework 1;$(IncludePath)</IncludePath> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="Homework2.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="Base64Converter.hpp" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/CST 126/Homework2/Homework2.vcxproj.filters b/CST 126/Homework2/Homework2.vcxproj.filters new file mode 100644 index 0000000..df37224 --- /dev/null +++ b/CST 126/Homework2/Homework2.vcxproj.filters @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="Homework2.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="Base64Converter.hpp"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> +</Project>
\ No newline at end of file |