Nothing too special, but it was an interesting task.

40 Views
``````#include <cstdlib>
#include <iostream>
#include <vector>
#define VALUE_ 12
using namespace std;

/**
Fibonacci series using template recursion -- successful
*/

class Fibonacci{
private:
vector<bool> analyzed;
bool start;
unsigned short current, firstN;

public:
Fibonacci(): analyzed(0), current(0), start(false) {};
template<unsigned short N>
inline unsigned short series(){
if(!start){
start = true;
vector<bool> tempVector(N, false);
analyzed = tempVector;
(firstN = N);
}
if(analyzed[N] == false){
analyzed[N] = true;
if((this->series<N>() <= firstN)){
cout << (this->series<N>()) << " " << flush;
}
}
if(N%2 == 0)
return(this->series<N - 2>() + ((this->series<N - 1>())));
else return (this->series<N - 1>() + ((this->series<N - 2>())));
}

static void reset(Fibonacci &fib){
fib.start = false;
}
};

template<>
inline unsigned short Fibonacci::series<1>(){
if(analyzed == false){
analyzed = true;
cout << 1 << " " << flush;
}
return 1;
};

template<>
inline unsigned short Fibonacci::series<0>(){
if(analyzed == false){
analyzed = true;
cout << 0 << " " << flush;
}
return 0;
};

#ifdef NUM
#undef NUM
#define NUM VALUE_
#else
#define NUM VALUE_
#endif

int main(int argc, char *argv[]){
Fibonacci fib;
fib.series<NUM>(); //prints out the entire series up to N
Fibonacci::reset(fib);
cout << endl;
fib.series<NUM - 6>();
cin.get();

#undef NUM
#undef VALUE_

return 0;
}``````

I think I finally understand what makes an individual a great programmer.

It's not the degree, and it's not the job...

...it's the discipline that makes an individual a great programmer.

I know of many people at Daniweb that did not go to college and still became great programmers. This is because they had the [u]discipline[/u] to improve their ability and familiarity with their understanding of programming technologies.

I'd like to thank these individuals, and many others who helped me since I came here:

[Note: Individuals with Professor next to their name were a huge influence to my way of thinking.]

Professor Narue (Truly a great, and very inspirational Software Engineer! )
Professor AD [Ancient Dragon] ( An Expert Programmer who knows how to turn complex problems into practical solutions. /salute )
Professor Ezzaral (Another very inspirational person! )
Professor Radical Edward ( Inspirational and absolutely Admirable! You rock!!! Whoo! XD)
Salem (Though strict, very knowledgeable programmer)
~s.o.s~ (Respectable Designer)