Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,664 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,164 people online right now. Registration is fast and FREE... Join Now!




Fibonacci

 
Reply to this topicStart new topic

Fibonacci

MWilson
post 16 Jul, 2007 - 08:24 AM
Post #1


New D.I.C Head

*
Joined: 23 Feb, 2007
Posts: 10


My Contributions


Hello,
I was looking for some help on an assignment. I am taking a course in Data Sructures with C++ using STL
The assignment states:
Write a header file that contains a recursive method Fib with one parameter of type long and returns the Fibonacci value. remember to use long as a data type for the returned Fibonacci result by the the method fib because the number could be very large.
Write a c++ file that reads in a long number and returns the corresponding Fibonacci number. Remember to limit the number you read in to a value between 0 and 40.
I understand the formula on paper but using the header file in conjunction with the .cpp file and its implementation is confusing me. Please Help. Here is what I have so far.

CODE
//July 16,2007
//Assignment 3
//File Name: fibonacci.h

#include <iostream>

using namespace std;

class fib
{
public:
    fib(long n = 0);
};
fib::fib(long n)
    {
        if (n < 0)
            cout<<"Number must be in the range 0-40\n";
        
    }
//July 16,2007
//Assignment 3
//File Name: fibonacci.cpp

#include <iostream>
#include "fibonacci.h"

using namespace std;

int main()
{
    fib n;

    cout<<"Enter a number between 0 and 40\n";
        /*cin>>n;*/
    cout<<"Fibonacci Number is: \n";
    cin.get();
        
        return 0;
}
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 16 Jul, 2007 - 09:07 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,178



Thanked 33 times

Dream Kudos: 25
My Contributions


The site has several implementations of Fibonacci.

http://www.dreamincode.net/code/snippet80.htm
User is online!Profile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 05:47AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month