From 351f3f40936fb01f653d2b36e9cbf686291ff97a Mon Sep 17 00:00:00 2001 From: Tyler Beckman Date: Sun, 25 Aug 2024 19:11:50 -0600 Subject: [PATCH] initial commit --- .clang-format | 3 + .class-clang-format | 39 ++++++++ .gitignore | 3 + .vscode/c_cpp_properties.json | 18 ++++ .vscode/launch.json | 24 +++++ .vscode/settings.json | 59 ++++++++++++ main.cpp | 174 ++++++++++++++++++++++++++++++++++ 7 files changed, 320 insertions(+) create mode 100644 .clang-format create mode 100644 .class-clang-format create mode 100644 .gitignore create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 main.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..9e0cc5b --- /dev/null +++ b/.clang-format @@ -0,0 +1,3 @@ +IndentWidth: 4 +UseTab: Always +TabWidth: 4 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/.gitignore b/.gitignore new file mode 100644 index 0000000..2ad0747 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.out +artifacts/ +cmake-build-debug/ \ 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..4218441 --- /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/L1A", + "program": "/home/ty/Dev/School/CSCI200/Sets/1/L1A/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/main.cpp b/main.cpp new file mode 100644 index 0000000..b3e3bf6 --- /dev/null +++ b/main.cpp @@ -0,0 +1,174 @@ +/* CSCI 200: Lab XX (_INSERT_LAB_HERE_): XXXX (_GIVE_BRIEF_DESCRIPTION_HERE_) + * + * Author: XXXX (_INSERT_YOUR_NAME_HERE_) + * + * More complete description here... + */ +#include + +#include + +double const MOLAR_GAS_CONSTANT = 8.314'462'618'153'24; +double const GRAVITATIONAL_CONSTANT = 0.000'000'000'066'740'8; +double const SPHERE_VOLUME = 4.0 / 3; +double const VACUUM_PERMITTIVITY = 0.000'000'000'008'854'187'818'8; + +double ideal_gas_law(double moles, double gas_absolute_temperature, + double volume) { + return (moles * MOLAR_GAS_CONSTANT * gas_absolute_temperature) / volume; +} + +double average_acceleration(double pos_start, double pos_end, double time_start, + double time_end) { + return (pos_end - pos_start) / std::pow(time_end - time_start, 2); +} + +double ohms_law(double voltage, double resistance) { + return voltage / resistance; +} + +double universal_gravitation(double mass_one, double mass_two, + double distance) { + return GRAVITATIONAL_CONSTANT * + ((mass_one * mass_two) / std::pow(distance, 2)); +} + +double pythagorean_theorem(double x, double y) { + return std::sqrt(std::pow(x, 2) + std::pow(y, 2)); +} + +double sphere_volume(double radius) { + return SPHERE_VOLUME * M_PI * std::pow(radius, 3); +} + +double deflection(double weight, double length, double elasticity_modulus, + double moment_of_inertia) { + return (weight * std::pow(length, 3)) / + (3 * elasticity_modulus * moment_of_inertia); +} + +double heat_transfer_rate(double transfer_coefficient, double surface_area, + double temperature_change) { + return transfer_coefficient * surface_area * temperature_change; +} + +double stress(double force, double area) { return force / area; } + +double shear_stress(double sigma_x, double sigma_y, double tau_xy, + double theta) { + return -0.5 * (sigma_x - sigma_y) * sin(2 * theta) + tau_xy * cos(2 * theta); +} + +double coulombs_law(double charge_1, double charge_2, + double relative_static_permittivity, double distance) { + return std::fabs(charge_1 * charge_2) / + (4 * M_PI * VACUUM_PERMITTIVITY * relative_static_permittivity * + std::pow(distance, 2)); +} + +double input_double(std::string prompt) { + double out; + while (true) { + std::cout << prompt + ": "; + std::cin >> out; + + if (std::cin.fail()) { + std::cin.clear(); + std::cin.ignore(std::numeric_limits::max(), '\n'); + std::cout << "Invalid number, Please try again" << std::endl; + } else { + break; + } + } + + return out; +} + +int main() { + while (true) { + std::cout << "[0] Quit program" << std::endl + << "[1] Ideal gas law" << std::endl + << "[2] Average acceleration" << std::endl + << "[3] Ohm's law" << std::endl + << "[4] Universal gravitation" << std::endl + << "[5] Pythagorean theorem" << std::endl + << "[6] Sphere volume" << std::endl + << "[7] Deflection" << std::endl + << "[8] Heat transfer rate" << std::endl + << "[9] Stress" << std::endl + << "[10] Shear Stress" << std::endl + << "[11] Coulomb's law" << std::endl; + int equation = input_double("Which equation would you like to calculate?"); + + std::string output = ""; + + switch (equation) { + case 0: + return 0; + case 1: + output = ideal_gas_law( + input_double("Please enter amount of moles"), + input_double("Please enter the gas absolute temperate"), + input_double("Please enter the volume")); + break; + case 2: + output = average_acceleration( + input_double("Please enter the starting position"), + input_double("Please enter the ending position"), + input_double("Please enter the starting time"), + input_double("Please enter the ending time")); + break; + case 3: + output = ohms_law(input_double("Please input the voltage"), + input_double("Please input the resistance")); + break; + case 4: + output = universal_gravitation( + input_double("Please input the mass of object 1"), + input_double("Please input the mass of object 2"), + input_double("Please input the distance between objects")); + break; + case 5: + output = + pythagorean_theorem(input_double("Please input the x distance"), + input_double("Please input the y distance")); + break; + case 6: + output = sphere_volume(input_double("Please input the sphere radius")); + break; + case 7: + output = deflection(input_double("Please input the force of weight"), + input_double("Please input the length"), + input_double("Please input the elasticity modulus"), + input_double("Please input the moment of inertia")); + break; + case 8: + output = heat_transfer_rate( + input_double("Please input the transfer coefficient"), + input_double("Please input the surface area"), + input_double("Please input the change in temperature")); + break; + case 9: + output = stress(input_double("Please input the amount of force"), + input_double("Please input the surface area")); + break; + case 10: + output = shear_stress( + input_double("Please enter σ_x"), input_double("Please enter σ_y"), + input_double("Please enter τ_xy"), input_double("Please enter θ")); + break; + case 11: + output = coulombs_law( + input_double("Please input the first charge"), + input_double("Please input the second charge"), + input_double("Please input the relative static permittivity"), + input_double("Please input the distance between charges")); + break; + default: + std::cout << "That is not a valid choice. Please try again." + << std::endl; + continue; + } + std::cout << "The result of that calculation is: " << output << std::endl; + } +} \ No newline at end of file