The basics of programming in c++ for beginners

A task: Loop “Geometric progression”

Classes C ++ can be created to describe the most unexpected entity of the real world. Create a class "geometric progression", objects which:

    • would display a geometric progression with a predetermined initial term and the denominator;
    • indexing allowed to obtain values ​​progression member with any serial number;
    • allowed to receive the amount of the initial progression of N-members;

recharge Klass, perhaps, other useful properties.

Decision:

One could, of course, to store the desired number of initial terms of the series as a class exponentially. But this and). extremely wasteful and b). when such representation is not clear, a number of terms stored? The indicated solution is compact and efficient:

A feature of the solution is, that when the indexing operation (progression extraction member) It is a fast recursive (Hoare's algorithm) exponentiation denominator.

Command line options can override the test length of the array, which correspond with the progression of the members:

One thought on “A task: Loop “Geometric progression”

Leave a Reply

Your email address will not be published. Required fields are marked *