Question: need help writing the constructor that accepts a string input and parses the string for real and imaginary numbers may only use the following headers:

 need help writing the constructor that accepts a string input and

need help writing the constructor that accepts a string input and parses the string for real and imaginary numbers

may only use the following headers: iostream string sstream stdexcept

In this homework, you will need to write a Complex class to represent complex num- bers and overload many operators for the Complex class to behave just like normal arithmetic. You should also make heavy use of constexpr. Everything that can be con- stexpr should be. Firstly, your Complex class should have two floating point (use double!!!) private member variables to store the real and imaginary parts; a single constexpr constructor that, through the use of default arguments, behaves as a default constructor that sets both the real and imaginary parts to 0; when given a single double as a parameter, the real part is set to this value and the imaginary part is set to 0; and when given two double inputs, it sets the real and imaginary parts to these values in respective order; and a constructor that accepts a string input, containing no spaces, for simplicity, that can parse a string containing addition/subtraction of complex numbers such as "T", 2+3.2-4i, 1+2+3-4i-51-6i, etc., and turn it into a complex number. Given an invalid input like the empty string or one that cannot be parsed, it should throw a std::logic_error with message "bad input string: (THE STRING)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!