diff options
| -rw-r--r-- | cpp02/ex00/Fixed.cpp | 5 | ||||
| -rw-r--r-- | cpp02/ex01/Fixed.cpp | 2 | ||||
| -rw-r--r-- | cpp02/ex01/Fixed.hpp | 10 | ||||
| -rw-r--r-- | cpp02/ex01/main_DO_NOT_TURN_ME_IN.cpp (renamed from cpp02/ex01/main.cpp) | 7 | ||||
| -rw-r--r-- | cpp02/ex02/Fixed.cpp | 16 | ||||
| -rw-r--r-- | cpp02/ex02/Fixed.hpp | 8 | ||||
| -rw-r--r-- | cpp02/ex02/main.cpp | 30 | ||||
| -rw-r--r-- | cpp02/ex02/main_DO_NOT_TURN_ME_IN.cpp | 106 |
8 files changed, 126 insertions, 58 deletions
diff --git a/cpp02/ex00/Fixed.cpp b/cpp02/ex00/Fixed.cpp index fc50102..091cb0b 100644 --- a/cpp02/ex00/Fixed.cpp +++ b/cpp02/ex00/Fixed.cpp @@ -6,14 +6,13 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 11:45:18 by charles #+# #+# */ -/* Updated: 2020/11/09 13:07:28 by cacharle ### ########.fr */ +/* Updated: 2020/11/10 09:50:15 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "Fixed.hpp" -Fixed::Fixed() - : m_value(0) +Fixed::Fixed() : m_value(0) { std::cout << "Default constructor called" << std::endl; } diff --git a/cpp02/ex01/Fixed.cpp b/cpp02/ex01/Fixed.cpp index 14ba1c6..759807b 100644 --- a/cpp02/ex01/Fixed.cpp +++ b/cpp02/ex01/Fixed.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 11:45:18 by charles #+# #+# */ -/* Updated: 2020/11/09 13:11:29 by cacharle ### ########.fr */ +/* Updated: 2020/11/10 09:59:45 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/cpp02/ex01/Fixed.hpp b/cpp02/ex01/Fixed.hpp index 1f768f6..43edba2 100644 --- a/cpp02/ex01/Fixed.hpp +++ b/cpp02/ex01/Fixed.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 11:40:49 by charles #+# #+# */ -/* Updated: 2020/11/09 13:11:15 by cacharle ### ########.fr */ +/* Updated: 2020/11/10 10:02:06 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,13 +27,11 @@ public: Fixed(const int from); Fixed(const float from); - int getRawBits() const; - void setRawBits(int const raw); - int getRawBits() const; void setRawBits(int const raw); - float toFloat() const; - int toInt() const; + + float toFloat(void) const; // void asked by subject + int toInt(void) const; static int getFractionalBits(); diff --git a/cpp02/ex01/main.cpp b/cpp02/ex01/main_DO_NOT_TURN_ME_IN.cpp index 34d365a..f2eb5e0 100644 --- a/cpp02/ex01/main.cpp +++ b/cpp02/ex01/main_DO_NOT_TURN_ME_IN.cpp @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* main.cpp :+: :+: :+: */ +/* main_DO_NOT_TURN_ME_IN.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 11:51:15 by charles #+# #+# */ -/* Updated: 2020/10/19 11:28:50 by cacharle ### ########.fr */ +/* Updated: 2020/11/10 10:00:32 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,12 +15,13 @@ int main(void) { - Fixed a; + Fixed a; Fixed const b(10); Fixed const c(42.42f); Fixed const d(b); a = Fixed(1234.4321f); + std::cout << "a is " << a << std::endl; std::cout << "b is " << b << std::endl; std::cout << "c is " << c << std::endl; diff --git a/cpp02/ex02/Fixed.cpp b/cpp02/ex02/Fixed.cpp index 7769083..085b16f 100644 --- a/cpp02/ex02/Fixed.cpp +++ b/cpp02/ex02/Fixed.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 11:45:18 by charles #+# #+# */ -/* Updated: 2020/10/19 12:41:30 by cacharle ### ########.fr */ +/* Updated: 2020/11/10 12:00:43 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,14 +64,12 @@ Fixed& Fixed::operator--() { m_value++; return *this; } Fixed Fixed::operator++(int) { Fixed copy(*this); m_value++; return copy; } Fixed Fixed::operator--(int) { Fixed copy(*this); m_value--; return copy; } -bool Fixed::operator<(Fixed const& other) const { return m_value < other.m_value; } -bool Fixed::operator>(Fixed const& other) const { return m_value > other.m_value; } -bool Fixed::operator<=(Fixed const& other) const { return !(*this > other); } -bool Fixed::operator>=(Fixed const& other) const { return !(*this < other); } -bool Fixed::operator==(Fixed const& other) const { return m_value == other.m_value; } -bool Fixed::operator!=(Fixed const& other) const { return !(*this == other); } - -int Fixed::getFractionalBits() { return m_fractionalBits; } +bool Fixed::operator<(Fixed const& other) const { return m_value < other.m_value; } +bool Fixed::operator>(Fixed const& other) const { return m_value > other.m_value; } +bool Fixed::operator<=(Fixed const& other) const { return *this < other || *this == other; } +bool Fixed::operator>=(Fixed const& other) const { return *this > other || *this == other; } +bool Fixed::operator==(Fixed const& other) const { return m_value == other.m_value; } +bool Fixed::operator!=(Fixed const& other) const { return !(*this == other); } Fixed& Fixed::max(Fixed& a, Fixed& b) { return a > b ? a : b; } Fixed& Fixed::min(Fixed& a, Fixed& b) { return a < b ? a : b; } diff --git a/cpp02/ex02/Fixed.hpp b/cpp02/ex02/Fixed.hpp index d839260..fe63381 100644 --- a/cpp02/ex02/Fixed.hpp +++ b/cpp02/ex02/Fixed.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 11:40:49 by charles #+# #+# */ -/* Updated: 2020/10/19 12:41:46 by cacharle ### ########.fr */ +/* Updated: 2020/11/10 11:06:40 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,15 +55,11 @@ public: static const Fixed& max(Fixed const& a, Fixed const& b); static const Fixed& min(Fixed const& a, Fixed const& b); - static int getFractionalBits(); - private: - int m_value; + int m_value; static int const m_fractionalBits = 8; }; std::ostream& operator<<(std::ostream& out, Fixed const& f); - - #endif diff --git a/cpp02/ex02/main.cpp b/cpp02/ex02/main.cpp deleted file mode 100644 index 7625260..0000000 --- a/cpp02/ex02/main.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* main.cpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/04/13 11:51:15 by charles #+# #+# */ -/* Updated: 2020/10/19 12:42:08 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include <iostream> -#include "Fixed.hpp" - -int main(void) -{ - Fixed a; - Fixed const b(Fixed(5.05f) * Fixed(2)); - - std::cout << a << std::endl; - std::cout << ++a << std::endl; - std::cout << a << std::endl; - std::cout << a++ << std::endl; - std::cout << a << std::endl; - std::cout << b << std::endl; - std::cout << Fixed::max(a, b) << std::endl; - - return 0; -} diff --git a/cpp02/ex02/main_DO_NOT_TURN_ME_IN.cpp b/cpp02/ex02/main_DO_NOT_TURN_ME_IN.cpp new file mode 100644 index 0000000..c7477e6 --- /dev/null +++ b/cpp02/ex02/main_DO_NOT_TURN_ME_IN.cpp @@ -0,0 +1,106 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main_DO_NOT_TURN_ME_IN.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 11:51:15 by charles #+# #+# */ +/* Updated: 2020/11/10 11:58:30 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <iostream> +#include "Fixed.hpp" + +int main(void) +{ + std::cout << "=== SUBJECT TESTS ===" << std::endl; + Fixed a; + Fixed const b(Fixed(5.05f) * Fixed(2)); + std::cout << a << std::endl; + std::cout << ++a << std::endl; + std::cout << a << std::endl; + std::cout << a++ << std::endl; + std::cout << a << std::endl; + std::cout << b << std::endl; + std::cout << Fixed::max(a, b) << std::endl; + + std::cout << std::endl << "=== SUBJECT 01 TESTS ===" << std::endl; + Fixed e; + Fixed const f(10); + Fixed const c(42.42f); + Fixed const d(b); + e = Fixed(1234.4321f); + std::cout << "e is " << e << std::endl; + std::cout << "f is " << f << std::endl; + std::cout << "c is " << c << std::endl; + std::cout << "d is " << d << std::endl; + std::cout << "e is " << e.toInt() << " as integer" << std::endl; + std::cout << "f is " << f.toInt() << " as integer" << std::endl; + std::cout << "c is " << c.toInt() << " as integer" << std::endl; + std::cout << "d is " << d.toInt() << " as integer" << std::endl; + + std::cout << std::boolalpha; + std::cout << std::endl << "=== OPERATORS TESTS ===" << std::endl; + Fixed x(3.3f); + Fixed y(3.5f); + std::cout << "x is " << x << std::endl; + std::cout << "y is " << y << std::endl; + std::cout << "x + y = " << (x + y) << std::endl; + std::cout << "x - y = " << (x - y) << std::endl; + std::cout << "x * y = " << (x * y) << std::endl; + std::cout << "x / y = " << (x / y) << std::endl; + + std::cout << std::endl << "=== COMPARISON TESTS ===" << std::endl; + Fixed z(x); + std::cout << "x is " << x << std::endl; + std::cout << "y is " << y << std::endl; + std::cout << "z is " << z << std::endl; + std::cout << "x > y = " << (x > y)<< std::endl; + std::cout << "x < y = " << (x < y)<< std::endl; + std::cout << "x >= y = " << (x >= y)<< std::endl; + std::cout << "x <= y = " << (x <= y)<< std::endl; + std::cout << "x == y = " << (x == y)<< std::endl; + std::cout << "x != y = " << (x != y)<< std::endl; + std::cout << std::endl; + std::cout << "x > z = " << (x > z)<< std::endl; + std::cout << "x < z = " << (x < z)<< std::endl; + std::cout << "x >= z = " << (x >= z)<< std::endl; + std::cout << "x <= z = " << (x <= z)<< std::endl; + std::cout << "x == z = " << (x == z)<< std::endl; + std::cout << "x != z = " << (x != z)<< std::endl; + std::cout << std::endl; + std::cout << "y > z = " << (y > z)<< std::endl; + std::cout << "y < z = " << (y < z)<< std::endl; + std::cout << "y >= z = " << (y >= z)<< std::endl; + std::cout << "y <= z = " << (y <= z)<< std::endl; + std::cout << "y == z = " << (y == z)<< std::endl; + std::cout << "y != z = " << (y != z)<< std::endl; + + std::cout << std::endl << "=== MAX/MIN TESTS ===" << std::endl; + std::cout << "x is " << x << std::endl; + std::cout << "y is " << y << std::endl; + std::cout << "z is " << z << std::endl; + std::cout << "Fixed::max(x, y): " << Fixed::max(x, y) << std::endl; + std::cout << "Fixed::max(x, z): " << Fixed::max(x, z) << std::endl; + std::cout << "Fixed::max(y, z): " << Fixed::max(y, z) << std::endl; + std::cout << "Fixed::min(x, y): " << Fixed::min(x, y) << std::endl; + std::cout << "Fixed::min(x, z): " << Fixed::min(x, z) << std::endl; + std::cout << "Fixed::min(y, z): " << Fixed::min(y, z) << std::endl; + + const Fixed cx(x); + const Fixed cy(y); + const Fixed cz(z); + std::cout << "cx is " << cx << std::endl; + std::cout << "cy is " << cy << std::endl; + std::cout << "cz is " << cz << std::endl; + std::cout << "Fixed::max(cx, cy): " << Fixed::max(cx, cy) << std::endl; + std::cout << "Fixed::max(cx, cz): " << Fixed::max(cx, cz) << std::endl; + std::cout << "Fixed::max(cy, cz): " << Fixed::max(cy, cz) << std::endl; + std::cout << "Fixed::min(cx, cy): " << Fixed::min(cx, cy) << std::endl; + std::cout << "Fixed::min(cx, cz): " << Fixed::min(cx, cz) << std::endl; + std::cout << "Fixed::min(cy, cz): " << Fixed::min(cy, cz) << std::endl; + + return 0; +} |
