Name:
Anonymous
2010-08-24 8:59
#include <iostream>
using std::cout;
using std::endl;
class Integer
{
public:
Integer( int i ) : i_( i ) {}
operator int() { return i_; }
protected:
int i_;
};
class Fibonacci : public Integer
{
public:
Fibonacci( int i );
};
Fibonacci::Fibonacci( int i ) : Integer( i )
{
try {
if ( i == 0 || i == 1 ) {
throw Integer( i );
} else {
throw Integer( Fibonacci( i - 1 ) + Fibonacci( i - 2 ) );
}
} catch ( Integer ex ) {
i_ = ex;
}
}
int main()
{
const int UNTIL = 20;
for ( int loop = 0; loop < UNTIL; ++loop ) {
Fibonacci fibo( loop );
cout << fibo << ' ';
}
cout << endl;
return 0;
}
Name:
Anonymous
2011-02-19 23:50
>>20
You're shifting bits into the I/O, so
logically it uses bitshifts.