d07 ajouts tests avec fixed et char dans ex01 et ex02

This commit is contained in:
Hugo LAMY
2022-03-18 14:26:15 +01:00
parent b30fdff668
commit 726bd388dd
18 changed files with 1098 additions and 31 deletions

View File

@@ -6,11 +6,22 @@
template < typename T >
class Array {
public:
Array(unsigned int n = 0u)
: _size(n)
, _arr(new T[n]) {};
~Array() { delete [] _arr; };
Array(Array const & src) : _arr(new T[0]) { *this = src; };
Array(unsigned int n = 0U)
: _size(n)
, _arr(new T[n]){
for (unsigned int i = 0; i < n; i++)
_arr[i] = 0;
};
~Array() {
delete [] _arr;
};
Array(Array const & src)
: _arr(new T[0]) {
*this = src;
};
Array &operator=(Array const & rhs) {
if (this == &rhs)
return (*this);

View File

@@ -0,0 +1,55 @@
#ifndef FIXED_HPP
# define FIXED_HPP
#include <iostream>
#include <string>
#include <cmath>
class Fixed {
public:
Fixed(void); // default/parametric constructor
Fixed(Fixed const & src); // copy constructor
~Fixed(void); // destructor
Fixed(int integer);
Fixed(float const floater);
Fixed & operator= (Fixed const & rhs); // assignement operator
bool operator< (Fixed const & rhs) const;
bool operator> (Fixed const & rhs) const;
bool operator<=(Fixed const & rhs) const;
bool operator>=(Fixed const & rhs) const;
bool operator==(Fixed const & rhs) const;
bool operator!=(Fixed const & rhs) const;
Fixed operator+ (Fixed const & rhs) const;
Fixed operator- (Fixed const & rhs) const;
Fixed operator* (Fixed const & rhs) const;
Fixed operator/ (Fixed const & rhs) const;
Fixed & operator++(void); // prefix ++o
Fixed & operator--(void); // prefix --o
Fixed operator++(int); // postfix o++
Fixed operator--(int); // postfix o--
static const Fixed & min(Fixed const & lhs, Fixed const & rhs);
static const Fixed & max(Fixed const & lhs, Fixed const & rhs);
static Fixed & min(Fixed & lhs, Fixed & rhs);
static Fixed & max(Fixed & lhs, Fixed & rhs);
int getRawBits(void) const;
void setRawBits(int const raw);
float toFloat(void) const;
int toInt(void) const;
private:
int _value;
static int const _frac;
static int const _max;
static int const _min;
};
std::ostream & operator<<(std::ostream & o, Fixed const & rhs);
#endif