From 8fadffb476cbb599cf1bfe232bb9ca30482cde5b Mon Sep 17 00:00:00 2001 From: jadranko lucic Date: Tue, 13 Nov 2018 21:51:39 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Jadranko=20Lu=C4=8Di=C4=87,=20day=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercise/01/color.cpp | 70 +++++ exercise/01/color.h | 25 ++ exercise/01/color_test.cpp | 3 +- exercise/01/color_test.vcxproj | 348 ++++++++++++------------- exercise/01/color_test.vcxproj.filters | 72 ++--- exercise/02/array.cpp | 50 +++- exercise/02/array.h | 56 +++- exercise/02/test.cpp | 15 +- 8 files changed, 409 insertions(+), 230 deletions(-) create mode 100644 exercise/01/color.cpp create mode 100644 exercise/01/color.h diff --git a/exercise/01/color.cpp b/exercise/01/color.cpp new file mode 100644 index 0000000..750a8e0 --- /dev/null +++ b/exercise/01/color.cpp @@ -0,0 +1,70 @@ +#include "stdafx.h" +#include "color.h" +#include // RGB + +color::color(double rn, double gn, double bn ) +{ + this->_rn = fix_value(rn); + this->_gn = fix_value(gn); + this->_bn = fix_value(bn); +} + +color::~color() +{ + +} + +double color::fix_value(double cn) +{ + if (cn < 0) + return 0.; + if (cn > 1.) + return 1.; + return cn; +} + +double color::get_red() const +{ + return this->_rn; +} +double color::get_blue()const +{ + return this->_bn; +} + +double color::get_green()const +{ + return this->_gn; +} + +void color::set_red(double cn) +{ + this->_rn = fix_value(cn); +} + +void color::set_green(double cn) +{ + this->_gn = fix_value(cn); +} + +void color::set_blue(double cn) +{ + this->_bn = fix_value(cn); +} + +COLORREF color::get_color_ref() +{ + COLORREF r = RGB(_rn * 255, _gn * 255, _bn * 255); + return r; + +} + +double color::get_luminance() +{ + return 0.2126*_rn + 0.7152*_gn + 0.0722*_bn; +} + +bool operator==(const color& lhs, const color& rhs) +{ + return true;//kod koji usporeduje svaku boju +} diff --git a/exercise/01/color.h b/exercise/01/color.h new file mode 100644 index 0000000..e8983c0 --- /dev/null +++ b/exercise/01/color.h @@ -0,0 +1,25 @@ +#pragma once +#include // RGB + +class color +{ +public: + color(double rn = 0, double gn = 0, double bn = 0); + ~color(); + double get_red() const; + double get_green() const; + double get_blue() const; + void set_red(double cn); + void set_green(double cn); + void set_blue(double cn); + COLORREF get_color_ref(); + double get_luminance(); + +private: + double fix_value(double rn); + double _rn; + double _gn; + double _bn; +}; + +bool operator==(const color& lhs, const color& rhs); \ No newline at end of file diff --git a/exercise/01/color_test.cpp b/exercise/01/color_test.cpp index 1af693e..84e6f6f 100644 --- a/exercise/01/color_test.cpp +++ b/exercise/01/color_test.cpp @@ -8,7 +8,8 @@ namespace Microsoft { namespace VisualStudio { namespace CppUnitTestFramework { template<> static std::wstring ToString(const color& c) { std::wostringstream ss; ss << c.get_red() << L',' << c.get_green() << L',' << c.get_blue(); - return ss.str(); + ss << L','; + return ss.str(); } }}} diff --git a/exercise/01/color_test.vcxproj b/exercise/01/color_test.vcxproj index 261fee9..c0588af 100644 --- a/exercise/01/color_test.vcxproj +++ b/exercise/01/color_test.vcxproj @@ -1,175 +1,175 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B} - Win32Proj - color_test - 10.0.17134.0 - NativeUnitTestProject - - - - DynamicLibrary - true - v141 - Unicode - false - - - DynamicLibrary - false - v141 - true - Unicode - false - - - DynamicLibrary - true - v141 - Unicode - false - - - DynamicLibrary - false - v141 - true - Unicode - false - - - - - - - - - - - - - - - - - - - - - true - - - true - - - true - - - true - - - - Use - Level3 - Disabled - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;%(PreprocessorDefinitions) - true - stdcpp17 - - - Windows - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - - - - - Use - Level3 - Disabled - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - _DEBUG;%(PreprocessorDefinitions) - true - stdcpp17 - - - Windows - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - - - - - Level3 - Use - MaxSpeed - true - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;%(PreprocessorDefinitions) - true - stdcpp17 - - - Windows - true - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - - - - - Level3 - Use - MaxSpeed - true - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - NDEBUG;%(PreprocessorDefinitions) - true - stdcpp17 - - - Windows - true - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - - - - - - - - - - Create - Create - Create - Create - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B} + Win32Proj + color_test + 10.0.17134.0 + NativeUnitTestProject + + + + DynamicLibrary + true + v141 + Unicode + false + + + DynamicLibrary + false + v141 + true + Unicode + false + + + DynamicLibrary + true + v141 + Unicode + false + + + DynamicLibrary + false + v141 + true + Unicode + false + + + + + + + + + + + + + + + + + + + + + true + + + true + + + true + + + true + + + + Use + Level3 + Disabled + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + stdcpp17 + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Use + Level3 + Disabled + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + true + stdcpp17 + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + stdcpp17 + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + true + stdcpp17 + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/exercise/01/color_test.vcxproj.filters b/exercise/01/color_test.vcxproj.filters index 61bbd8e..53d8354 100644 --- a/exercise/01/color_test.vcxproj.filters +++ b/exercise/01/color_test.vcxproj.filters @@ -1,37 +1,37 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {3f0b361d-e959-4712-bd7f-b211a50b8b89} - - - {a5701a66-1845-4643-b359-7bc01a47fe2d} - - - {ec9c9ba0-fde3-42a6-ad15-1d2221ab37fb} - - - - - Source Files\test - - - Source Files\precompiled - - - Source Files\source - - - - - Source Files\precompiled - - - Source Files\source - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {3f0b361d-e959-4712-bd7f-b211a50b8b89} + + + {a5701a66-1845-4643-b359-7bc01a47fe2d} + + + {ec9c9ba0-fde3-42a6-ad15-1d2221ab37fb} + + + + + Source Files\test + + + Source Files\precompiled + + + Source Files\source + + + + + Source Files\precompiled + + + Source Files\source + + \ No newline at end of file diff --git a/exercise/02/array.cpp b/exercise/02/array.cpp index 9247ffd..4637b5b 100644 --- a/exercise/02/array.cpp +++ b/exercise/02/array.cpp @@ -1 +1,49 @@ -#include "array.h" +#include "array.h" +#include + +//dafault-ne vrijdnosti ne idu u implementaciju konstruktora +array::array(int size, double value) +{ + n = size; + v = value; + p = new double[n]; + for (int i = 0; i < n; i++) + { + p[i] = v; + } +} + +array::~array() +{ + if (p != nullptr) + { + delete[] p; + p = nullptr; + } +} + +array::array(const array& other) +{ + n = other.n; + v = other.v; + p = new double[n]; + for (int i = 0; i < n; i++) + { + p[i] = v; + } + +} + +int array::size() const +{ + return n;; +} + +double array::at(int index) const +{ + if (index > n -1 || index < 0) + { + throw std::out_of_range("index is out of range"); + } + return p[index]; +} diff --git a/exercise/02/array.h b/exercise/02/array.h index 20489df..9b828d1 100644 --- a/exercise/02/array.h +++ b/exercise/02/array.h @@ -1,7 +1,55 @@ -// do not use standard container as member or base class +// do not use standard container as member or base class +#include + class array -{ - double* p; - int n; +{ +private: + double* p; + double v; + int n; + //double* arr = new double[n]; + public: + array(int size = 0, double value = 0); + ~array(); + array(const array& other); + int size() const; + double at(int index) const; + array operator = (array const &other) + { + if (this != &other) + { + delete[] p; + //v = other.v; + //n = other.n; + //p = other.p; + //p = new double[n]; + //for (int i = 0; i < n; i++) + //{ + // p[i] = v; + //} + } + return *this; + } }; + + +//class array +//{ +//public: +// color(double rn = 0, double gn = 0, double bn = 0); +// ~color(); +// double get_green() const; +// double get_blue() const; +// void set_red(double cn); +// void set_green(double cn); +// void set_blue(double cn); +// COLORREF get_color_ref(); +// double get_luminance(); +// +//private: +// double fix_value(double rn); +// double _rn; +// double _gn; +// double _bn; +//}; \ No newline at end of file diff --git a/exercise/02/test.cpp b/exercise/02/test.cpp index 1adae67..98379c1 100644 --- a/exercise/02/test.cpp +++ b/exercise/02/test.cpp @@ -12,73 +12,60 @@ TEST_CLASS(test_array) TEST_METHOD(array_default_constructor) { - /* + array a; Assert::AreEqual(0, a.size()); - */ } TEST_METHOD(array_constructor) { - /* array a(size, value); Assert::AreEqual(size, a.size()); for(int i=0; i(func); - */ } TEST_METHOD(array_index_invalid_negative) { - /* array a(size, value); auto func = [a]() { a.at(-2); }; Assert::ExpectException(func); - */ } TEST_METHOD(array_assignment) { - /* array a(size, value); array b; b = a; Assert::AreEqual(size, b.size()); for (int i = 0; i < b.size(); ++i) Assert::AreEqual(value, b.at(i)); - */ } TEST_METHOD(array_copy_constructor) { - /* array a(size, value); array b(a); Assert::AreEqual(size, b.size()); for (int i = 0; i < b.size(); ++i) Assert::AreEqual(value, b.at(i)); - */ } TEST_METHOD(array_move_constructor) { - /* array a(size, value); array b = std::move(a); Assert::AreEqual(0, a.size()); Assert::AreEqual(size, b.size()); for (int i = 0; i < b.size(); ++i) Assert::AreEqual(value, b.at(i)); - */ } }; From d599a96e1222412d63fecb80278e9065f7565ee1 Mon Sep 17 00:00:00 2001 From: jadranko lucic Date: Tue, 13 Nov 2018 22:56:16 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Jadranko=20Lu=C4=8Di=C4=87=20+=20move=20con?= =?UTF-8?q?str?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercise/02/array.cpp | 9 +++++++++ exercise/02/array.h | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/exercise/02/array.cpp b/exercise/02/array.cpp index 4637b5b..b646878 100644 --- a/exercise/02/array.cpp +++ b/exercise/02/array.cpp @@ -34,6 +34,15 @@ array::array(const array& other) } +array::array(array&& other) { + n = other.n; + v = other.v; + p = other.p; + other.p = nullptr; + other.n = 0; + other.v = 0; +} + int array::size() const { return n;; diff --git a/exercise/02/array.h b/exercise/02/array.h index 9b828d1..5144d05 100644 --- a/exercise/02/array.h +++ b/exercise/02/array.h @@ -13,21 +13,22 @@ class array array(int size = 0, double value = 0); ~array(); array(const array& other); + array(array&& other); int size() const; double at(int index) const; - array operator = (array const &other) + array& operator = (array const &other) { if (this != &other) { delete[] p; - //v = other.v; - //n = other.n; - //p = other.p; - //p = new double[n]; - //for (int i = 0; i < n; i++) - //{ - // p[i] = v; - //} + v = other.v; + n = other.n; + p = other.p; + p = new double[n]; + for (int i = 0; i < n; i++) + { + p[i] = v; + } } return *this; } From 5e8cb8c19de89ac5651eb5e8f87e09040c7fcd9d Mon Sep 17 00:00:00 2001 From: jadranko lucic Date: Wed, 14 Nov 2018 11:12:12 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Jadanko=20Lu=C4=8Di=C4=87=20day2/03?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercise/02/array.h | 2 +- exercise/03/point.cpp | 25 ++++++++++++++++++++++++- exercise/03/point.h | 19 +++++++++++++++++++ exercise/03/test.cpp | 8 -------- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/exercise/02/array.h b/exercise/02/array.h index 5144d05..b66ce59 100644 --- a/exercise/02/array.h +++ b/exercise/02/array.h @@ -16,7 +16,7 @@ class array array(array&& other); int size() const; double at(int index) const; - array& operator = (array const &other) + array& operator= (array const &other) { if (this != &other) { diff --git a/exercise/03/point.cpp b/exercise/03/point.cpp index 5c7c45f..05fee98 100644 --- a/exercise/03/point.cpp +++ b/exercise/03/point.cpp @@ -1,2 +1,25 @@ -#include "point.h" +#include "point.h" + +point::point(int x, int y) +{ + this->X = x; + this->Y = y; +} + +point::~point() +{ + +} +//bool operator==(const point& lp, const point& rp) +//{ +// return lp.X == rp.X && lp.Y == rp.Y; +//} +bool operator!=(const point& lp, const point& rp) +{ + return lp.X != rp.X || lp.Y != rp.Y; +} +bool operator<(const point& lp, const point& rp) +{ + return lp.X*lp.X + lp.Y*lp.Y < rp.X*rp.X + rp.Y*rp.Y; +} diff --git a/exercise/03/point.h b/exercise/03/point.h index e69de29..f832279 100644 --- a/exercise/03/point.h +++ b/exercise/03/point.h @@ -0,0 +1,19 @@ +class point +{ +public: + point(int x = 0, int y = 0); + ~point(); + +//private: + int X; + int Y; + + bool operator==(const point& other) + { + return X == other.X && Y == other.Y; + + } +}; +//bool operator==(const point& lp, const point& rp); +bool operator!=(const point& lp, const point& rp); +bool operator<(const point& lp, const point& rp); \ No newline at end of file diff --git a/exercise/03/test.cpp b/exercise/03/test.cpp index d8e6669..abb842a 100644 --- a/exercise/03/test.cpp +++ b/exercise/03/test.cpp @@ -9,30 +9,22 @@ TEST_CLASS(test_1_operators) TEST_METHOD(point_default_constructor) { - /* Assert::IsTrue(point(0, 0) == point()); - */ } TEST_METHOD(points_equal) { - /* Assert::IsTrue(point(1, 2) == point(1, 2)); Assert::IsTrue(point(-12, -34) == point(-12, -34)); - */ } TEST_METHOD(points_not_equal) { - /* Assert::IsTrue(point(1, 2) != point(2, 1)); Assert::IsTrue(point(-1, -2) != point(1, 2)); - */ } TEST_METHOD(points_sorted_by_first_coordinate_then_second) { - /* Assert::IsTrue(point(1, 2) < point(1, 3)); Assert::IsTrue(point(1, 2) < point(2, 2)); Assert::IsFalse(point(1, 2) < point(1, 2)); - */ } };