Question: a) Given that a class Complex exists, properly declare an array to hold as many as 50 Complex objects. b) Given your array declared above,
a) Given that a class Complex exists, properly declare an array to hold as many as 50 Complex objects.
b) Given your array declared above, and assuming your program has already read in a certain number of Complex values into that array, we'd like to take the average of these Complex values.
It may help if you also knew that the Complex class has this method for adding two Complex objects:
Complex Complex::add(const Complex & b) const; and a method to divide a Complex object by a floating-point value:
Complex Complex::divide(double n) const; Now, show your code to average all the elements in your array of Complex numbers. (Hint: What is the data type of the average of two or more Complex numbers?)
c) Show the code for an addition method of a Complex class. (You, of course, recall that a complex number has both a real and an imaginary part.) (Reminder: Adding two values does not change either of the values, but rather creates a third value which is the originals' sum.) (Thought-provoker: Some programmers might find it useful if Complex addition were compatible with the built-in types -- double, for instance.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
