Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 21-12-2007, 01:57 PM   #1 (permalink)
mortal kombat
 
quan chi's Avatar
 
Join Date: Jul 2006
Posts: 1,673
Default urgent help required.please solve this program.


using constructor write a program in c++ to generate first n terms of fibonacci series.

(you can take n=5)

how to do it using constructor.
please help.
quan chi is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 21-12-2007, 02:27 PM   #2 (permalink)
Wahahaha~!
 
Faun's Avatar
 
Join Date: Dec 2006
Location: Pune/there
Posts: 7,675
Default Re: urgent help required.please solve this program.

lol..its easy man

just write the whole code in the constructor passing n as an argument.

try it now, probably someone will come up with complete code.
__________________
Blog | Flickr | Battlelog
Spoiler:
Asus Z68 V-Pro|i5 2500k|TRUE Black|Ripjaws X|U2311H|N560GTX|D7000|XONAR STX|RE272|RE0|CC51|XE200PRO Walnut| TD II V2| Ultraphile|N5800

Mono
Faun is online now  
Old 27-12-2007, 08:08 PM   #3 (permalink)
Mad and Furious
 
redhat's Avatar
 
Join Date: May 2006
Location: Visual Basic 6.0
Posts: 453
Smile Re: urgent help required.please solve this program.

Suppose this is some sort of "SCHOOL" Homework!!!
Jus create a parameterized Constructor n accept the value of 'n' within it
Simple!!!!!
redhat is offline  
Old 30-12-2007, 04:01 AM   #4 (permalink)
In The Zone
 
Join Date: Oct 2004
Location: Visnagar
Posts: 227
Default Re: urgent help required.please solve this program.

search on google u can do it

and here no one is free to do ur homework

so have some tricky questions
__________________
EVERY QUESTION HAVE PERFACT ANSWER

AND NOTHING IS IMPOSSIBLE
vinaypatel is offline  
Old 30-12-2007, 08:44 AM   #5 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: urgent help required.please solve this program.

I've not compiled this code and even not programmed C++ for a long time.
Please check this.
The program will be something like -
Code:
 include <iostream>

class factorial
{
    long int fact=1;
    
    factorial (int no)    // This is a constructor with 1 argument
    {
        int store=no;
        for ( ; no <1 ; --no)
            fact*=no;
        cout << "Factorial of " << store << "is " << fact;
    }
}

int main()
{
    int no;
    
    factorial f1(3);    // Direct call
    // User choice
    cout << "Enter a number : ";
      cin >> no;
     
    factorial f(no);
    
    return 0;
}
Sorry, if there are mistakes.
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 30-12-2007, 11:45 AM   #6 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: urgent help required.please solve this program.

As others said, use a default constructor and a parameterized constructor to call some function which outputs the needed.

Code:
#include<iostream>

using namespace std;

class A
{
    int n;

    public:
        void call(int n)
        {
            cout<<"\nFibonacci numbers upto "<<n<<" are: \n";
            int a(1),b(1),t(0);
            for(int i=0;i<n;i++)
            {
                cout<<a<<" ";
                t=b;
                b=a+b;
                a=t;
            }
            cout<<endl;
        }
        
        A()
        {
            cout<<"\nEnter the number of Fibonacci numbers you wish to calculate: ";
            cin>>n;
            call(n);
        }
        
        A(int n)
        {
            call(n);
        }
};

int main()
{
    A *a;
    cout<<"\nDefault constructor call (Asks for user input):\n";
    a =  new A;
    cout<<"\nParameterized constructor call (Assumes input as value passed):\n";
    a = new A(10);
    return 0;
}
Outputs as:
Code:
Default constructor call (Asks for user input):

Enter the number of Fibonacci numbers you wish to calculate: 6

Fibonacci numbers upto 6 are: 
1 1 2 3 5 8 

Parameterized constructor call (Assumes input as value passed):

Fibonacci numbers upto 10 are: 
1 1 2 3 5 8 13 21 34 55
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
(Urgent!!) Need A Software Or Program For Ma' Office!!! harry_nitish Software Q&A 3 17-07-2007 06:05 PM
Urgent Help Needed 2 Solve Win Xp Problem SLIPKNOT Software Q&A 7 17-11-2006 12:22 PM
solve the problem ofasus mother board (URGENTLY REQUIRED) Tuku Hardware Q&A 3 17-09-2006 10:10 PM
Urgent Help required!!! sourabh_nandi QnA (read only) 3 22-07-2005 11:39 PM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:46 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2