diff --git a/exercise/01/Release/color_test.iobj b/exercise/01/Release/color_test.iobj new file mode 100644 index 0000000..1213c83 Binary files /dev/null and b/exercise/01/Release/color_test.iobj differ diff --git a/exercise/01/Release/color_test.ipdb b/exercise/01/Release/color_test.ipdb new file mode 100644 index 0000000..479aa49 Binary files /dev/null and b/exercise/01/Release/color_test.ipdb differ diff --git a/exercise/01/color.cpp b/exercise/01/color.cpp new file mode 100644 index 0000000..b5a73cd --- /dev/null +++ b/exercise/01/color.cpp @@ -0,0 +1,66 @@ +#include "stdafx.h" +#include "color.h" +#include + +// Error C2678 binary '==': no operator found which takes a left - hand operand of type 'const T' +bool color::operator==(const color& other) const +{ + return red == other.red && green == other.green && blue == other.blue; +} + +double color::get_red() const +{ + return red; +} + +double color::get_green() const +{ + return green; +} + +double color::get_blue() const +{ + return blue; +} + + +double setToValidRange(double val) +{ + if (val < 0.0) + val = 0.0; + else if (val > 1.0) + val = 1.0; + return val; + +} + +void color::set_red(double red) +{ + this->red = setToValidRange(red); +} +void color::set_green(double green) +{ + this->green = setToValidRange(green); +} +void color::set_blue(double blue) +{ + this->blue = setToValidRange(blue); +} + +color::color(double red, double green, double blue) +{ + set_red(red); + set_green(green); + set_blue(blue); +} + +unsigned long color::get_color_ref() const +{ + return RGB(static_cast(red * 255), static_cast(green * 255), static_cast(blue * 255)); + //return RGB((int)red * 255, (int)green * 255, (int)blue * 255); +} + +double color::get_luminance() const +{ + return 0.2126*red + 0.7152*green + 0.0722*blue; +} diff --git a/exercise/01/color.h b/exercise/01/color.h new file mode 100644 index 0000000..50d155e --- /dev/null +++ b/exercise/01/color.h @@ -0,0 +1,26 @@ +#pragma once + +class color +{ +private: + double red; + double green; + double blue; + +public: + color(double r = 0.0, double g = 0.0, double b = 0.0); + double get_red() const; + double get_green() const; + double get_blue() const; + + void set_red(double value); + void set_green(double value); + void set_blue(double value); + + // Error C2678 binary '==': no operator found which takes a left - hand operand of type 'const T' + bool operator==(const color& other) const; + + unsigned long get_color_ref() const; + double get_luminance() const; + +}; \ No newline at end of file diff --git a/exercise/01/colorD.cpp b/exercise/01/colorD.cpp new file mode 100644 index 0000000..e25c9a3 --- /dev/null +++ b/exercise/01/colorD.cpp @@ -0,0 +1,48 @@ +#include "stdafx.h" +#include "color.h" +#include + const double color_min = 0.0; +const double color_max = 1.0; + color::color(double r, double g, double b) : + red(std::clamp(r, color_min, color_max)), + green(std::clamp(g, color_min, color_max)), + blue(std::clamp(b, color_min, color_max)) +{ } + double color::get_red() const +{ + return red; +} + double color::get_green() const +{ + return green; +} + double color::get_blue() const +{ + return blue; +} + void color::set_red(const double value) +{ + red = std::clamp(value, color_min, color_max); +} + void color::set_green(const double value) +{ + green = std::clamp(value, color_min, color_max); +} + void color::set_blue(const double value) +{ + blue = std::clamp(value, color_min, color_max); +} + bool color::operator==(const color& other) const +{ + return red == other.red && green == other.green && blue == other.blue; +} + COLORREF color::get_color_ref() const +{ + return RGB(static_cast (red * 255), + static_cast (green * 255), + static_cast (blue * 255)); +} + double color::get_luminance() const +{ + return 0.2126 * red + 0.7152 * green + 0.0722* blue; +} \ No newline at end of file diff --git a/exercise/01/colorD.h b/exercise/01/colorD.h new file mode 100644 index 0000000..1c0ee66 --- /dev/null +++ b/exercise/01/colorD.h @@ -0,0 +1,20 @@ +#pragma once +#include + class color +{ +public: + color(double r = 0.0, double g = 0.0, double b = 0.0); + double get_red() const; + double get_green() const; + double get_blue() const; + void set_red(double value); + void set_green(double value); + void set_blue(double value); + bool operator==(const color& other) const; + COLORREF get_color_ref() const; + double get_luminance() const; + private: + double red; + double green; + double blue; +}; \ No newline at end of file diff --git a/exercise/01/color_test.cpp b/exercise/01/color_test.cpp index 1af693e..fd81863 100644 --- a/exercise/01/color_test.cpp +++ b/exercise/01/color_test.cpp @@ -66,7 +66,7 @@ namespace color_test Assert::AreEqual(a, b); Assert::AreEqual(a, c); } - + TEST_METHOD(test_conversion_colorref) { Assert::AreEqual(RGB(255, 0, 0), color( 1, 0, 0 ).get_color_ref()); @@ -84,6 +84,6 @@ namespace color_test Assert::AreEqual(0.0722, color( 0, 0, 1 ).get_luminance()); Assert::AreEqual( 1., color( 1, 1, 1 ).get_luminance()); } - + }; } \ No newline at end of file diff --git a/exercise/01/color_test.sln b/exercise/01/color_test.sln new file mode 100644 index 0000000..3a5c11d --- /dev/null +++ b/exercise/01/color_test.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2050 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "color_test", "color_test.vcxproj", "{F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Debug|x64.ActiveCfg = Debug|x64 + {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Debug|x64.Build.0 = Debug|x64 + {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Debug|x86.ActiveCfg = Debug|Win32 + {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Debug|x86.Build.0 = Debug|Win32 + {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Release|x64.ActiveCfg = Release|x64 + {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Release|x64.Build.0 = Release|x64 + {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Release|x86.ActiveCfg = Release|Win32 + {F6408CAA-4C86-4D98-8D13-9AF4DF77D23B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8A6DA6F2-69B3-42AA-BE15-F8B8E72FECF2} + EndGlobalSection +EndGlobal diff --git a/exercise/01/color_test.vcxproj b/exercise/01/color_test.vcxproj index 261fee9..8af7123 100644 --- a/exercise/01/color_test.vcxproj +++ b/exercise/01/color_test.vcxproj @@ -1,175 +1,180 @@ - - - - - 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/01/x64/Release/color_test.iobj b/exercise/01/x64/Release/color_test.iobj new file mode 100644 index 0000000..fcde54b Binary files /dev/null and b/exercise/01/x64/Release/color_test.iobj differ diff --git a/exercise/01/x64/Release/color_test.ipdb b/exercise/01/x64/Release/color_test.ipdb new file mode 100644 index 0000000..9f2d750 Binary files /dev/null and b/exercise/01/x64/Release/color_test.ipdb differ diff --git a/exercise/02/array.cpp b/exercise/02/array.cpp index 9247ffd..9f741f4 100644 --- a/exercise/02/array.cpp +++ b/exercise/02/array.cpp @@ -1 +1,62 @@ -#include "array.h" +#include "array.h" +#include +//array_default_constructor +array::array() : p(nullptr),n(0) +{ +} + +//array_constructor +array::array(int size, double value) +{ + if (size > 0) + { + n = size; + p = new double[n]; + for (int i = 0; i < n; i++) + p[i] = value; + } + else + { + n = 0; + p = nullptr; + } + } + + +int array::size() const +{ + return n; +} + +double array::at(int index) const +{ + // array_index_invalid_large and array_index_invalid_negative + if (index < 0 || index >= n) + { + throw std::out_of_range("Index is out of range!"); + } + return p[index]; +} + + +array::array(const array& other) +{ + n = other.n; + if (n > 0) + { + p = new double[n]; + for (int i = 0; i < n; i++) + p[i] = other.p[i]; + } +} + + +// +//array::~array() +//{ +// if (p) +// { +// delete[] p; +// p = nullptr; +// } +//} \ No newline at end of file diff --git a/exercise/02/array.h b/exercise/02/array.h index 20489df..30e58b6 100644 --- a/exercise/02/array.h +++ b/exercise/02/array.h @@ -4,4 +4,10 @@ class array double* p; int n; public: + array(); + array(int size, double value); + int size() const; + double at(int index) const; + array(const array& other); + //~array(); }; diff --git a/exercise/02/array.sln b/exercise/02/array.sln new file mode 100644 index 0000000..c5f8bb5 --- /dev/null +++ b/exercise/02/array.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2050 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "array", "array.vcxproj", "{BB15329E-10D8-4740-94BC-64C50BA4EE12}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BB15329E-10D8-4740-94BC-64C50BA4EE12}.Debug|x86.ActiveCfg = Debug|Win32 + {BB15329E-10D8-4740-94BC-64C50BA4EE12}.Debug|x86.Build.0 = Debug|Win32 + {BB15329E-10D8-4740-94BC-64C50BA4EE12}.Release|x86.ActiveCfg = Release|Win32 + {BB15329E-10D8-4740-94BC-64C50BA4EE12}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {377FD41D-9D71-4C3A-A895-E3E31A996A64} + EndGlobalSection +EndGlobal diff --git a/exercise/02/test.cpp b/exercise/02/test.cpp index 1adae67..55ed1b2 100644 --- a/exercise/02/test.cpp +++ b/exercise/02/test.cpp @@ -12,73 +12,59 @@ 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)); - */ } }; diff --git a/exercise/03/operators.sln b/exercise/03/operators.sln new file mode 100644 index 0000000..c398cd2 --- /dev/null +++ b/exercise/03/operators.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2050 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "operators", "operators.vcxproj", "{86A75A8D-048F-4B18-A466-A62C44E92490}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {86A75A8D-048F-4B18-A466-A62C44E92490}.Debug|x86.ActiveCfg = Debug|Win32 + {86A75A8D-048F-4B18-A466-A62C44E92490}.Debug|x86.Build.0 = Debug|Win32 + {86A75A8D-048F-4B18-A466-A62C44E92490}.Release|x86.ActiveCfg = Release|Win32 + {86A75A8D-048F-4B18-A466-A62C44E92490}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {41933DBD-23C9-46AE-89F5-C87358DE1E42} + EndGlobalSection +EndGlobal diff --git a/exercise/03/pch.h b/exercise/03/pch.h new file mode 100644 index 0000000..9cf6cd8 Binary files /dev/null and b/exercise/03/pch.h differ diff --git a/exercise/03/point.cpp b/exercise/03/point.cpp index 5c7c45f..bff5335 100644 --- a/exercise/03/point.cpp +++ b/exercise/03/point.cpp @@ -1,2 +1,21 @@ -#include "point.h" - +#include "point.h" + +point::point(int a, int b) :point_a(a), point_b(b) +{ + +} + +bool point::operator==(const point& other) const +{ + return point_a==other.point_a && point_b == other.point_b; +} + +bool point::operator!=(const point& other) const +{ + return point_a != other.point_a && point_b != other.point_b; +} + +bool point::operator<(const point& other) const +{ + return point_a < other.point_a || point_b < other.point_b; +} \ No newline at end of file diff --git a/exercise/03/point.h b/exercise/03/point.h index e69de29..1325e5b 100644 --- a/exercise/03/point.h +++ b/exercise/03/point.h @@ -0,0 +1,12 @@ + +class point +{ + int point_a, point_b; + +public: + point(int a = 0, int b = 0); + bool operator==(const point& other) const; + bool operator!=(const point& other) const; + bool operator<(const point& other) const; + +}; 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)); - */ } };