1. Welcome! Please take a few seconds to create your free account to post threads, make some friends, remove a few ads while surfing and much more. ClutchFans has been bringing fans together to talk Houston Sports since 1996. Join us!

Programming Question

Discussion in 'BBS Hangout' started by Lil Pun, Feb 4, 2004.

  1. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    I'm taking a C++ programming class this semester. Our professor gave us an assignment to be able to enter a number and compute Fibonnacci numbers, you know 1,1,2,3,5,8,13,21,34,55,89,144.....

    We are supposed to make a class, called HugeNumber to do this and my question is am I supposed to take this class and implement it into a C++ program then compile sort of like a Java client or will this HugeNumber class do all the computing within itself and all I would have to do is compile the class, ? Any websites where I can get some examples of classes that I could download and compile or implement to get some practice?
     
  2. RunninRaven

    RunninRaven Member
    Supporting Member

    Joined:
    Jun 16, 2000
    Messages:
    15,280
    Likes Received:
    3,243
    My guess would be that since it is a C++ class, the HugeNumber class should do all the work. But honestly, this sounds like a question that only your professor can answer.
     
  3. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    I already asked him and he tried to explain but he is from a different country and has a very firm accent which makes it difficult to understand him most of the time.
     
  4. super_mario

    super_mario Member

    Joined:
    Apr 22, 2002
    Messages:
    479
    Likes Received:
    1
    My recommendation is:

    1) Understand what this exercise is trying to teach you.
    2) Send your professor an e-mail if you have a hard time understanding him.

    Based on what you wrote, here is my interpretation. I think that you are being asked to calculate the Nth element of a Fibinocci sequence. For example, the second element is 1, the third element is 2, but what is the billionth element?

    In C++, the maximum value of an unsigned long on a 32 bit operating system is 4294967295. So I think that you are being asked to implement a C++ class that you can use to hold integers greater than that of an unsigned long.

    Again, I would ask your professor.

    Good luck!
     
  5. boomboom

    boomboom I GOT '99 PROBLEMS

    Joined:
    Sep 29, 1999
    Messages:
    12,789
    Likes Received:
    9,470
    He's probably trying to get you to implement the function and then call it recursively to do the calculations. I've got a link to a website that has a sample implementation of this. Let me know if you need it...of course it would be for comparison purposes...to see if your working code is similar to someone else's.;)
     
  6. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    Yeah go ahead and give it to me since I already sent it in this morning. Hey super_mario that's what he said he wants but was I supposed to write two programs instead of the one I wrote?
     
  7. super_mario

    super_mario Member

    Joined:
    Apr 22, 2002
    Messages:
    479
    Likes Received:
    1
    I think that it should be one program. Just make sure that it properly handles big numbers. :)
     
  8. boomboom

    boomboom I GOT '99 PROBLEMS

    Joined:
    Sep 29, 1999
    Messages:
    12,789
    Likes Received:
    9,470
    Here it is...

    http://homepages.ius.edu/JDRUIN/html_pages/C++_examples.htm
     
  9. ragingFire

    ragingFire Contributing Member

    Joined:
    Jan 13, 2003
    Messages:
    1,671
    Likes Received:
    0
    You are some confused dude ... mixing C++ with Java, .... 2 programs ....

    I have to read between the line and here is your assignment:

    Write a C++ program with a class called Hugenumber that compute the Fibonnacci numbers. The class takes in 1 argument: the number that you want to compute the F number for. You can feed this number to your class thru command line argument to your main program, which instantiates an object of the Hugenumber class.

    Your prof. probably wants you print the input and the output too.

    You compile a C++ program with a C++ compiler. It produces an executable program that runs stand-alone. It has nothing to do with Java, the Web ...
     
  10. LegendZ3

    LegendZ3 Member

    Joined:
    Nov 6, 2002
    Messages:
    4,196
    Likes Received:
    5
    You should have make an class in the same file that your main function is in, and your main function will call the class, and pass the argument to the constructor of the class. I haven't been use C++ in a while now, but that "HugeNumber" class's main fuction should be little something like this:

    int HugeNumber (int n)
    {
    if (n == 0 || n == 1)
    return n;
    else
    return HugeNumber (n - 1) + HugeNumber (n - 2);
    }
     
  11. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    OK, Legend that is what I was asking, does something extra need to go in the program and what you have told me seems to make sense. I already have my Fibonnaci program written out I just don't think it's what the professor wants at the moment. He wants to print the huge number and he also wants two huge numbers added together and he also wants us to limit the digits to 300. Basically what I have got, so far, is how to calculate Fibonnaci of a integer given by the user and print that out one huge number but within my program I have no calculations yet but that shouldn't be a problem but how do I set a limit of 300?

    Oh ragingfire thanks for your info but I know it has nothing to do with Java but I can handle Java pretty well, this is my first stab at C++ and a TA told me that the two languages were some what similar so I thought a C++ class may be like a Java Client but I guess I was incorrect.
     
  12. SoSoDef76

    SoSoDef76 Member

    Joined:
    Jul 8, 2002
    Messages:
    655
    Likes Received:
    20
    This thread is frying my brain. I graduated from CS in 1998 and I haven't touched a C++ book since. I don't understand anything anyone is saying. :)
     
  13. Woofer

    Woofer Member

    Joined:
    Oct 10, 2000
    Messages:
    3,995
    Likes Received:
    1
    Use your C++ program to call a Lisp interpreter. :)
     
  14. LegendZ3

    LegendZ3 Member

    Joined:
    Nov 6, 2002
    Messages:
    4,196
    Likes Received:
    5
    Limit to 300 is easy, you just have to add another condition in the loop that checks if the number is smaller than 300, like do{blah blah blah}while(n < 300); .
     
  15. LegendZ3

    LegendZ3 Member

    Joined:
    Nov 6, 2002
    Messages:
    4,196
    Likes Received:
    5
    And those are the stuffs they now teach in high school cs class :D
     
  16. RIET

    RIET Member

    Joined:
    May 20, 2002
    Messages:
    4,916
    Likes Received:
    1
    Tell your professor you would like to outsource this problem to India.
     
  17. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    Hey Legend do you think this is good code:
    I don't know but something is telling me I'm not using a class in this function, what do you think?



    #include iostream. h>

    long fibonacci( long );

    int main()
    {
    long result, number;

    cout << "Enter an integer: ";
    cin >> number;
    result = fibonacci( number );
    cout << "Fibonacci(" << number << ") = " << result << endl;
    return 0;
    }


    long fibonacci( long n )
    {
    if ( n == 0 || n == 1 ) // base case
    return n;
    else // recursive case
    return fibonacci( n - 1 ) + fibonacci( n - 2 );
    }
     
  18. LegendZ3

    LegendZ3 Member

    Joined:
    Nov 6, 2002
    Messages:
    4,196
    Likes Received:
    5
    I don't have a c++ compiler, so I can't tell you if it's going to run or not. But first of all, you didn't use a class, you only creat a function, which was not what your professor asked for. And I wouldn't use recursion if you going to pass reference through parameter.
     
  19. Lil Pun

    Lil Pun Member

    Joined:
    Oct 6, 1999
    Messages:
    34,143
    Likes Received:
    1,038
    Well I have one and the program compiles and runs fine I was just asking you to confirm what you did, that I did not use a class.
    How do I eliminate recursion and what exactly do you mean pass reference through a parameter? Damn it I thought I was close! :mad:

    Is there some place like a chat room or messenger service (ie Yahoo!, MSN) I can talk to you on so I don't post any more questions here?
     
    #19 Lil Pun, Feb 4, 2004
    Last edited: Feb 4, 2004
  20. LegendZ3

    LegendZ3 Member

    Joined:
    Nov 6, 2002
    Messages:
    4,196
    Likes Received:
    5
    Well, if it runs fine and have no logical error, then I guess you just have to have a class, and to tell you the truth, I pretty much forgot how to use class in C++, so I went back to the book from CS1, and I think you have do this:

    class HugeNumber
    {
    private:
    long n;
    public:
    long fibonacci();
    };

    int main()
    {
    long result, number;
    HugeNumber fibo;

    cout << "Enter an integer: ";
    cin >> number;
    result = fibo.fibonacci( number );
    cout << "Fibonacci(" << number << ") = " << result << endl;
    return 0;
    }

    long HugeNumber::fibonacci( long n )
    {
    if ( n == 0 || n == 1 ) // base case
    return n;
    else // recursive case
    return fibonacci( n - 1 ) + fibonacci( n - 2 );
    }
     

Share This Page