Return the centered average of an array, which is the mean average of the values, ignoring the largest and smallest. If there are multiple copies of the smallest or largest values, ignore just one. If the array length is less than 3, then return 0. You may use a loop, or the algorithms in the standard library. arrays.cpp

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 23SA
icon
Related questions
Question
Return the centered average of an array, which is the mean average of the values, ignoring the largest
and smallest. If there are multiple copies of the smallest or largest values, ignore just one. If the array
length is less than 3, then return 0.
You may use a loop, or the algorithms in the standard library.
arrays.cpp
1
#include <algorithm>
2
#include <numeric>
using namespace std;
4
double centeredAverage(const double a[], size_t len)
{
8
10
}
Demo.cpp
1
#include <iostream>
2
using namespace std;
3
4
#include "arrays.h"
6.
int main()
{
double al[] = {13.4,6.2,3.2,10.8,13.5,10.7,14.4,14.4,4.0,4.0,13.9,13.6,12.7,6.3,4.7};
print("al->", al, 15);
cout « "centeredAverage: " << centeredAverage(al, 15) « endl;
cout « endl;
7
8
10
11
12
double a2[] = {15.0};
print ("a2->", a2, 1);
cout « "centeredAverage:
cout « endl;
13
14
15
« centeredAverage(a2, 1) <« endl;
16
17
18
double a3[] = {7.1,11.1,5.9,17.1};
print("a3->", aз, 4);
cout « "centeredAverage: " « centeredAverage(a3, 4) « endl;
cout « endl;
19
20
21
22
double a4[] = {12.7};
print ("a4->", a4, 1);
cout « "centeredAverage:
cout « endl;
23
24
25
« centeredAverage (a4, 1) <« endl;
26
27
Transcribed Image Text:Return the centered average of an array, which is the mean average of the values, ignoring the largest and smallest. If there are multiple copies of the smallest or largest values, ignore just one. If the array length is less than 3, then return 0. You may use a loop, or the algorithms in the standard library. arrays.cpp 1 #include <algorithm> 2 #include <numeric> using namespace std; 4 double centeredAverage(const double a[], size_t len) { 8 10 } Demo.cpp 1 #include <iostream> 2 using namespace std; 3 4 #include "arrays.h" 6. int main() { double al[] = {13.4,6.2,3.2,10.8,13.5,10.7,14.4,14.4,4.0,4.0,13.9,13.6,12.7,6.3,4.7}; print("al->", al, 15); cout « "centeredAverage: " << centeredAverage(al, 15) « endl; cout « endl; 7 8 10 11 12 double a2[] = {15.0}; print ("a2->", a2, 1); cout « "centeredAverage: cout « endl; 13 14 15 « centeredAverage(a2, 1) <« endl; 16 17 18 double a3[] = {7.1,11.1,5.9,17.1}; print("a3->", aз, 4); cout « "centeredAverage: " « centeredAverage(a3, 4) « endl; cout « endl; 19 20 21 22 double a4[] = {12.7}; print ("a4->", a4, 1); cout « "centeredAverage: cout « endl; 23 24 25 « centeredAverage (a4, 1) <« endl; 26 27
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage