OOPS Write a program to demonstrate function definition outside class and accessing class members in function definition. - BSC IT PRACTICALS

Thursday, January 18, 2018

OOPS Write a program to demonstrate function definition outside class and accessing class members in function definition.


CODE:

#include<iostream.h>
#include<conio.h>

class fibo
{
public:
void fibonacci();
};

void fibo::fibonacci()
{
   int t1 = 0, t2 = 1, nextTerm = 0, n;

    cout << "\nEnter a positive number to calculate \nthe Fibonacci series upto entered number: ";
    cin >> n;
    cout << "\nFibonacci Series: " << t1 << ", " << t2 << ", ";

    nextTerm = t1 + t2;

    while(nextTerm <= n)
    {
        cout << nextTerm << ", ";
        t1 = t2;
        t2 = nextTerm;
        nextTerm = t1 + t2;
    }
}

void main()
{
clrscr();
fibo ob;
ob.fibonacci();
getch();

}

3 comments:

  1. This is good article. You can read more interesting top C Programming Practicals here.

    ReplyDelete
  2. The site contains few practicals want more on bscit see hereBscIt Notes and study material.

    ReplyDelete
  3. Thank you so much for sharing all practical information It really help to understand c++ in better way and also completing my practical keep it a bro you doing wonderful job... thank you so much

    ReplyDelete