aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzedarider <ymherklotz@gmail.com>2016-11-06 21:10:56 +0000
committerzedarider <ymherklotz@gmail.com>2016-11-06 21:10:56 +0000
commit36c282d3212603eb8c395f61fa0e5401ca104587 (patch)
treebb5defc1b801379f04dabf4ab6c7a9b334d919d3
parent1f0e0e1baf5ac536473fcbcd3306d83c8dd46748 (diff)
downloadsecond-year-computing-36c282d3212603eb8c395f61fa0e5401ca104587.tar.gz
second-year-computing-36c282d3212603eb8c395f61fa0e5401ca104587.zip
adding first projectedit
-rw-r--r--labs/Makefile34
-rw-r--r--labs/include/point.hpp35
-rw-r--r--labs/include/triangle.hpp20
-rw-r--r--labs/src/main.cpp11
-rw-r--r--labs/src/point.cpp54
-rw-r--r--labs/src/triangle.cpp24
6 files changed, 178 insertions, 0 deletions
diff --git a/labs/Makefile b/labs/Makefile
new file mode 100644
index 0000000..68d0b8b
--- /dev/null
+++ b/labs/Makefile
@@ -0,0 +1,34 @@
+CC := g++ # this is the main compiler
+# CC := clange --analyze # and comment out the linker last line
+SRCDIR := src
+BUILDDIR := build
+TARGET := bin/points
+
+SRCEXT := cpp
+SOURCES := $(shell find $(SRCDIR) -type f -name "*.$(SRCEXT)")
+OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
+CFLAGS := -g -Wall -Wextra -std=c++14
+LIB :=
+INC := -I include
+
+$(TARGET): $(OBJECTS)
+ @echo " Linking..."
+ @echo " $(CC) $^ -o $(TARGET) $(LIB)"; $(CC) $^ -o $(TARGET) $(LIB)
+
+$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
+ @mkdir -p $(BUILDDIR)
+ @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $<
+
+clean:
+ @echo " Cleaning..."
+ @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET)
+
+# Tests
+tester:
+ @echo " $(CC) $(CFLAGS) test/tester.cpp $(INC) $(LIB) -o bin/tester"; $(CC) $(CFLAGS) test/tester.cpp $(INC) $(LIB) -o bin/tester
+
+# Spikes
+ticket:
+ @echo " $(CC) $(CFLAGS) spikes/ticket.cpp $(INC) $(LIB) -o bin/ticket"; $(CC) $(CFLAGS) spikes/ticket.cpp $(INC) $(LIB) -o bin/ticket
+
+.PHONY: clean
diff --git a/labs/include/point.hpp b/labs/include/point.hpp
new file mode 100644
index 0000000..95458df
--- /dev/null
+++ b/labs/include/point.hpp
@@ -0,0 +1,35 @@
+#ifndef POINT_HPP
+#define POINT_HPP
+
+#include <string>
+#include <sstream>
+#include <cmath>
+
+class Point {
+public:
+ Point() : x(0), y(0), distance(0) {}
+ Point(double x, double y);
+
+ void set(double x, double y);
+ void set_x(double x);
+ void set_y(double y);
+ void origin_symmetry();
+ void translate(Point p);
+
+ double get_x();
+ double get_y();
+ double get_distance();
+ double get_distance(Point p);
+
+ std::string str();
+
+protected:
+private:
+ double x;
+ double y;
+ double distance;
+
+ void calc_distance();
+};
+
+#endif
diff --git a/labs/include/triangle.hpp b/labs/include/triangle.hpp
new file mode 100644
index 0000000..2d2cf88
--- /dev/null
+++ b/labs/include/triangle.hpp
@@ -0,0 +1,20 @@
+#ifndef TRIANGLE_HPP
+#define TRIANGLE_HPP
+
+#include "point.hpp"
+
+class Triangle {
+public:
+ Triangle() : p1(), p2(), p3() {}
+ Triangle(Point p1, Point p2, Point p3);
+
+ void set(Point p1, Point p2, Point p3);
+ void set_point(unsigned point, Point p);
+
+ double perimeter();
+protected:
+private:
+ Point p1, p2, p3;
+};
+
+#endif
diff --git a/labs/src/main.cpp b/labs/src/main.cpp
new file mode 100644
index 0000000..2147b4b
--- /dev/null
+++ b/labs/src/main.cpp
@@ -0,0 +1,11 @@
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+int main(int argc, char* argv[]) {
+ (void)argc;
+ (void)argv;
+
+ return 0;
+}
diff --git a/labs/src/point.cpp b/labs/src/point.cpp
new file mode 100644
index 0000000..1619bb6
--- /dev/null
+++ b/labs/src/point.cpp
@@ -0,0 +1,54 @@
+#include "../include/point.hpp"
+
+Point::Point(double x, double y) {
+ set(x, y);
+}
+
+void Point::set(double x, double y) {
+ set_x(x);
+ set_y(y);
+}
+
+void Point::set_x(double x) {
+ this->x = x;
+ calc_distance();
+}
+
+void Point::set_y(double y) {
+ this->y = y;
+ calc_distance();
+}
+
+void Point::origin_symmetry() {
+ set(-x, -y);
+}
+
+void Point::translate(Point p) {
+ set(x+p.x, y+p.y);
+}
+
+double Point::get_x() {
+ return x;
+}
+
+double Point::get_y() {
+ return y;
+}
+
+double Point::get_distance() {
+ return distance;
+}
+
+double Point::get_distance(Point p) {
+ return sqrt(pow(x-p.x, 2) + pow(y-p.y, 2));
+}
+
+std::string Point::str() {
+ std::stringstream ss;
+ ss << "(" << x << ", " << y << ")";
+ return ss.str();
+}
+
+void Point::calc_distance() {
+ distance = sqrt(pow(x, 2) + pow(y, 2));
+}
diff --git a/labs/src/triangle.cpp b/labs/src/triangle.cpp
new file mode 100644
index 0000000..991de92
--- /dev/null
+++ b/labs/src/triangle.cpp
@@ -0,0 +1,24 @@
+#include "../include/triangle.hpp"
+
+Triangle::Triangle(Point p1, Point p2, Point p3) {
+ set(p1, p2, p3);
+}
+
+void Triangle::set(Point p1, Point p2, Point p3) {
+ this->p1 = p1;
+ this->p2 = p2;
+ this->p3 = p3;
+}
+
+void Triangle::set_point(unsigned point, Point p) {
+ if(point == 1)
+ p1 = p;
+ else if(point == 2)
+ p2 = p;
+ else if(point == 3)
+ p3 = p;
+}
+
+double Triangle::perimeter() {
+ return 0;
+}