write a complete c++ program using the following specifications: please use poin
ID: 3801544 • Letter: W
Question
write a complete c++ program using the following specifications: please use pointer notation to code this program.
-in function main(), declare an array named numbers[], type integer size 5.
-pass the array to a function named loadArray(), and ask the user to enter 5 integer values into the array elements,(callby reference).
-pass the array to function named Maximum(), that will find the largest number in the array and returns the largest number back to main.(call by refernce)
-pass the array to a function named minimum(), that will find the lowest number in the array and returns the lowest number back to main,(call by reference )
-pass the largest and lowest numbers to a function named print (), that will display the following outputs on your monitor:(call by value)
the largest number was : 99
the lowest number was: 99
please note: 99 means that the numbers enterd into array numbers[] are 2 digits
Explanation / Answer
#include <iostream>
using namespace std;
void loadArray(int* array, int length) {
for (int i=0; i<length; i++) {
cout << "Enter the "<< (i+1) << "th element : ";
cin >> array[i];
}
}
int maximum(int* array, int length) {
int max = array[0];
for (int i=1; i<length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
int minimum(int* array, int length) {
int min = array[0];
for (int i=1; i<length; i++) {
if (array[i] < min) {
min = array[i];
}
}
return min;
}
void print(int min, int max) {
cout << "The largest number is " << max << endl;
cout << "The smallest number is " << min <<endl;
}
int main()
{
int length = 5;
int* array = new int[length];
loadArray(array, length);
int max = maximum(array, length);
int min = minimum(array, length);
print(min, max);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.