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

How are portions of a program disabled in demo versions?
By inserting comments in the program Single line comment denoted by // Multi line comment denoted by /* */
Akhilesh
0 0
5
hi sir c progarm codeing how to write sir........
take any C book then u can learn more...
Suryateja
In which program we use character constants?
For the name of months, animal, colors we do use it.
Mona
Can I learn C and C++ by watching videos? If it is possible, what is the best channel?
Yes!! you can learn.but the concept won't be clear up the mark,since there is no one to guide while you are doing some programs.you might have observed these things.There are no such online tutorial that...
Mohammad
0 0
5
I’ve been learning C language for 3 weeks but it’s becoming more difficult. As a result, I’m becoming lazy. What should I do to motivate myself?
Learn algorithm or flowchart first. Once you start C, try to relate with real time example. Example: When learn printf() , think about a a bill where you customer information is printed. Similarly when...
Akhilesh
0 0
5

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

Ask a Question

Related Lessons

Java and C trainer
Always think any conspect with real-time example like Object -- object must have states and behaviour then only we will call that thing is Object like fan is Object (rotating,color)

Find out the Output of the following with reason and get C Language Training fess less by 10%
1. void main() { clrscr(); printf(5+"Beautifull"); getch(); } 2. void main() { int a=50; clrscr(); ...

4 Things Every Tech Startup Needs to Know About The Coaching Industry
Knowledge on any subject is widely available to those who wish to learn. However, just gathering knowledge from other people doesn’t guarantee results in business. Results come from applying what...


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 >

Applications engineering is a hot trend in the current IT market.  An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...

Read full article >

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

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