0% found this document useful (0 votes)
22 views2 pages

#Include Iostream

The document contains a C++ program that includes four classes: Fibonacci, Table, EvenNumbers, and SumNatural, each providing different functionalities. The program generates a Fibonacci series, displays a multiplication table in descending order, lists even numbers within a specified range, and calculates the sum of the first N natural numbers. The main function orchestrates user input and calls the respective methods from these classes to display the results.

Uploaded by

rkanwal5598
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

#Include Iostream

The document contains a C++ program that includes four classes: Fibonacci, Table, EvenNumbers, and SumNatural, each providing different functionalities. The program generates a Fibonacci series, displays a multiplication table in descending order, lists even numbers within a specified range, and calculates the sum of the first N natural numbers. The main function orchestrates user input and calls the respective methods from these classes to display the results.

Uploaded by

rkanwal5598
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <iostream>

using namespace std;

// (a) Fibonacci Series


class Fibonacci {
public:
void generateSeries(int limit) {
int first = 1, second = 1, next;
cout << first << " " << second << " ";
for (int i = 3; i <= limit; i++) {
next = first + second;
cout << next << " ";
first = second;
second = next;
}
cout << endl;
}
};

// (b) Table in Descending Order


class Table {
public:
void displayTable(int num) {
for (int i = 10; i >= 1; i--) {
cout << num << " x " << i << " = " << num * i << endl;
}
}
};

// (c) Even Numbers in a Range


class EvenNumbers {
public:
void displayEven(int start, int end) {
for (int i = start; i <= end; i++) {
if (i % 2 == 0) {
cout << i << " ";
}
}
cout << endl;
}
};

// (d) Sum of First N Natural Numbers


class SumNatural {
public:
int findSum(int N) {
int sum = 0;
for (int i = 1; i <= N; i++) {
sum += i;
}
return sum;
}
};

int main() {
Fibonacci fib;
Table tbl;
EvenNumbers even;
SumNatural sumNat;
// Fibonacci Series
cout << "Fibonacci Series:" << endl;
fib.generateSeries(20);

// Table in Descending Order


int num;
cout << "\nEnter a number for table: ";
cin >> num;
tbl.displayTable(num);

// Even Numbers in a Range


int start, end;
cout << "\nEnter start number: ";
cin >> start;
cout << "Enter end number: ";
cin >> end;
cout << "Even numbers between " << start << " and " << end << " are: ";
even.displayEven(start, end);

// Sum of First N Natural Numbers


int N;
cout << "\nEnter N for sum of first N natural numbers: ";
cin >> N;
cout << "Sum of first " << N << " natural numbers is: " << sumNat.findSum(N) <<
endl;

return 0;
}

You might also like