Task:
Write a C++ program with a function named FindMax that has two parameters, one in type
constant pointer to constant double array (i.e. const double* const arr), another one is in int
type that represents the size of the array. Your task in this part is to find the position of array
element with maximum value. Instead of returning the index of array, a pointer to the
maximum element should be returned (note: the returned pointer should be made in a way
that the value of the maximum value is unchangeable.)
Assumption: All the floating point values in the array are distinct.
Your main function should start by asking the user how many numbers he/she would like to
input, then followed by asking all the values. At the end of the program, print out the
maximum value obtained from the FindMax function.
A sample screen display when the method is called is given below:
How many numbers do you like to enter? 5
Enter values: 10.5 2.1 5.21 1.23 23.8
The maximum value: 23.8
These are work so far.But in the code
cin >> arr;
I don't know how to grab user inputs( a few double ) into a array..
Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <ctime>
#include <limits>
#include <cstdlib>
using namespace std;
int main()
{
int nums;
cout << "How many numbers do you like to enter? " ;
cin >> nums;
int* arr = new int[nums];
delete [ ] arr;
cout << "Enter values: " ;
cin >> arr;
delete [ ] arr;
// Hold the command window
system("pause");
return 0;
}
void FindMax( const double* const arr ,int arr2)
{
}
|