File: main.cc

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (40 lines) | stat: -rw-r--r-- 890 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>

using namespace std;

class Fibo
{
    size_t d_return = 0;
    size_t d_next = 1;

    public:
        size_t next();
};

size_t Fibo::next()
{
    size_t ret = d_return;      // the next fibonacci number

    d_return = d_next;          // at the next call: return d_next;
    d_next += ret;              // prepare d_next as the sum of the
                                // original d_return and d_next
    return ret;
}

int main(int argc, char **argv)
{
    Fibo fibo;                  // create a Fibo object

    size_t sum = 0;

                                // use its 'next' member to obtain
    for (                       // the sequence of fibonacci numbers
        size_t begin = 0, end = argc == 1 ? 10 : stoul(argv[1]);
            begin != end;
                ++begin
    )
        sum += fibo.next();

    cout << sum << '\n';
}