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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <iostream>
using namespace std;
void fillArray(int a[], int size, int& num_used);
//Precondition:The declared size of array a is given by parameter size.
//Postcondition:Array a will contain a number of non-negative integers entered by the user.
void displayArray(int a[], int num_used);
//Precondition:Array a should exist
//Postcondition:Those num_integers in array a are displayed on screen in a single line in the order that they are stored in array a.
void find_max_min(int a[], int num_used, int& max_index, int& min_index);
//Precondition:The first parameter a is an array of integers, and the second parameter num_used represents the actual number of positions in a that are used to store valid integers.
//Postcondition:The third parameter max_index should contain the index position where the largest element appears.
int main()
{
const int ARRAY_SIZE = 20;
int a[ARRAY_SIZE];
int num = 0;
int x = -1, y = -1;
int num_pass_grades(const int a[], int num_used);
fillArray(a, ARRAY_SIZE, num);
cout <<"Now display the array that has just been entered:\n";
displayArray(a, num);
find_max_min(a, num, x, y);
cout << "\nNow display the max value in array a:\n";
cout << a[x]<< " first appears at index "<< x << endl;
cout << "\nNow display the min value in array a:\n";
cout << a[y]<< " first appears at index "<< y << endl;
cout << "\nThere are " << num_pass_grades(a, num) << " scores >=60.\n";
return 0;
}
void fillArray(int a[], int size, int& num_used)
{
cout << "Please enter up to" << size << "non-negative integers.\n";
for (num_used; num_used < size; num_used++)
{
cin >> a[num_used];
}
}
void displayArray (int a[], int num_used)
{
int i = 0;
for (i; i < num_used; i++)
{
cout << a[i] << "";
}
cout << endl;
}
/*
void find_max_min (int a[], int num_used, int& max_index, int& min_index)
{
int i = 0;
for (i; i < num_used; i++)
{
if(isupper(a[]))
{
num_used[i] = max_index[i];
}
else
{
num_used[i] = min_index[i];
}
}
}
still figuring this one out, not sure on this
*/
|