I have the following problem that is quite complex and don't have a clue how to solve it:

---

Let's assume that we have got a class that defines the new type calledFaultyUnsignedLongLong, which is similar to standardunsigned long long, but in which some arithmetic operations on numbers in this type are returning false values or are causing errors.

The problem is to create a functionFaultyUnsignedLongLong cprod(const int &fromInt, const int &toInt)that is calculating the product(fromInt)*(fromInt+1)*...*(toInt-1)*(toInt), wherefromIntandtoIntare integers such that0 <= fromInt <= toInt <= 600000.

The typeFaultyUnsignedLongLongis implementing some arithmetic and logical operators. Unfortunately there is always a risk that these operators will returne false results. Arithmetic operations can cause the following exceptions:

-class ErrorCalculation {};- operation caused an error and will not return the result,

-class ErrorPrevCalculation {};- previous arithmetic operation was calculated in the incorrect way, so the result that was returned by this operations has been incorrect,

-class ErrorPrevCalculaionsIncreasedByOne : public ErrorPrevCalculation {};- means that the previous arithmetic operation returned a result that was larger by one than it's true solution,

-class SystemError {};- means that operation has cause an overall reset (values of all variables that were defined asFaultyUnsignedLongLongare change to 0). Such reset could be also cause on purpose - you have to use a static methodreset().

All of the exceptions can occur in a random manner.

The file in which we are implementing the functionFaultyUnsignedLongLong cprod(const int &fromInt, const int &toInt)must have the following properties:

-it should include only the fileFaultyUnsignedLongLong.h,

-using#defineinside the file is forbidden,

-inside the file one can't use or declare any variables of the type other thenFaultyUnsignedLongLong(particullary one can't useconst_cast,type_of,class,structor any other keywords likebool,char,long,floatetc.; theintkeyword can be only used twice in the definition of the functionFaultyUnsignedLongLong cprod(const int &fromInt, const int &toInt),

-there should be only a definition of one function:FaultyUnsignedLongLong cprod(const int &fromInt, const int &toInt)that is calculating the product(fromInt)*(fromInt+1)*...*(toInt-1)*(toInt),

-each of the variablesfromInt,toIntcould be used only 4 times in the file.

A declaration of the classFaultyUnsignedLongLonglooks like that:

and it's source code has the following includes:Code:class FaultyUnsignedLongLong { private: unsigned long long int value; public: FaultyUnsignedLongLong(const unsigned long long int &i = 0); FaultyUnsignedLongLong(const FaultyUnsignedLongLong &i); ~FaultyUnsignedLongLong(); static void reset(); friend FaultyUnsignedLongLong operator+(const FaultyUnsignedLongLong &i, const FaultyUnsignedLongLong &j) throw(ErrorCalculation, ErrorPrevCalculation, SystemError); friend FaultyUnsignedLongLong operator-(const FaultyUnsignedLongLong &i, const FaultyUnsignedLongLong &j) throw(ErrorCalculation, ErrorPrevCalculation, SystemError); friend FaultyUnsignedLongLong operator*(const FaultyUnsignedLongLong &i, const FaultyUnsignedLongLong &j) throw(ErrorCalculation, ErrorPrevCalculation, SystemError); friend FaultyUnsignedLongLong operator/(const FaultyUnsignedLongLong &i, const FaultyUnsignedLongLong &j) throw(ErrorCalculation, ErrorPrevCalculation, SystemError); friend FaultyUnsignedLongLong operator%(const FaultyUnsignedLongLong &i, const FaultyUnsignedLongLong &j) throw(ErrorCalculation, ErrorPrevCalculation, SystemError); friend bool operator==(const FaultyUnsignedLongLong &i, const FaultyUnsignedLongLong &j); friend bool operator!=(const FaultyUnsignedLongLong &i, const FaultyUnsignedLongLong &j); friend bool operator<=(const FaultyUnsignedLongLong &i, const FaultyUnsignedLongLong &j); friend bool operator>=(const FaultyUnsignedLongLong &i, const FaultyUnsignedLongLong &j); };

---Code:#include <map> #include <set> #include <iostream> #include <cstdlib> #include <climits> #include <iosfwd>

I will be very glad if any of you could give me some hints or possible solutions of this problem.