upload
This commit is contained in:
commit
d23e932c64
7 changed files with 256 additions and 0 deletions
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/2/L2C",
|
||||||
|
"program": "/home/ty/Dev/School/CSCI200/Sets/2/L2C/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:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
|
||||||
|
"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
|
||||||
|
}
|
69
Makefile
Normal file
69
Makefile
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
TARGET = L2C
|
||||||
|
SRC_FILES = main.cpp coordinate_conversion.cpp
|
||||||
|
|
||||||
|
# Tyler's custom makefile extensions
|
||||||
|
.DEFAULT_GOAL := all # Necessary so `make` doesn't run the "pack" target, as it is declared before "all"
|
||||||
|
.PHONY: pack clean-run c run
|
||||||
|
|
||||||
|
## Adds only the necessary files for build into a .tar.gz file, named appropriately
|
||||||
|
ARCHIVED_FILES = Makefile $(SRC_FILES) $(SRC_FILES:.cpp=.h) $(SRC_FILES:.cpp=.hpp)
|
||||||
|
pack:
|
||||||
|
tar --ignore-failed-read -czvf $(TARGET).tar.gz $(shell echo $(ARCHIVED_FILES) | xargs ls -d 2>/dev/null)
|
||||||
|
|
||||||
|
## Runs the pack target and then attempts to build & run the program to make sure it functions correctly
|
||||||
|
pack-test: pack
|
||||||
|
$(eval TMP := $(shell mktemp -d))
|
||||||
|
tar -xvzf $(TARGET).tar.gz --directory $(TMP)
|
||||||
|
make -C $(TMP)
|
||||||
|
$(TMP)/$(TARGET)
|
||||||
|
rm -rf $(TMP)
|
||||||
|
|
||||||
|
## An extension of the clean command that is shorter to type and removes a potential .tar.gz file
|
||||||
|
c: clean
|
||||||
|
$(DEL) -f $(TARGET).tar.gz
|
||||||
|
|
||||||
|
## Simply builds and then executes the program
|
||||||
|
run: all
|
||||||
|
./$(TARGET)
|
||||||
|
|
||||||
|
# NO EDITS NEEDED BELOW THIS LINE
|
||||||
|
|
||||||
|
CXX = g++
|
||||||
|
CXXFLAGS = -O2
|
||||||
|
CXXFLAGS_DEBUG = -g
|
||||||
|
CXXFLAGS_WARN = -Wall -Wextra -Wunreachable-code -Wshadow -Wpedantic
|
||||||
|
CPPVERSION = -std=c++17
|
||||||
|
|
||||||
|
OBJECTS = $(SRC_FILES:.cpp=.o)
|
||||||
|
|
||||||
|
ifeq ($(shell echo "Windows"), "Windows")
|
||||||
|
TARGET := $(TARGET).exe
|
||||||
|
DEL = del
|
||||||
|
Q =
|
||||||
|
else
|
||||||
|
DEL = rm -f
|
||||||
|
Q = "
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
$(TARGET): $(OBJECTS)
|
||||||
|
$(CXX) -o $@ $^
|
||||||
|
|
||||||
|
.cpp.o:
|
||||||
|
$(CXX) $(CXXFLAGS) $(CPPVERSION) $(CXXFLAGS_DEBUG) $(CXXFLAGS_WARN) -o $@ -c $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(DEL) -f $(TARGET) $(OBJECTS) Makefile.bak
|
||||||
|
|
||||||
|
depend:
|
||||||
|
@sed -i.bak '/^# DEPENDENCIES/,$$d' Makefile
|
||||||
|
@$(DEL) sed*
|
||||||
|
@echo $(Q)# DEPENDENCIES$(Q) >> Makefile
|
||||||
|
@$(CXX) -MM $(SRC_FILES) >> Makefile
|
||||||
|
|
||||||
|
.PHONY: all clean depend
|
||||||
|
|
||||||
|
# DEPENDENCIES
|
||||||
|
main.o: main.cpp coordinate_conversion.h
|
||||||
|
coordinate_conversion.o: coordinate_conversion.cpp
|
17
coordinate_conversion.cpp
Normal file
17
coordinate_conversion.cpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef COORDINATE_CONVERSION_H
|
||||||
|
#define COORDINATE_CONVERSION_H
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
void polar_to_cartesian(double radius, double angle, double *xCoordinate,
|
||||||
|
double *yCoordinate) {
|
||||||
|
*xCoordinate = radius * std::cos(angle);
|
||||||
|
*yCoordinate = radius * std::sin(angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cartesian_to_polar(double xCoordinate, double yCoordinate, double *radius,
|
||||||
|
double *angle) {
|
||||||
|
*radius = std::sqrt(std::pow(xCoordinate, 2) + std::pow(yCoordinate, 2));
|
||||||
|
*angle = std::atan(xCoordinate);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // COORDINATE_CONVERSION_H
|
26
coordinate_conversion.h
Normal file
26
coordinate_conversion.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef COORDINATE_CONVERSION_H
|
||||||
|
#define COORDINATE_CONVERSION_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Converts passed polar coordinates to their cartesian equivalent, using
|
||||||
|
* pass-by-pointer
|
||||||
|
*
|
||||||
|
* @param radius The radius of the polar coordinates
|
||||||
|
* @param angle The angle of the polar coordinates
|
||||||
|
* @param xCoordinate A pointer referencing the variable to place the x component of the cartesian coordinates into
|
||||||
|
* @param yCoordinate A pointer referencing the variable to place the y component of the cartesian coordinates into
|
||||||
|
*/
|
||||||
|
void polar_to_cartesian(double radius, double angle, double* xCoordinate, double* yCoordinate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Converts passed cartesian coordinates to their polar equivalent, using
|
||||||
|
* pass-by-pointer
|
||||||
|
*
|
||||||
|
* @param x The x component of the cartesian coordinates
|
||||||
|
* @param y The y component of the cartesian coordinates
|
||||||
|
* @param radius A pointer referencing the variable to put the radius of the polar coordinates into
|
||||||
|
* @param angle A pointer referencing the variable to put the angle of the polar coordinates into
|
||||||
|
*/
|
||||||
|
void cartesian_to_polar(double xCoordinate, double yCoordinate, double* radius, double* angle);
|
||||||
|
|
||||||
|
#endif // COORDINATE_CONVERSION_H
|
43
main.cpp
Normal file
43
main.cpp
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/* CSCI 200: Lab 2C (Coordinate Conversion By Pointer): Tyler Beckman
|
||||||
|
*
|
||||||
|
* Author: Tyler Beckman
|
||||||
|
*
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
#include "coordinate_conversion.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
char direction = 'P';
|
||||||
|
|
||||||
|
std::cout << "Which coordinate system would you like to convert to? [P]olar - (x, y) -> (r, θ), or [C]artesian - (r, θ) -> (x, y)? ";
|
||||||
|
std::cin >> direction;
|
||||||
|
|
||||||
|
double radius = 0;
|
||||||
|
double angle = 0;
|
||||||
|
double xCoordinate = 0;
|
||||||
|
double yCoordinate = 0;
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case 'P':
|
||||||
|
std::cout << "Please enter the (x, y) coordinates, separated by a space: ";
|
||||||
|
std::cin >> xCoordinate >> yCoordinate;
|
||||||
|
|
||||||
|
cartesian_to_polar(xCoordinate, yCoordinate, &radius, &angle);
|
||||||
|
|
||||||
|
std::cout << "The result (r, θ) is: (" << radius << ", " << angle << ")";
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
std::cout << "Please enter the (r, θ) coordinates, separated by a space: ";
|
||||||
|
std::cin >> radius >> angle;
|
||||||
|
|
||||||
|
polar_to_cartesian(radius, angle, &xCoordinate, &yCoordinate);
|
||||||
|
|
||||||
|
std::cout << "The result (x, y) is: (" << xCoordinate << ", " << yCoordinate << ")";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
std::cout << "\"" << direction << "\" is not a valid option, exiting";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue