//File: Fibonacci.h
#ifndef FIBONACCI_H
#define FIBONACCI_H
class Fibonacci {
friend istream& operator >> (istream&, Fibonacci&);
public:
Fibonacci();
void printFibonacci();
private:
long batas, f1, f2, f3;
bool cek;
};
#endif
//File: Fibonacci.cpp
#include
#include "Fibonacci.h"
Fibonacci::Fibonacci() {
f1 = 0;
f2 = 1;
cek = 1;
}
istream& operator >> (istream& in, Fibonacci& F) {
cout << "Batas maksimal deret: "; in >> F.batas;
return in;
}
void Fibonacci::printFibonacci() {
cout << "Bilangan Fibonacci < " << batas << ":\n0, 1"; while(cek) { f3 = f2 + f1; if (f3 > batas) break;
cout << ", " << f3; f1 = f2; f2 = f3; } } //File: Main.cpp #include #include "Fibonacci.h" void main() { Fibonacci X; cin >> X;
X.printFibonacci();
}
Class dan Implementasi Fibonacci
Subscribe to:
Post Comments
(
Atom
)
0 komentar :
Post a Comment
Silahkan meluangkan waktu anda untuk meninggalkan secuil komentar anda pada Form komentar di bawah ini...