Upload
This commit is contained in:
commit
d16f63cc5f
7 changed files with 275 additions and 0 deletions
39
.clang-format
Normal file
39
.clang-format
Normal file
|
@ -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
|
39
.class-clang-format
Normal file
39
.class-clang-format
Normal file
|
@ -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
|
18
.vscode/c_cpp_properties.json
vendored
Normal file
18
.vscode/c_cpp_properties.json
vendored
Normal file
|
@ -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
|
||||
}
|
24
.vscode/launch.json
vendored
Normal file
24
.vscode/launch.json
vendored
Normal file
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
59
.vscode/settings.json
vendored
Normal file
59
.vscode/settings.json
vendored
Normal file
|
@ -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
|
||||
}
|
24
Makefile
Normal file
24
Makefile
Normal file
|
@ -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)
|
72
main.cpp
Normal file
72
main.cpp
Normal file
|
@ -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 <chrono>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <random>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
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<std::streamsize>::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<float> realDist(
|
||||
min, std::nextafter(max, std::numeric_limits<float>::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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue