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

Do every operator has an Associativity?
Yes, every operator will have an associativity.
Basundhara
0 0
5

What is void main () into main and what it does?

Void main () is the entry point for execution in C program. The void is a keyword that represents function will not return anything but a void value. Main is the name of the function and () represents...
Noreen
how to calculate address of n dimensional matrix
An n dimensional matrix can be of any dimension. Adding a dimension is adding one more index number (to access the element). In 1-D array you the elements are linearly arranged and can be addressed as...
Rupendra

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

Ask a Question

Related Lessons

What is a Programming Language
What is a Language? Language is a communication system of human. What is a programming Language? A programming Language is a formal constructed language design to communicate...

C Program-Error Handling
//Header files #include<stdio.h>#include<conio.h>#include<stdlib.h> //Main function void main(){ int dividend=10; int divisor=0; int quotient; //Function for clearing screen clrscr(); ...

C PROGRAM FOR GENERATING SOUND
#include<stdio.h> #include<conio.h> #include<dos.h> void main() { sound(3000); // sound function have single parameter , this parameter we put integer value its generating...

V. Muthu Ganeshan

0 0
0

Functions In C Programming
A C-language program is nothing but collection of Function, these are the building blocks of a ‘C’ program. Generally, a function mans a task. “Function is a...

Program to swap the value of two variables without using third variable(simplest way)...
int main() { int a=10,b=20; printf("values of a before swap ="%d,a); printf("values of b before swap ="%d,b); a=a+b; b=a-b; a=a-b; printf("******************"); printf("values of a after swap...

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