From d16f63cc5f4e523041d058de2b1b2db12a39bc08 Mon Sep 17 00:00:00 2001 From: Tyler Beckman Date: Wed, 28 Aug 2024 22:32:24 -0600 Subject: [PATCH] Upload --- .clang-format | 39 +++++++++++++++++++ .class-clang-format | 39 +++++++++++++++++++ .vscode/c_cpp_properties.json | 18 +++++++++ .vscode/launch.json | 24 ++++++++++++ .vscode/settings.json | 59 ++++++++++++++++++++++++++++ Makefile | 24 ++++++++++++ main.cpp | 72 +++++++++++++++++++++++++++++++++++ 7 files changed, 275 insertions(+) create mode 100644 .clang-format create mode 100644 .class-clang-format create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 Makefile create mode 100644 main.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ffa4e99 --- /dev/null +++ b/.clang-format @@ -0,0 +1,39 @@ +IndentWidth: 4 +UseTab: Always +TabWidth: 4 +InsertBraces: false +SortIncludes: true +IncludeBlocks: Regroup +IncludeCategories: + # System headers from C + - Regex: '<(cassert|ccomplex|cctype|cerrno|cfenv|cfloat|cinttypes|ciso646|climits|clocale|cmath|csetjmp|csignal|cstdalign|cstdarg|cstdatomic|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstdnoreturn|cstring|ctgmath|cthreads|ctime|cuchar|cwchar|cwctype)>' + Priority: 3 + # System headers without extension. + - Regex: '<([A-Za-z0-9\Q/-_\E])+>' + Priority: 2 + # Local headers with extension. + - Regex: '"([A-Za-z0-9\Q/-_\E])+\.h(pp)?"' + Priority: 1 +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +IndentCaseLabels: true +IntegerLiteralSeparator: + Binary: 0 + Decimal: 3 + Hex: -1 \ No newline at end of file diff --git a/.class-clang-format b/.class-clang-format new file mode 100644 index 0000000..278bfcb --- /dev/null +++ b/.class-clang-format @@ -0,0 +1,39 @@ +IndentWidth: 2 +UseTab: Never +TabWidth: 2 +InsertBraces: true +SortIncludes: true +IncludeBlocks: Regroup +IncludeCategories: + # System headers from C + - Regex: '<(cassert|ccomplex|cctype|cerrno|cfenv|cfloat|cinttypes|ciso646|climits|clocale|cmath|csetjmp|csignal|cstdalign|cstdarg|cstdatomic|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstdnoreturn|cstring|ctgmath|cthreads|ctime|cuchar|cwchar|cwctype)>' + Priority: 3 + # System headers without extension. + - Regex: '<([A-Za-z0-9\Q/-_\E])+>' + Priority: 2 + # Local headers with extension. + - Regex: '"([A-Za-z0-9\Q/-_\E])+\.h(pp)?"' + Priority: 1 +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +IndentCaseLabels: true +IntegerLiteralSeparator: + Binary: -1 + Decimal: -1 + Hex: -1 \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..c2098a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..be201d8 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/ty/Dev/School/CSCI200/Sets/1/L1B", + "program": "/home/ty/Dev/School/CSCI200/Sets/1/L1B/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3e5eb95 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6bb17ba --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +TARGET = L1B +SRC_FILES = main.cpp + +# NO EDITS BELOW THIS LINE +CXX = g++ +OBJECTS = $(SRC_FILES:.cpp=.o) + +ifeq ($(shell echo "Windows"), "Windows") + TARGET := $(TARGET).exe + DEL = del +else + DEL = rm -f +endif + +all: $(TARGET) + +$(TARGET): $(OBJECTS) + $(CXX) -std=c++17 -o $@ $^ + +%.o: %.cpp + $(CXX) -std=c++17 -o $@ -c $< + +clean: + $(DEL) $(TARGET) $(OBJECTS) \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..a1a3180 --- /dev/null +++ b/main.cpp @@ -0,0 +1,72 @@ +/* CSCI 200: Lab 1B (Random Classification): Tyler Beckman + * + * Author: Tyler Beckman + * + * A program to generate a random number between user inputted bounds + * (inclusive), and classify it by quartile. In addition, more than one random + * number in the same range can be generated if the user wishes. + */ + +#include +#include +#include +#include + +#include + +float input_float(std::string prompt) { + float out; + while (true) { + std::cout << prompt + ": "; + std::cin >> out; + + if (std::cin.fail()) { + // The clear and ignore are necessary because otherwise it seems to + // keep reusing the first input a person enters + std::cin.clear(); + std::cin.ignore(std::numeric_limits::max(), '\n'); + std::cout << "Invalid number, please make sure your number is formatted " + "correctly." + << std::endl; + } else { + break; + } + } + + return out; +} + +int main(void) { + float min = input_float("Please input the minimum value"), + max = input_float("Please input the maximum value"); + + std::mt19937 mt(std::chrono::steady_clock::now().time_since_epoch().count()); + std::uniform_real_distribution realDist( + min, std::nextafter(max, std::numeric_limits::max())); + + while (true) { + float randomNumber = realDist(mt); + std::cout << "The random value is: " << randomNumber << std::endl; + + float quartileSize = (max - min) / 4.0f; + + if (randomNumber < (min + quartileSize)) { + std::cout << "This number is in the first quartile" << std::endl; + } else if (randomNumber < (min + quartileSize) * 2) { + std::cout << "This number is in the second quartile" << std::endl; + } else if (randomNumber < (min + quartileSize) * 3) { + std::cout << "This number is in the third quartile" << std::endl; + } else { + std::cout << "This number is in the fourth quartile" << std::endl; + } + + char runAgainInput = 'N'; + std::cout << "Do you want another random value? (Y/N) "; + std::cin >> runAgainInput; + + if (runAgainInput == 'N') { + std::cout << "Have a nice day!" << std::endl; + break; + } + } +} \ No newline at end of file