Skip to content

CPP02-ex02 - Now we're talking #39

Description

@TheLeBerton

Files to submit

  • in ex02/ dir
  • Makefile
  • main.cpp
  • Fixed.{h, hpp}
  • Fixed.cpp

Authorized

  • roundf from <cmath>

Definition of done

Add public member functions to the class to overload the following operators:

  • the 6 comparison operators ( >, <, >=, <=, == and != )
  • the 4 arithmetic operators ( +, -, * and / )
  • the 4 increment / decrement operators ( which will increase or decrease the fixed-point value by the smallest representable ϵ, such that 1 + ϵ > 1 )
  • a public static function min that takes two references to fixed-point numbers as parameters and returns a reference to the smallest one
  • a public static function min that takes two references to constant fixed-point numbers as parameters and returns a reference to the smallest one
  • a public static function max that takes two references to fixed-point numbers as parameters and returns a reference to the greatest one
  • a public static function max that takes two references to constant fixed-point numbers as parameters and returns a reference to the greatest one

Testing

Running this code:

#include <iostream>
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;

should output something like this:

$> ./a.out
0
0.00390625
0.00390625
0.00390625
0.0078125
10.1016
10.1016
$>

If the program crashes when dividing by 0, it's acceptable.

Metadata

Metadata

Assignees

Labels

Type

Fields

Priority

High

Projects

  • Status
    Todo

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions