Continued Fraction C++ program

En curso Publicado hace 5 años Pagado a la entrega
En curso Pagado a la entrega

i wanna a program that execute a regular continued fraction for any real valued number x is defined by the formula above and can be written in a short form with squared brackets x=[f0;f1,f2,f3,…].

Task is to represent this short form for continued fractions inside a computer by lists of integer numbers, to input, calculate and also delete them; no global variables shall be defined and used.

the code must be as the following steps :-

1- Define a structure for above list elements to implement continued fraction by lists with these elements.

2- Define a function with a continued fraction cf=[f0;f1,f2,f3,…,fk] as pointer/list as first and a natural/integer number fk+1 as second parameter extending the continuous fraction to cf=[f0;f1,f2,f3,…,fk,fk+1], i.e. appending a further element with value fk+1 at the end of the list. Return the extended continued fraction/the resulting list as function value.

3- Define a function with a continued fraction as pointer parameter deleting the complete list, freeing the memory of all list elements on the heap. Output like in the examples below all deleted values fk to check your function.

4-Define a function with a continued fraction as pointer parameter returning its value as a double coded floating point value.

Hint: a recursive solution is especially appropriate and short in this case.

5 - Write a function without parameter, first reading f0∈Z, then in a loop the values fk∈N, k=1,2,…, successively constructing the continued fraction as list and return it.

6 - Write a main function and define three pointer variables for continued fractions. Initialise the first above example cf1=123100=[1;4,2,1,7] and the second cf2=1710=[1;1,2,3] by appropriate nested functions calls directly in code. Input the third continued fraction cf3 by giving a function call to above defined function (task 5).

For all three continued fractions output its floating point values calculated by respectively given function calls (task 4) with at least 15 digits after the decimal point and then delete the memory in heap for the continued fractions/lists also by appropriate function calls (task 3; see also examples below).

Test your program at least for inputs 1=[1], 2=[1;1], 0.5=[0;2], 2–√≈[1;2,2,2,2,…] and π≈[3;7,15,1,292,1,1,1,2,1,3,1,…], find further examples here.

ps: Only use C++ input and output, no calls of scanf or printf function or malloc, calloc, ... or free!

don't include any libraries more than <iostream> .

Programación en C Programación en C++

Nº del proyecto: #18174580

Sobre el proyecto

2 propuestas Proyecto remoto Activo hace 5 años

2 freelancers están ofertando un promedio de €34 por este trabajo

yuwy

I'm good in math, will do it in 1 day ************************************ ************************************

€29 EUR en 1 día
(0 comentarios)
0.0