UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I write a C++ program for generating Fibonacci numbers using constructor?

Asked by Last Modified  

Follow 1
Answer

Please enter your answer

Tutor

#include"iostream.h" #include"conio.h" #include"stdio.h" class fibo { private: int t1; int t2; int t3; public: fibo(); fibo(int n); }; fibo :: fibo(int n) { int term; t1=1; t2=1; term=n; cout=0;term--) { t3=t1+t2; cout> n; fibo F1(n); getch(); }
read more
#include"iostream.h" #include"conio.h" #include"stdio.h" class fibo { private: int t1; int t2; int t3; public: fibo(); fibo(int n); }; fibo :: fibo(int n) { int term; t1=1; t2=1; term=n; cout<< t1<< " "<< t2; term-=2; for(;term>=0;term--) { t3=t1+t2; cout<< " "<< t3; t1 = t2; t2 = t3; } } void main() { clrscr(); int n; cout<< "Enter the number of terms: "; cin>> n; fibo F1(n); getch(); } read less
Comments

Tutor

#include class fibonacci { private: unsigned long int f0,f1,fib, public: fibonacci() { f0=0; f1=1; fib=f0+f1; } fibonacci (fibonacci &ptr) { f0=ptr.f0; f1=ptr.f1; fib=ptr.fib; } void increment() { f0=f1; f1=fib; fib=f0+f1; } void display() { cout << fib << 't\'; } }; //end...
read more
#include class fibonacci { private: unsigned long int f0,f1,fib, public: fibonacci() { f0=0; f1=1; fib=f0+f1; } fibonacci (fibonacci &ptr) { f0=ptr.f0; f1=ptr.f1; fib=ptr.fib; } void increment() { f0=f1; f1=fib; fib=f0+f1; } void display() { cout << fib << 't\'; } }; //end of class construction void main (void) { fibonacci number; for (int i=0; i<=15;i++) { number.display(); number.increment(); } } read less
Comments

Advance Excel And VBA Training

Constructor: A constructor is a special member function used in a class in order to Initialize the objects of a class. The name of the constructor should be same as that of the class name. Constructors does not have any return type not even void In Object oriented programming we have 3 types...
read more
Constructor: A constructor is a special member function used in a class in order to Initialize the objects of a class. The name of the constructor should be same as that of the class name. Constructors does not have any return type not even void In Object oriented programming we have 3 types of constructors they are: 1. default constructor: The constructor which does not have any arguments are known as default constructors. Syntax: Class_name() { --------------//arguments } 2. parameterized constructor: The constructors which passes arguments is known as a parameterized constructor. Syntax: Class_name(parameters) { -------------------//arguments } 3. copy constructor: The constructor which creates an object by initializing it with an object of the same class which was created prior is known as a copy constructor. Now let us see a program to generate a Fibonacci serious using constructor to in Action l an object. #include "iostream" using namespace std; class fib //class declaration { int n; public: //access specifier fib() //default constructor { cout<<"enter the number until which you want the fibonacci series to come"<>n; } int fib_op(int x) // function declaration and definition { if(x==0) return 0; else if(x==1) return 1; else return(fib_op(x-1)+fib_op(x-2)); } void display() //function to display the output { for(int i=0;i<=n;i++) { cout<read less
Comments

View 1 more Answers

Related Questions

What is the most efficient way to store flag values?
A flag is a value used to make a decision between two or more options in the execution of a program. Efficiency in this case is a tradeoff between size and speed. The most memory-space efficient way to...
Deepak
0 0
6
What is the best website to learn c language?
In case of problems you will face while making programs, you may take help of google. There may be the situation when you need a helping hand to make clear the basic concepts of programming and internal...
Nom
In which program we use character constants?
For the name of months, animal, colors we do use it.
Mona
What is the best IDE for C and C++ development?
If you're a student then Turbo C++ is best for C and C++ program + inbuilt C/C++ Graphics Function If you're a professional or working then Netbeans for C/C++ or Code:: Blocks is Best.
Balakrishnasingh

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

C Program-The Odd Loop Demo
/* WAP to print square value of the number entered by user using odd loop*/ //Header Files #include<stdio.h>#include<conio.h> //Main Function void main(){ char another='y'; int num,sq; //...
S

Memory Layout of C Programs
A typical memory representation of C program consists of following sections. Text Segment: A text segment, also known as a code segment or simply as text, is one of the sections of a program in an object...

Static and dynamic libraries
A library is a package of code that is meant to be reused by many programs. A static library (also known as an archive) consists of routines that are compiled and linked directly into your program. When...

Introduction to Programming Languages
What is a Programming Language? A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages...

Variables
Variables in C Language:A variable is a name that may be used to store a data value. Unlike constant, variables are changeable, we can change value of a variable during execution of a program. A programmer...

Recommended Articles

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today.  In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more