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 are the control statements in C language?
Control statements in C are constructs that allow the program to make decisions and control the flow of execution based on certain conditions. The primary control statements in C include if-else statements,...
Jitender
0 0
6
What is C language used for?
C language is a versatile programming language commonly used for system programming, developing operating systems, embedded systems, and creating various applications ranging from game development to scientific...
Anil
0 0
5

Program to accept a list of elements and find the maximum number in the list. 

 

The logic will be 1. Create an array of the desired type 2. Sort the array in the descending order 3. Fetch the first elemnet from the array, this will be the maximum element in that array. Now use...
Lavanya
0 0
8
What are security issues in the C language?
The C programming language is susceptible to various security issues due to its low-level nature and lack of built-in safety features. One significant concern is buffer overflow, where writing more data...
Avinesh
0 0
7

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

Ask a Question

Related Lessons

Can we store different data types in a stack?
Yesterday, one of my Facebook friend asked me this question. My answer is "yes", and in this post I will discuss how could we do this.I am a great supporter of working with unions and I will be using union...

C Program-Upper Case Demo
/*WAP to print the character entered by user in upper case*/ //Header files #include<stdio.h>#include<conio.h> //Main function void main(){ char ch; //Function for clearing screen clrscr(); ...
S

Some Tricky Questions in C
Can you write two functions in which one executes before main function and other executes after the main function? #pragma startup #pragma exit Where, priority is optional integer value.For user priority...

C and C++ programming with memory level debugging
Understanding C and C++ programming by using memory level debugging. Step 1: Understand the Memory map of C executable Step 2: Start memory level debugging using popular IDE Step 3: Find the memory...

Compiler vs Interpreter
Compiler Interpreter Convert all the code into binary format and execute. Convert one statement at a time and execute, then Convert next statement and execute. After conversion, source...

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