Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Mandelbrot Iterations (c++) Classes The ability to define classes is an essential part of Object Oriented Programming. In C++, a class definition includes both data

Mandelbrot Iterations (c++)

Classes

The ability to define classes is an essential part of Object Oriented Programming. In C++, a class definition includes both data and methods to operate on that data. Some of the methods in C++ may be specified as overloaded operators. This is particularly convenient when the class represents a mathematical object such as a complex number, a point in 3 space, or a matrix. There are two problems in this homework.

Related C++ HackerRank Problems

Classes -> Structs

Classes -> Class

Classes -> Classes and Objects

The Mandelbrot Set (https://en.wikipedia.org/wiki/Mandelbrot_set)

The Mandelbrot set is a fractal defined as the set of points on the complex plane such that a particular iterated function on them does not "diverge". For a given complex number c, the iterated function is as follows:

f_0(c) = (0 + 0i)

f_n(c) = f_{n-1}(c)^2 + c

where the squaring in step 2 is done by complex number multiplication. It is known that if at any point during the iteration |f_n(c)|becomes greater than 2, that the function will eventually diverge. Thus, a common visualization technique is to iterate until |f_n(c)| is greater than two, up to some maximum number of iterations, say 255. Pseudocode for this is given below:

 int mandelbrotIteration(Complex c, maxIterations) { Complex z = 0 + 0i; for i=0 to maxIerations z = z*z + c; if |z| > 2 return i; return maxIterations; } 

Problem 4a : Mandelbrot Iterations

Write a class called Complex that encapsulates a complex number with the following functionality:

It should have two double variables for the real and imaginary coefficients of the number.

Make a constructor that takes two double values for the real and imaginary coefficients of the number.

Make a length method that returns the distance of the number from the origin (length(a+bi) = sqrt(aa + bb))

Overload the +, =, and * operators for your class to operate properly on complex numbers.

Overload the >> operator so you can print out complex numbers.

Write a program that will take the real and imaginary coefficients of a complex number, store them using your Complex number class, and then perform the Mandelbrot iteration on it.

The program should terminate the iterations when the length of the z is greater than 2, or when 255 iterations are completed.

When the program stops iterating, it should print how many iterations were performed along with the value of the iterate (z in the pseudocode above). For your output of the final z value, print 4 digits after the decimal point. Hint: use the following to print 4 digits after the decimal point (or use printf).

cout << setprecision(4) << fixed; 

Sample program run

 Enter the coefficients of a complex number: 0 1.5 Num iterations: 2 Final value: (-2.2500 + 1.500i) 

Things to remember:

For this assignment, it is not sufficient to get the right output. You must define a Complex class and use it to do the calculations.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago