This commit is contained in:
starnakin 2023-09-26 15:14:25 +02:00
parent 5da9bee747
commit bbb87d690d
2 changed files with 67 additions and 0 deletions

44
ex01/Span.cpp Normal file
View File

@ -0,0 +1,44 @@
#include "Span.hpp"
#include <bits/stdc++.h>
Span::Span()
{}
Span::Span(unsigned int N):
_size(N)
{
}
Span::Span(const Span& src)
{
*this = src;
}
Span::~Span()
{
}
Span& Span::operator=(const Span& src)
{
this->_size = src._size;
this->_vector = src._vector;
return *this;
}
int Span::shortestSpan() const
{
return *std::min_element(_vector.begin(), _vector.end());
}
int Span::longestSpan() const
{
return *std::max_element(_vector.begin(), _vector.end());
}
void Span::addNumber(const int nb)
{
if (this->_vector.size() == this->_size)
throw std::exception();
this->_vector[this->_size] = nb;
this->_size++;
}

23
ex01/Span.hpp Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include <vector>
class Span
{
private:
unsigned int _size;
std::vector<int> _vector;
Span();
public:
Span(unsigned int N);
Span(const Span& src);
~Span();
Span& operator=(const Span& src);
int shortestSpan() const;
int longestSpan() const;
void addNumber(const int nb);
};