0% found this document useful (0 votes)
3 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)
3 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
You are on page 1/ 2

#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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy