Given that a class complex exists, properly^2 declare an array to hold as many a
ID: 3815541 • Letter: G
Question
Given that a class complex exists, properly^2 declare an array to hold as many as 50 complex objects. Now we'll assume your program has already read in a certain number of Complex values into this array. Further, we'll assume that you need to take their average. BTW, it may help if you also knew that that this class has a method to add two Complex objects. Its cal signature is: Complex Complex::add const Complex & b) const; It also has a method to divide a complex object by a floating-point value. Its call signature is: Complex Complex::divide (double n) const; Show your code to average all the elements in your array of values.Explanation / Answer
//Given that a class Complex exists, properly declare an array to hold as many as 50 Complex objects.
Complex numbers[50];
//Given: Complex Complex::add(const Complex &b) const;
// Complex Complex::divide(double n) const;
//Now we'll assume your program has already read in certain number of Complex values into
//this array. Further we'll assume that you need to take their average.
//Show your code to average all elements in your array of values.
Complex avg;
for(int i = 0; i < n; i++) //Assuming there are n Complex numbers in the array.
result = result.add(numbers[i]);
result = result.divide(n);
//Now result is the average of n Complex numbers.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.