Write 3 functions: Write int readNumbersIntoArray(int numbers[], int size); // Reads up to size numbers or a non-numeric and puts them in the array. // Returns how many numbers read. Write int minOrMax(int numbers[], int size, bool Max); // Returns the minimum or the maximum value in the array depending on "Max". // If "Max" is true, then it returns the maximum. // If "Max" is false, then it returns the minimum. Write double trimmedAvg(int numbers[], int size); // Returns the trimmed average of the array. // A trimmed average is a normal average but leaves out the first instance of // the smallest and largest value in the array when doing the calculation. // HINT: use calls to minOrMax() to get the largest and smallest number. Write int main(): // Prompt the user for between 3 and 20 numbers and use readNumbersIntoArray() to // read them into an array. Print an error message and exit if less than three numbers. // Print out the min, max, and trimmedAverage of the array using calls to minOrMax() and // trimmedAvg(). User input is shown in bold below: // Sample run 1: Enter from 3 to 20 numbers followed by a non-numeric: 1 2 q Must be between 3 and 20 numbers! // Sample run 2: Enter from 3 to 20 numbers followed by a non-numeric: -8 2 3 -2 57 q Minimum value in the array: -8 Maximum value in the array: 57 Trimmed average of the array: 1 // Sample run 3: Enter from 3 to 20 numbers followed by a non-numeric: 3, -22, 5, 68, 21, -6, 2 q Minimum value in the array: -22 Maximum value in the array: 68 Trimmed average of the array: 5 Write program C++ program with comments. Here is code #include #include using namespace std; // Function to read numbers from user input and store them in an array int readNumbersIntoArray(int numbers[], int size) { int num; int count = 0; cout << "Enter from 3 to 20 numbers followed by a non-numeric: " << endl; while (cin >> num) { if (count == size) { break; } numbers[count++] = num; } // Clear the error flag in case of non-numeric input cin.clear(); cin.ignore(numeric_limits::max(), '\n'); return count; } // Function to find the minimum or maximum value in the array int minOrMax(int numbers[], int size, bool Max) { int result = numbers[0]; for (int i = 1; i < size; i++) { if (Max && numbers[i] > result) { result = numbers[i]; } if (!Max && numbers[i] < result) { result = numbers[i]; } } return result; } // Function to calculate the trimmed average of the array double trimmedAvg(int numbers[], int size) { int minVal = minOrMax(numbers, size, false); // Get the minimum value int maxVal = minOrMax(numbers, size, true); // Get the maximum value double sum = 0; int count = 0; for (int i = 0; i < size; i++) { if (numbers[i] != minVal && numbers[i] != maxVal) { sum += numbers[i]; count++; } } return sum / count; } int main() { const int maxSize = 20; const int minSize = 3; int numbers[maxSize]; int numCount = readNumbersIntoArray(numbers, maxSize); if (numCount < minSize) { cout << "Must be between 3 and 20 numbers!" << endl; return 1; } int minVal = minOrMax(numbers, numCount, false); int maxVal = minOrMax(numbers, numCount, true); double trimmedAverage = trimmedAvg(numbers, numCount); cout << "Minimum value in the array: " << minVal << endl; cout << "Maximum value in the array: " << maxVal << endl; cout << "Trimmed average of the array: " << trimmedAverage << endl; return 0; } Some of error I am getting and attaching picture of it and bottom I paste error 3 message. Could you please fix it? Source.cpp: In function ‘bool testPassed(std::ofstream&)’: Source.cpp:83:39: error: cannot convert ‘double*’ to ‘int*’ 83 | double studentResultMax = minOrMax(a,L,true); | ^ | | | double* Source.cpp:33:18: note: initializing argument 1 of ‘int minOrMax(int*, int, bool)’ 33 | int minOrMax(int numbers[], int size, bool Max) { | ~~~~^~~~~~~~~ Source.cpp:84:39: error: cannot convert ‘double*’ to ‘int*’ 84 | double studentResultMin = minOrMax(a,L,false); | ^ | | | double* Source.cpp:33:18: note: initializing argument 1 of ‘int minOrMax(int*, int, bool)’ 33 | int minOrMax(int numbers[], int size, bool Max) { | ~~~~^~~~~~~~~ Source.cpp:81:17: warning: unused variable ‘EPS’ [-Wunused-variable] 81 | const double EPS=0.001; | ^~~
Write 3 functions:
Write
int readNumbersIntoArray(int numbers[], int size);
// Reads up to size numbers or a non-numeric and puts them in the array.
// Returns how many numbers read.
Write
int minOrMax(int numbers[], int size, bool Max);
// Returns the minimum or the maximum value in the array depending on "Max".
// If "Max" is true, then it returns the maximum.
// If "Max" is false, then it returns the minimum.
Write
double trimmedAvg(int numbers[], int size);
// Returns the trimmed average of the array.
// A trimmed average is a normal average but leaves out the first instance of // the smallest and largest value in the array when doing the calculation.
// HINT: use calls to minOrMax() to get the largest and smallest number.
Write
int main():
// Prompt the user for between 3 and 20 numbers and use readNumbersIntoArray() to
// read them into an array. Print an error message and exit if less than three numbers.
// Print out the min, max, and trimmedAverage of the array using calls to minOrMax() and
// trimmedAvg().
User input is shown in bold below:
// Sample run 1: Enter from 3 to 20 numbers followed by a non-numeric:
1 2 q
Must be between 3 and 20 numbers! // Sample run 2:
Enter from 3 to 20 numbers followed by a non-numeric:
-8 2 3 -2 57 q
Minimum value in the array: -8
Maximum value in the array: 57
Trimmed average of the array: 1
// Sample run 3:
Enter from 3 to 20 numbers followed by a non-numeric:
3, -22, 5, 68, 21, -6, 2 q
Minimum value in the array: -22
Maximum value in the array: 68
Trimmed average of the array: 5
Write program C++ program with comments.
Here is code
#include <iostream>
#include <limits>
using namespace std;
// Function to read numbers from user input and store them in an array
int readNumbersIntoArray(int numbers[], int size) {
int num;
int count = 0;
cout << "Enter from 3 to 20 numbers followed by a non-numeric: " << endl;
while (cin >> num) {
if (count == size) {
break;
}
numbers[count++] = num;
}
// Clear the error flag in case of non-numeric input
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
return count;
}
// Function to find the minimum or maximum value in the array
int minOrMax(int numbers[], int size, bool Max) {
int result = numbers[0];
for (int i = 1; i < size; i++) {
if (Max && numbers[i] > result) {
result = numbers[i];
}
if (!Max && numbers[i] < result) {
result = numbers[i];
}
}
return result;
}
// Function to calculate the trimmed average of the array
double trimmedAvg(int numbers[], int size) {
int minVal = minOrMax(numbers, size, false); // Get the minimum value
int maxVal = minOrMax(numbers, size, true); // Get the maximum value
double sum = 0;
int count = 0;
for (int i = 0; i < size; i++) {
if (numbers[i] != minVal && numbers[i] != maxVal) {
sum += numbers[i];
count++;
}
}
return sum / count;
}
int main() {
const int maxSize = 20;
const int minSize = 3;
int numbers[maxSize];
int numCount = readNumbersIntoArray(numbers, maxSize);
if (numCount < minSize) {
cout << "Must be between 3 and 20 numbers!" << endl;
return 1;
}
int minVal = minOrMax(numbers, numCount, false);
int maxVal = minOrMax(numbers, numCount, true);
double trimmedAverage = trimmedAvg(numbers, numCount);
cout << "Minimum value in the array: " << minVal << endl;
cout << "Maximum value in the array: " << maxVal << endl;
cout << "Trimmed average of the array: " << trimmedAverage << endl;
return 0;
}
Some of error I am getting and attaching picture of it and bottom I paste error 3 message. Could you please fix it?
Source.cpp: In function ‘bool testPassed(std::ofstream&)’:
Source.cpp:83:39: error: cannot convert ‘double*’ to ‘int*’
83 | double studentResultMax = minOrMax(a,L,true);
| ^
| |
| double*
Source.cpp:33:18: note: initializing argument 1 of ‘int minOrMax(int*, int, bool)’
33 | int minOrMax(int numbers[], int size, bool Max) {
| ~~~~^~~~~~~~~
Source.cpp:84:39: error: cannot convert ‘double*’ to ‘int*’
84 | double studentResultMin = minOrMax(a,L,false);
| ^
| |
| double*
Source.cpp:33:18: note: initializing argument 1 of ‘int minOrMax(int*, int, bool)’
33 | int minOrMax(int numbers[], int size, bool Max) {
| ~~~~^~~~~~~~~
Source.cpp:81:17: warning: unused variable ‘EPS’ [-Wunused-variable]
81 | const double EPS=0.001;
| ^~~
![Source.cpp: In function "bool test Passed (std::ofstream&)':
Source.cpp:84:39: error: cannot convert 'double* to 'int**
84 1
double student Resulta = trimmedAvg (a, L);
I
double*
Source.cpp:49:23: note: initializing argument 1 of 'double trimmedAvg (int*, int)'
49 | double trimmedAvg (int numbers [], int size) {
I
Source.cpp:85:39: error: cannot convert 'double*' to 'int**
double studentResultb = trimmedAvg (b, L);
85 1
I
double*
Source.cpp:49:23: note: initializing argument 1 of 'double trimmedAvg (int*, int)'
49 | double trimmedAvg (int numbers [], int size) {](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Feaff9129-3ee7-45d2-be07-4710dc5f9db4%2F6922b342-2c6e-4508-b697-ebdb07afb1d4%2Ftw8ylq2_processed.png&w=3840&q=75)
![Source.cpp: In function 'bool testPassed (std::ofstream&)':
Source.cpp:83:39: error: cannot convert 'double*' to 'int**
83 | double student ResultMax = minorMax (a, L, true);
I
double*
Source.cpp:33:18: note: initializing argument 1 of 'int minorMax (int*, int, bool)'
33 | int minorMax (int numbers [], int size, bool Max) {
I
~~~~
Source.cpp:84:39: error: cannot convert 'double*' to 'int**
double studentResultMin = minorMax (a, L, false);
84 |
I
I
double*
Source.cpp:33:18: note: initializing argument 1 of 'int minorMax (int*, int, bool)'
33 | int minorMax (int numbers [], int size, bool Max) {
I
Source.cpp:81:17: warning: unused variable 'EPS' [-Wunused-variable]
81 I const double EPS=0.001;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Feaff9129-3ee7-45d2-be07-4710dc5f9db4%2F6922b342-2c6e-4508-b697-ebdb07afb1d4%2F8vxrj2e_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images









