class Sequence {
public:
// The value of the sequence at the current step.
double Value();
// Advances to the next step.
void Next();
};
// 1, 1, 2, 3, 5, 8, ...
class FibonacciSequence : public Sequence {
};
// 1, 1, 2, 6, 24, 120, 720, ... modulo x: if x = 10, that's
// 1, 1, 2, 6, 4, 0, 0, ...
class FactorialModXSequence : public Sequence {
public:
explicit FactorialModXSequence(int x);
};
Veillez à rendre les fonctions de la classe de base Sequence
abstraites.
rm 1.tar.gz; wget --no-cache http://fabien.viger.free.fr/cpp/td11/1.tar.gz tar xf 1.tar.gz make 1.1RENDU: 1.1.h et 1.1.cc
make 1.2RENDU: 1.2.h et 1.2.cc
make 1.3RENDU: 1.3.h et 1.3.cc
rm 2.tar.gz; wget --no-cache http://fabien.viger.free.fr/cpp/td11/2.tar.gz tar xf 2.tar.gz make 2.1Ne changez pas 2.1.h!
#include <exception>
// Converts a string to an integer, with strict checking: throws an exception
// if 'str' doesn't represent an integer in the range [-2^31...2^31-1].
//
// Exceptions thrown:
// - NullPtrException: if str == nullptr.
// - EmptyStrException: if str is empty.
// - BadFormatException: if the string doesn't follow the regexp 0|(-?[1-9][0-9]*)
// - OverflowException: if the string follows the regexp above, but the integer
// is outside p[-2^31...2^31-1].
//
// The last two exceptions take an argument at construction: a string that helps
// to know what failed. Typically it would be the input that's being parsed.
// The first two don't need it, because the context is pretty clear (nullptr
// or empty string).
int ParseInt(const char* str);
using std::exception;
class NullPtrException : public exception {};
class EmptyStrException : public exception {};
class BadFormatException : public exception {
public:
explicit BadFormatException(const char* data) : data_(data) {}
// See http://www.cplusplus.com/reference/exception/exception/what/
const char* what() const throw() override { return data_; }
private:
const char* data_;
};
class OverflowException : public exception {
public:
explicit OverflowException(const char* data) : data_(data) {}
const char* what() const throw() override { return data_; }
private:
const char* data_;
};
RENDU: 2.1.cc
rm 3.tar.gz; wget --no-cache http://fabien.viger.free.fr/cpp/td11/3.tar.gz tar xf 3.tar.gz make 3.1RENDU: 3.1.h